[go: up one dir, main page]

Menu

[r51]: / examples / eqc.sty  Maximize  Restore  History

Download this file

235 lines (234 with data), 10.2 kB

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%* file eqc.sty
%*
%*
%*  Copyright (C) 2001 Jan Rheinländer, 71272 Renningen, Germany,
%*  jrheinlaender@gmx.de
%*
%*  This program is free software; you can redistribute it and/or modify
%*  it under the terms of the GNU General Public License as published by
%*  the Free Software Foundation; either version 2 of the License, or
%*  (at your option) any later version.
%*
%*  This program is distributed in the hope that it will be useful,
%*  but WITHOUT ANY WARRANTY; without even the implied warranty of
%*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%*  GNU General Public License for more details.
%*
%*  You should have received a copy of the GNU General Public License
%*  along with this program; if not, write to the Free Software
%*  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
%*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 
\NeedsTeXFormat{LaTeX2e}
\def\packagename{eqc}
\def\packagemessage{}
\def\filedate{2013/01/09}
\def\fileversion{1.4.10}
\def\docdate{}
\ProvidesPackage{eqc}[\filedate\space v\fileversion\space \packagename (JRh)]
\typeout{Package: '\packagename' v\fileversion\space <\filedate> (JRh)}
\typeout{\packagemessage}
\DeclareOption{german}{}
\DeclareOption{english}{}
\ProcessOptions
%
%------------------------- Processing equations --------------------------
%*** command \eq added in 0.4
%*** added extra brackets in 0.6
%*** changed in 0.9, the old version is inserted by EQC now
\newcommand{\lhs}[1]{\mbox{[lhs of } #1\mbox{]}} % added in 0.6, changed in 0.9
\newcommand{\rhs}[1]{\mbox{[rhs of } #1\mbox{]}} % added in 0.6, changed in 0.9
\newcommand{\denom}[1]{\mbox{[denominator of} #1\mbox{]}} 
\newcommand{\numer}[1]{\mbox{[numerator of} #1\mbox{]}}
%
%----------------------- Writing out equations --------------------------
\let\eqcnamedef\@namedef % Because \@... commands can't be used outside style files
\newtoks\eqtoks%
\newcommand{\eqwrite}[3]{%
  \eqtoks{\eq*[#3]{#2}}%
  \immediate\write#1{\the\eqtoks}%
  \eqtoks{\global\eqcnamedef{EQC@#3}}%
  \immediate\write#1{%
    \the\eqtoks{\expandafter\@setref\csname r@#3\endcsname\@firstoftwo{#3}}%
  }%
}%
\newcommand{\eqcref}[1]{%
  \@nameuse{EQC@#1}%
}%
%
%----------------------- Dummy commands ----------------------------------
%*** added in 0.9
\gdef\@kill#1{}
\newcommand{\@killtwo}[2][]{}
\newcommand{\@killthree}[3][]{}
\newcommand{\@killfour}[4][]{}
%
%Print a macro argument without interpreting ^, _ etc
%Thanks to Markus Kohm <markus.kohm@gmx.de>, Son 05 Dez 2004 11:21:14 in de.comp.text.tex
%TODO: Try fancyvrb!!!!!!!!!!!!!
%TODO: You can use \meaning to convert an entire argument to a verbatim
%      string of characters (or use e-TeX's recoding ability).
\def\g@remfrom@specials#1{%
  \def\@new@specials{}%
  \def\@remove##1{%
    \ifx ##1#1%
    \else \g@addto@macro\@new@specials{\do ##1}%
    \fi
  }%
  \let\do\@remove\dospecials
  \let\dospecials\@new@specials
}
\newcommand*{\printarg}{\bgroup
  \let\org@dospecials\dospecials
%  \g@remfrom@specials{\\}% Is this necessary?
  \g@remfrom@specials{\{}%
  \g@remfrom@specials{\}}%
  \let\do\@makeother
  \dospecials
  \let\dospecials\org@dospecials
  \frenchspacing\@vobeyspaces\printargend}
\newcommand{\printargend}[1]{#1\egroup}
%
\gdef\constant{\@ifstar\@kill\@constant}%Print constant definition if no star
\def\@constant#1{#1}
\newcommand{\function}[3][]{}%ignore completely
\gdef\deffunc{\@ifstar\@killthree\@deffunc}%print if no star
\newcommand{\@deffunc}[3][\empty]{#2 = #3\ifx#1\empty\else\label{#1}\fi}
\gdef\eq{\@ifstar\@killtwo\@eq}%print the equation if no star
\newcommand{\@eq}[2][\empty]{{}#2\ifx#1\empty\else\label{#1}\fi} 
\gdef\eqrev{\@ifstar\@killtwo\@eqrev}%print if no star
\newcommand{\@eqrev}[2][\empty]{\mbox{[reverse } #2\mbox{]}\ifx#1\empty\else\label{#1}\fi}
\gdef\eqadd{\@ifstar\@killthree\@eqadd}%print if no star
\newcommand{\@eqadd}[3][\empty]{\mbox{[add } #3 \mbox{ to } #2 \mbox{]}\ifx#1\empty\else\label{#1}\fi}
\gdef\eqsub{\@ifstar\@killthree\@eqsub}%print if no star
\newcommand{\@eqsub}[3][\empty]{\mbox{[subtract } #3 \mbox{ from } #2 \mbox{]}\ifx#1\empty\else\label{#1}\fi}
\gdef\eqmul{\@ifstar\@killthree\@eqmul}%print if no star
\newcommand{\@eqmul}[3][\empty]{\mbox{[multiply } #2 \mbox{ with } #3 \mbox{]}\ifx#1\empty\else\label{#1}\fi}
\gdef\eqdiv{\@ifstar\@killthree\@eqdiv}%print if no star
\newcommand{\@eqdiv}[3][\empty]{\mbox{[divide } #2 \mbox{ by } #3 \mbox{]}\ifx#1\empty\else\label{#1}\fi}
\gdef\eqpow{\@ifstar\@killthree\@eqpow}%print if no star
\newcommand{\@eqpow}[3][\empty]{\mbox{[take } #2 \mbox{ to power of } #3 \mbox{]}\ifx#1\empty\else\label{#1}\fi}
\gdef\eqdiff{\@ifstar\@killthree\@eqdiff}%print if no star
\newcommand{\@eqdiff}[3][\empty]{\mbox{[differentiate } #2 \mbox{ with respect to } #3 \mbox{]}\ifx#1\empty\else\label{#1}\fi}
\gdef\eqsubst{\@ifstar\@killthree\@eqsubst}%print if no star
\newcommand{\@eqsubst}[3][\empty]{\mbox{[substitute } #3 \mbox{ in } #2 \mbox{]}\ifx#1\empty\else\label{#1}\fi}
\gdef\eqsimpf{\@ifstar\@killthree\@eqsimpf}%print if no star
\newcommand{\@eqsimpf}[3][\empty]{\mbox{[#3 } #2 \mbox{]}\ifx#1\empty\else\label{#1}\fi}
\gdef\eqsolve{\@ifstar\@killfour\@eqsolve}%print if no star
\newcommand{\@eqsolve}[4][\empty]{\mbox{[find solution no. } #4 \mbox{ for } #3 \mbox{ in } #2 \mbox{]}\ifx#1\empty\else\label{#1}\fi}
\let\printeq\printarg
\newcommand{\deleq}[1]{}
\newcommand{\clearequations}{}
%
%----------------------- Other commands ----------------------------------
%*** added extra brackets in 0.6
%*** added \val and \quantity in 0.9
\newcommand{\numval}[2][\empty]{\mbox{[numval of }#2\ifx#1\empty\else\mbox{ in } #1\fi\mbox{]}}
\newcommand{\units}[2][\empty]{\mbox{[units of }#2\ifx#1\empty\else\mbox{ in } #1\fi\mbox{]}}
\newcommand{\val}[2][\empty]{\mbox{[val of }#2\ifx#1\empty\else\mbox{ in } #1\fi\mbox{]}}
\newcommand{\quantity}[2][\empty]{\mbox{[quantity of }#2\ifx#1\empty\else\mbox{ in } #1\fi\mbox{]}}
%changed defunit definition in 0.9 to parse `*' form
\gdef\defunit{\@ifstar\@killthree\@defunit}
\newcommand{\@defunit}[3][\empty]{\ifx#1\empty\def#2{#3}\else\def#2{#1}\fi}
%
%----------------------for debugging purposes-----------------------------
\newcommand{\result}[1]{{[Result: #1]}}%removed \small in 0.6
%
%----------------------mathematical functions
\newcommand{\arcosh}{\ensuremath{\mathrm{arcosh}}}
\newcommand{\arsinh}{\ensuremath{\mathrm{arsinh}}}
\newcommand{\artanh}{\ensuremath{\mathrm{artanh}}}
\newcommand{\tseries}[3]{\ensuremaths{T_{#3} #1 ]_{#2}}}
%
%----------------------helpful abbreviations----------------------------
\newcommand{\tdiff}[2]{\frac{d #1}{d #2}}%total derivative
\newcommand{\pdiff}[2]{\frac{\delta #1}{\delta #2}}%partial derivative
%
%
% eqc requires package SIunits to be loaded
\usepackage[amssymb,pstricks]{SIunits}
%
% *** Rewrite of \makepspicture, \mmakepspicture in 1.0. Removed \gmakepspicture
% eqc requires package fp and calc to be loaded
\usepackage{fp}
\usepackage{calc}
%TODO: This is terribly complicated, but there are so many
%limitations:
%calc truncates all fractional parts of real numbers when doing counter arithmetics
%fp can't handle dimensions
%fp can't use FPadd or FPsub or + or - because of a name conflict with
%multido
%
\newcommand{\EQCaxisarrowfact}{1.05}%
\newcommand{\EQCaxisnamefact}{1.07}%
\edef\EQCmulfact{100}%
\edef\EQCx{0}%
\edef\EQCy{0}%
\edef\EQChx{0}%
\edef\EQChy{0}%
\edef\EQCtx{0}%
\edef\EQCty{0}%
\edef\EQCtotx{0}%
\edef\EQCtoty{0}%
\newlength{\EQClenx}%
\newlength{\EQCleny}%
\newcounter{EQChelp}%
\newlength{\EQChelp}%
\FPmessagesfalse%
%
\newcommand{\makepspicture}[9]{%
\FPmul\EQCx{#3}{\EQCaxisarrowfact}%
\FPmul\EQCy{#4}{\EQCaxisarrowfact}%
\FPmul\EQCtx{#3}{\EQCaxisnamefact}%
\FPmul\EQCty{#4}{\EQCaxisnamefact}%
\setlength{\EQClenx}{#3\psxunit}%
\setlength{\EQCleny}{#4\psyunit}%
%This is what we would LIKE to do here:
%\FPeval\EQCtotx{\EQCtx + \widthof{#7} / \psxunit}
\setlength{\EQChelp}{\EQCaxisnamefact\EQClenx}%
\setcounter{EQChelp}{\EQCmulfact + (\widthof{#7} * \EQCmulfact) / \EQChelp}%
\def\EQCwx{\arabic{EQChelp}}%
\FPupn\EQCtotx{EQCmulfact EQCtx EQCwx * /}%
\setlength{\EQChelp}{\EQCaxisnamefact\EQCleny}%
\setcounter{EQChelp}{\EQCmulfact + ((\heightof{#8} + \depthof{#8}) * \EQCmulfact) / \EQChelp}%
\def\EQCwy{\arabic{EQChelp}}%
\FPupn\EQCtoty{EQCmulfact EQCty EQCwy * /}%
\pspicture#2(\EQCtotx, \EQCtoty)
  \psaxes[linewidth=2pt, ticks=none, labels=none]{->}#1#2(\EQCx, \EQCy)
  \psaxes[Dx=#5, ticks=x, ticksize=\EQCleny, labels=x, tickstyle=top]{->}#1#2(\EQCx, \EQCy)
  \rput[l]{0}(\EQCtx, 0){\large #7}
  \psaxes[Dy=#6, ticks=y, ticksize=\EQClenx, labels=y, tickstyle=top]{->}#1#2(\EQCx, \EQCy)
  \rput[b]{0}(0, \EQCty){\large #8}
  \pscurve{-}#9
\endpspicture%
}
\newcommand{\mmakepspicture}[9]{%Note that the origin is assumed to be (0,0)
\FPmul\EQCx{#3}{\EQCaxisarrowfact}%
\FPmul\EQCy{#4}{\EQCaxisarrowfact}%
\FPmul\EQChx{#3}{1.001}%
\FPmul\EQChy{#4}{1.001}%
\FPmul\EQCtx{#3}{\EQCaxisnamefact}%
\FPmul\EQCty{#4}{\EQCaxisnamefact}%
\setlength{\EQClenx}{#3\psxunit - #1\psxunit}%
\setlength{\EQCleny}{#4\psyunit - #2\psyunit}%
\setlength{\EQChelp}{1.06\EQClenx}%
\setcounter{EQChelp}{1000 + (\widthof{#7} * 1000) / \EQChelp}%
\def\EQCwx{\arabic{EQChelp}}%
\FPupn\EQCtotx{1000 EQCtx EQCwx * /}%
\setlength{\EQChelp}{1.06\EQCleny}%
\setcounter{EQChelp}{1000 + ((\heightof{#8} + \depthof{#8}) * 1000) / \EQChelp}%
\def\EQCwy{\arabic{EQChelp}}%
\FPupn\EQCtoty{1000 EQCty EQCwy * /}%
\pspicture(#1,#2)(\EQCtotx, \EQCtoty)
  \psaxes[Dx=#5, Dy=#6, labels=none, linewidth=2pt]{->}(0,0)(#1,#2)(\EQCx, \EQCy)%draw x and y axis with bold ticks
  \psaxes[Dx=#5, labels=none, ticks=x, ticksize=\EQCleny, tickstyle=top]{-}(#1,#2)(#1,#2)(\EQChx, \EQChy)%draw y grid lines
  \psaxes[Dx=#5, labels=x, ticks=none]{-}(0,#2)(#1,#2)(\EQChx, \EQChy)%write x axis labels
  \rput[l]{0}(\EQCtx, 0){\large #7}
  \psaxes[Dy=#6, labels=none, ticks=y, ticksize=\EQClenx, tickstyle=top]{-}(#1,#2)(#1,#2)(\EQChx, \EQChy)
  \psaxes[Dy=#6, labels=y, ticks=none]{-}(#1,0)(#1,#2)(\EQChx, \EQChy)
  \rput[b]{0}(0, \EQCty){\large #8}
  \pscurve{-}#9
\endpspicture%
}