2 %% This is file `calc.sty',
3 %% generated with the docstrip utility.
5 %% The original source files were:
7 %% calc.dtx (with options: `package')
10 %% Copyright (C) 1992--1995 Kresten Krab Thorup and Frank Jensen.
11 %% All rights reserved.
13 \def\fileversion{v4.0c (TEST)}
14 \def\filedate{1995/04/10}
17 %% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
18 %% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
19 %% Digits \0\1\2\3\4\5\6\7\8\9
20 %% Exclamation \! Double quote \" Hash (number) \#
21 %% Dollar \$ Percent \% Ampersand \&
22 %% Acute accent \' Left paren \( Right paren \)
23 %% Asterisk \* Plus \+ Comma \,
24 %% Minus \- Point \. Solidus \/
25 %% Colon \: Semicolon \; Less than \<
26 %% Equals \= Greater than \> Question mark \?
27 %% Commercial at \@ Left bracket \[ Backslash \\
28 %% Right bracket \] Circumflex \^ Underscore \_
29 %% Grave accent \` Left brace \{ Vertical bar \|
30 %% Right brace \} Tilde \~}
31 \NeedsTeXFormat{LaTeX2e}
32 \ProvidesPackage{calc}[\filedate\space\fileversion]
33 \typeout{Package: `calc' \fileversion\space <\filedate> (KKT and FJ)}
34 \def\calc@assign@generic#1#2#3#4{\let\calc@A#1\let\calc@B#2%
35 \expandafter\calc@open\expandafter(#4!%
36 \global\calc@A\calc@B\endgroup#3\calc@B}
37 \def\calc@assign@count{\calc@assign@generic\calc@Acount\calc@Bcount}
38 \def\calc@assign@dimen{\calc@assign@generic\calc@Adimen\calc@Bdimen}
39 \def\calc@assign@skip{\calc@assign@generic\calc@Askip\calc@Bskip}
40 \newcount\calc@Acount \newcount\calc@Bcount
41 \newdimen\calc@Adimen \newdimen\calc@Bdimen
42 \newskip\calc@Askip \newskip\calc@Bskip
43 \def\setcounter#1#2{\@ifundefined{c@#1}{\@nocounterr{#1}}%
44 {\calc@assign@count{\global\csname c@#1\endcsname}{#2}}}
45 \def\addtocounter#1#2{\@ifundefined{c@#1}{\@nocounterr{#1}}%
46 {\calc@assign@count{\global\advance\csname c@#1\endcsname}{#2}}}
47 \DeclareRobustCommand\setlength{\calc@assign@skip}
48 \DeclareRobustCommand\addtolength[1]{\calc@assign@skip{\advance#1}}
49 \def\calc@pre@scan#1{%
51 \let\calc@next\calc@open
53 \let\calc@next\calc@numeric
56 \def\calc@open({\begingroup\aftergroup\calc@initB
57 \begingroup\aftergroup\calc@initB
59 \def\calc@initB{\calc@B\calc@A}
60 \def\calc@numeric{\afterassignment\calc@post@scan \global\calc@A}
61 \def\calc@post@scan#1{%
62 \ifx#1!\let\calc@next\endgroup \else
63 \ifx#1+\let\calc@next\calc@add \else
64 \ifx#1-\let\calc@next\calc@subtract \else
65 \ifx#1*\let\calc@next\calc@multiplyx \else
66 \ifx#1/\let\calc@next\calc@dividex \else
67 \ifx#1)\let\calc@next\calc@close \else \calc@error#1%
75 \def\calc@add{\calc@generic@add\calc@addAtoB}
76 \def\calc@subtract{\calc@generic@add\calc@subtractAfromB}
77 \def\calc@generic@add#1{\endgroup\global\calc@A\calc@B\endgroup
78 \begingroup\aftergroup#1\begingroup\aftergroup\calc@initB
80 \def\calc@addAtoB{\advance\calc@B\calc@A}
81 \def\calc@subtractAfromB{\advance\calc@B-\calc@A}
82 \def\calc@multiplyx#1{\def\calc@tmp{#1}%
83 \ifx\calc@tmp\calc@ratio@x \let\calc@next\calc@ratio@multiply \else
84 \ifx\calc@tmp\calc@real@x \let\calc@next\calc@real@multiply \else
85 \let\calc@next\calc@multiply
89 \def\calc@dividex#1{\def\calc@tmp{#1}%
90 \ifx\calc@tmp\calc@ratio@x \let\calc@next\calc@ratio@divide \else
91 \ifx\calc@tmp\calc@real@x \let\calc@next\calc@real@divide \else
92 \let\calc@next\calc@divide
96 \def\calc@ratio@x{\ratio}
97 \def\calc@real@x{\real}
98 \def\calc@multiply{\calc@generic@multiply\calc@multiplyBbyA}
99 \def\calc@divide{\calc@generic@multiply\calc@divideBbyA}
100 \def\calc@generic@multiply#1{\endgroup\begingroup
101 \let\calc@A\calc@Acount \let\calc@B\calc@Bcount
102 \aftergroup#1\calc@pre@scan}
103 \def\calc@multiplyBbyA{\multiply\calc@B\calc@Acount}
104 \def\calc@divideBbyA{\divide\calc@B\calc@Acount}
106 {\endgroup\global\calc@A\calc@B
107 \endgroup\global\calc@A\calc@B
109 \def\calc@ratio@multiply\ratio{\calc@ratio@evaluate}
110 \def\calc@ratio@divide\ratio#1#2{\calc@ratio@evaluate{#2}{#1}}
111 \let\calc@numerator=\calc@Bcount
112 \newcount\calc@denominator
113 \def\calc@ratio@evaluate#1#2{%
115 \calc@assign@dimen\calc@numerator{#1}%
116 \calc@assign@dimen\calc@denominator{#2}%
117 \gdef\calc@the@ratio{}%
118 \ifnum\calc@numerator<0 \calc@numerator-\calc@numerator
119 \gdef\calc@the@ratio{-}%
121 \ifnum\calc@denominator<0 \calc@denominator-\calc@denominator
122 \xdef\calc@the@ratio{\calc@the@ratio-}%
124 \calc@Acount\calc@numerator
125 \divide\calc@Acount\calc@denominator
126 \xdef\calc@the@ratio{\calc@the@ratio\number\calc@Acount.}%
127 \calc@next@digit \calc@next@digit \calc@next@digit
128 \calc@next@digit \calc@next@digit \calc@next@digit
130 \calc@multiply@by@real\calc@the@ratio
133 \def\calc@next@digit{%
134 \multiply\calc@Acount\calc@denominator
135 \advance\calc@numerator -\calc@Acount
136 \multiply\calc@numerator 10
137 \calc@Acount\calc@numerator
138 \divide\calc@Acount\calc@denominator
139 \xdef\calc@the@ratio{\calc@the@ratio\number\calc@Acount}}
140 \def\calc@multiply@by@real#1{\calc@Bdimen #1\calc@B \calc@B\calc@Bdimen}
141 \def\calc@real@multiply\real#1{\endgroup
142 \calc@multiply@by@real{#1}\begingroup
144 \def\calc@real@divide\real#1{\calc@ratio@evaluate{1pt}{#1pt}}
146 \errhelp{Calc error: I expected to see one of: + - * / )}%
147 \errmessage{Invalid character `#1' in arithmetic expression}}
150 %% End of file `calc.sty'.