Debian Codegraph @

texmf-dist/tex/latex-dev/tools/calc.sty

raw
1 %%
2 %% This is file `calc.sty',
3 %% generated with the docstrip utility.
4 %%
5 %% The original source files were:
6 %%
7 %% calc.dtx (with options: `package')
8 %%
9 %% This is a generated file.
10 %%
11 %% The source is maintained by the LaTeX Project team and bug
12 %% reports for it can be opened at https://latex-project.org/bugs/
13 %% (but please observe conditions on bug reports sent to that address!)
14 %%
15 %%
16 %% Copyright (C) 1993-2026
17 %% The LaTeX Project and any individual authors listed elsewhere
18 %% in this file.
19 %%
20 %% This file was generated from file(s) of the Standard LaTeX `Tools Bundle'.
21 %% --------------------------------------------------------------------------
22 %%
23 %% It may be distributed and/or modified under the
24 %% conditions of the LaTeX Project Public License, either version 1.3c
25 %% of this license or (at your option) any later version.
26 %% The latest version of this license is in
27 %% https://www.latex-project.org/lppl.txt
28 %% and version 1.3c or later is part of all distributions of LaTeX
29 %% version 2005/12/01 or later.
30 %%
31 %% This file may only be distributed together with a copy of the LaTeX
32 %% `Tools Bundle'. You may however distribute the LaTeX `Tools Bundle'
33 %% without such generated files.
34 %%
35 %% The list of all files belonging to the LaTeX `Tools Bundle' is
36 %% given in the file `manifest.txt'.
37 %%
38 %% File `calc.dtx'.
39 %% Copyright (C) 1992--1995
40 %% Kresten Krab Thorup and Frank Jensen.
41 %% Copyright (C) 1997--2007
42 %% Kresten Krab Thorup, Frank Jensen and the LaTeX Project.
43 %%
44 %% The original authors ([email protected] and [email protected]) have
45 %% contributed this package to the LaTeX distribution.
46 %% Problems with this package should now be sent using latexbug.tex to
47 %% the normal LaTeX bug report address.
48 \NeedsTeXFormat{LaTeX2e}
49 \ProvidesPackage{calc}
50 [2025/03/01 v4.3b Infix arithmetic (KKT,FJ)]
51 \def\calc@assign@generic#1#2#3#4{\let\calc@A#1\let\calc@B#2%
52 \calc@open(#4!%
53 \global\calc@A\calc@B\endgroup#3\calc@B}
54 \def\calc@assign@count{\calc@assign@generic\calc@Acount\calc@Bcount}
55 \def\calc@assign@dimen{\calc@assign@generic\calc@Adimen\calc@Bdimen}
56 \def\calc@assign@skip{\calc@assign@generic\calc@Askip\calc@Bskip}
57 \newcount\calc@Acount \newcount\calc@Bcount
58 \newdimen\calc@Adimen \newdimen\calc@Bdimen
59 \newskip\calc@Askip \newskip\calc@Bskip
60 \def\setcounter#1#2{\@ifundefined{c@#1}{\@nocounterr{#1}}%
61 {\calc@assign@count{\global\csname c@#1\endcsname}{#2}}}
62 \def\addtocounter#1#2{\@ifundefined{c@#1}{\@nocounterr{#1}}%
63 {\calc@assign@count{\global\advance\csname c@#1\endcsname}{#2}}}%
64 \def\stepcounter#1{\@ifundefined {c@#1}%
65 {\@nocounterr {#1}}%
66 {\global\advance\csname c@#1\endcsname \@ne
67 \begingroup
68 \let\@elt\@stpelt \csname cl@#1\endcsname
69 \endgroup}}%
70 \AtBeginDocument{%
71 \@ifpackageloaded{amstext}{%
72 \def\addtocounter#1#2{\iffirstchoice@
73 \@ifundefined{c@#1}{\@nocounterr{#1}}%
74 {\calc@assign@count{\global\advance\csname c@#1\endcsname}{#2}}%
75 \fi}%
76 \def\stepcounter#1{\iffirstchoice@
77 \@ifundefined {c@#1}%
78 {\@nocounterr {#1}}%
79 {\global\advance\csname c@#1\endcsname \@ne
80 \begingroup
81 \let\@elt\@stpelt \csname cl@#1\endcsname
82 \endgroup}%
83 \fi}%
84 }{}%
85 }
86 \DeclareRobustCommand\setlength{\calc@assign@skip}
87 \DeclareRobustCommand\addtolength[1]{\calc@assign@skip{\advance#1}}
88 \def\calc@pre@scan#1{%
89 \expandafter\@calc@pre@scan\romannumeral-`\a#1}
90 \def\@calc@pre@scan#1{%
91 \ifx(#1%
92 \expandafter\calc@open
93 \else
94 \ifx\widthof#1%
95 \expandafter\expandafter\expandafter\calc@textsize
96 \else
97 \ifx\maxof#1%
98 \expandafter\expandafter\expandafter\expandafter
99 \expandafter\expandafter\expandafter\calc@maxmin@addsub
100 \else
101 \calc@numeric% no \expandafter needed for this one.
102 \fi
103 \fi
104 \fi
105 #1}
106 \def\calc@open({\begingroup\aftergroup\calc@initB
107 \begingroup\aftergroup\calc@initB
108 \calc@pre@scan}
109 \def\calc@initB{\calc@B\calc@A}
110 \def\calc@numeric{\afterassignment\calc@post@scan \global\calc@A}
111 \@for\reserved@a:=widthof,heightof,depthof,totalheightof,maxof,minof\do
112 {\@ifundefined{\reserved@a}{}{%
113 \PackageError{calc}{%
114 The\space calc\space package\space reserves\space the\space
115 command\space name\space `\@backslashchar\reserved@a'\MessageBreak
116 but\space it\space has\space already\space been\space defined\space
117 with\space the\space meaning\MessageBreak
118 `\expandafter\meaning\csname\reserved@a\endcsname'.\MessageBreak
119 This\space original\space definition\space will\space be\space lost}%
120 {If\space you\space need\space a\space command\space with\space
121 this\space definition,\space you\space must\space use\space a\space
122 different\space name.}}%
123 }
124 \let\widthof\ignorespaces
125 \let\heightof\ignorespaces
126 \let\depthof\ignorespaces
127 \let\totalheightof\ignorespaces
128 \def\calc@textsize #1#2{%
129 \begingroup
130 \let\widthof\wd
131 \let\heightof\ht
132 \let\depthof\dp
133 \def\totalheightof{\ht\dp}%
134 \expandafter\@settodim\expandafter{#1}%
135 {\global\calc@A}%
136 {%
137 \let\widthof\ignorespaces
138 \let\heightof\ignorespaces
139 \let\depthof\ignorespaces
140 \let\totalheightof\ignorespaces
141 #2}%
142 \endgroup
143 \calc@post@scan}
144 \def\calc@post@scan#1{%
145 \expandafter\@calc@post@scan\romannumeral-`\a#1}
146 \def\@calc@post@scan#1{%
147 \ifx#1!\let\calc@next\endgroup \else
148 \ifx#1+\let\calc@next\calc@add \else
149 \ifx#1-\let\calc@next\calc@subtract \else
150 \ifx#1*\let\calc@next\calc@multiplyx \else
151 \ifx#1/\let\calc@next\calc@dividex \else
152 \ifx#1)\let\calc@next\calc@close \else
153 \ifx#1\relax\let\calc@next\calc@post@scan \else
154 \def\calc@next{\calc@error#1}%
155 \fi
156 \fi
157 \fi
158 \fi
159 \fi
160 \fi
161 \fi
162 \calc@next}
163 \def\calc@add{\calc@generic@add\calc@addAtoB}
164 \def\calc@subtract{\calc@generic@add\calc@subtractAfromB}
165 \def\calc@generic@add#1{\endgroup\global\calc@A\calc@B\endgroup
166 \begingroup\aftergroup#1\begingroup\aftergroup\calc@initB
167 \calc@pre@scan}
168 \def\calc@addAtoB{\advance\calc@B\calc@A}
169 \def\calc@subtractAfromB{\advance\calc@B-\calc@A}
170 \ifx\real\@undefined\let\real\relax\fi
171 \ifx\ratio\@undefined\let\ratio\relax\fi
172 \def\calc@ratio@x{\ratio}
173 \def\calc@real@x{\real}
174 \def\calc@multiplyx#1{\def\calc@tmp{#1}%
175 \ifx\calc@tmp\calc@ratio@x \let\calc@next\calc@ratio@multiply \else
176 \ifx\calc@tmp\calc@real@x \let\calc@next\calc@real@multiply \else
177 \ifx\maxof#1\let\calc@next\calc@maxmin@multiply \else
178 \let\calc@next\calc@multiply
179 \fi
180 \fi
181 \fi
182 \calc@next#1}
183 \def\calc@dividex#1{\def\calc@tmp{#1}%
184 \ifx\calc@tmp\calc@ratio@x \let\calc@next\calc@ratio@divide \else
185 \ifx\calc@tmp\calc@real@x \let\calc@next\calc@real@divide \else
186 \ifx\maxof#1\let\calc@next\calc@maxmin@divide \else
187 \let\calc@next\calc@divide
188 \fi
189 \fi
190 \fi
191 \calc@next#1}
192 \def\calc@multiply{\calc@generic@multiply\calc@multiplyBbyA}
193 \def\calc@divide{\calc@generic@multiply\calc@divideBbyA}
194 \def\calc@generic@multiply#1{\endgroup\begingroup
195 \let\calc@A\calc@Acount \let\calc@B\calc@Bcount
196 \aftergroup#1\calc@pre@scan}
197 \def\calc@multiplyBbyA{\multiply\calc@B\calc@Acount}
198 \def\calc@divideBbyA{\divide\calc@B\calc@Acount}
199 \def\calc@close
200 {\endgroup\global\calc@A\calc@B
201 \endgroup\global\calc@A\calc@B
202 \calc@post@scan}
203 \def\calc@ratio@multiply\ratio{\calc@ratio@evaluate}
204 \def\calc@ratio@divide\ratio#1#2{\calc@ratio@evaluate{#2}{#1}}
205 \newcount\calc@Ccount
206 \let\calc@numerator=\calc@Bcount
207 \let\calc@denominator=\calc@Ccount
208 \def\calc@ratio@evaluate#1#2{%
209 \endgroup\begingroup
210 \calc@assign@dimen\calc@numerator{#1}%
211 \calc@assign@dimen\calc@denominator{#2}%
212 \gdef\calc@the@ratio{}%
213 \ifnum\calc@numerator<0 \calc@numerator-\calc@numerator
214 \gdef\calc@the@ratio{-}%
215 \fi
216 \ifnum\calc@denominator<0 \calc@denominator-\calc@denominator
217 \xdef\calc@the@ratio{\calc@the@ratio-}%
218 \fi
219 \calc@Acount\calc@numerator
220 \divide\calc@Acount\calc@denominator
221 \xdef\calc@the@ratio{\calc@the@ratio\number\calc@Acount.}%
222 \calc@next@digit \calc@next@digit \calc@next@digit
223 \calc@next@digit \calc@next@digit \calc@next@digit
224 \endgroup
225 \calc@multiply@by@real\calc@the@ratio
226 \begingroup
227 \calc@post@scan}
228 \def\calc@next@digit{%
229 \multiply\calc@Acount\calc@denominator
230 \advance\calc@numerator -\calc@Acount
231 \multiply\calc@numerator 10
232 \calc@Acount\calc@numerator
233 \divide\calc@Acount\calc@denominator
234 \xdef\calc@the@ratio{\calc@the@ratio\number\calc@Acount}}
235 \def\calc@multiply@by@real#1{\calc@Bdimen #1\calc@B \calc@B\calc@Bdimen}
236 \def\calc@real@multiply\real#1{\endgroup
237 \calc@multiply@by@real{#1}\begingroup
238 \calc@post@scan}
239 \def\calc@real@divide\real#1{\calc@ratio@evaluate{1pt}{#1pt}}
240 \let\maxof\@@italiccorr
241 \let\minof\@@italiccorr
242 \newskip\calc@Cskip
243 \newif\ifcalc@count@
244 \def\calc@maxmin@addsub#1#2#3{\begingroup
245 \ifx\calc@A\calc@Acount%
246 \calc@count@true
247 \else
248 \calc@count@false
249 \fi
250 \calc@maxmin@generic#1{#2}{#3}%
251 \endgroup
252 \calc@post@scan
253 }
254 \def\calc@maxmin@generic#1#2#3{%
255 \begingroup
256 \ifcalc@count@
257 \calc@assign@count\calc@Ccount{#2}%
258 \calc@assign@count\calc@Bcount{#3}%
259 \def\minof{<}\def\maxof{>}%
260 \global\calc@A\ifnum\calc@Ccount#1\calc@Bcount
261 \calc@Ccount\else\calc@Bcount\fi
262 \else
263 \calc@assign@skip\calc@Cskip{#2}%
264 \calc@assign@skip\calc@Bskip{#3}%
265 \def\minof{<}\def\maxof{>}%
266 \global\calc@A\ifdim\calc@Cskip#1\calc@Bskip
267 \calc@Cskip\else\calc@Bskip\fi
268 \fi
269 \endgroup
270 }
271 \def\calc@maxmin@divmul#1#2#3#4{%
272 \endgroup\begingroup
273 \calc@count@true
274 \aftergroup#1%
275 \calc@maxmin@generic#2{#3}{#4}%
276 \endgroup\begingroup
277 \calc@post@scan
278 }
279 \def\calc@maxmin@multiply{\calc@maxmin@divmul\calc@multiplyBbyA}
280 \def\calc@maxmin@divide {\calc@maxmin@divmul\calc@divideBbyA}
281 \def\calc@error#1{%
282 \PackageError{calc}%
283 {`#1' invalid at this point}%
284 {I expected to see one of: + - * / )}}
285 \def\@settodim#1#2#3{%
286 \setbox\@tempboxa\hbox
287 {{\SuspendTagging{\@settodim}#3\ResumeTagging{\@settodim}}}%
288 \dimen@ii=\z@
289 \@tf@r\reserved@a #1\do{%
290 \advance\dimen@ii\reserved@a\@tempboxa}%
291 #2=\dimen@ii
292 \setbox\@tempboxa\box\voidb@x}
293 \def\settototalheight{\@settodim{\ht\dp}}
294 \endinput
295 %%
296 %% End of file `calc.sty'.