summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/koma-script/source/scrkernel-pseudolengths.dtx
blob: 4c891a86201070ab7ffcdf919d509db007f24db4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
% \iffalse meta-comment
% ======================================================================
% scrkernel-pseudolengths.dtx
% Copyright (c) Markus Kohm, 2002-2022
%
% This file is part of the LaTeX2e KOMA-Script bundle.
%
% This work may be distributed and/or modified under the conditions of
% the LaTeX Project Public License, version 1.3c of the license.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions of LaTeX 
% version 2005/12/01 or later and of this work.
%
% This work has the LPPL maintenance status "author-maintained".
%
% The Current Maintainer and author of this work is Markus Kohm.
%
% This work consists of all files listed in manifest.txt.
% ======================================================================
%%% From File: $Id: scrkernel-pseudolengths.dtx 3701 2022-02-14 09:17:40Z kohm $
%<option>%%%            (run: option)
%<body>%%%            (run: body)
%<*dtx>
\ifx\ProvidesFile\undefined\def\ProvidesFile#1[#2]{}\fi
\begingroup
  \def\filedate$#1: #2-#3-#4 #5${\gdef\filedate{#2/#3/#4}}
  \filedate$Date: 2022-02-14 10:17:40 +0100 (Mo, 14. Feb 2022) $
  \def\filerevision$#1: #2 ${\gdef\filerevision{r#2}}
  \filerevision$Revision: 3701 $
  \edef\reserved@a{%
    \noexpand\endgroup
    \noexpand\ProvidesFile{scrkernel-pseudolengths.dtx}%
                          [\filedate\space\filerevision\space
                           KOMA-Script source
                          (pseudo length)]
  }%
\reserved@a
\documentclass[USenglish]{koma-script-source-doc}
\usepackage{babel}
\usepackage{hvlogos}
\setcounter{StandardModuleDepth}{2}
\begin{document}
\DocInput{scrkernel-pseudolengths.dtx}
\end{document}
%</dtx>
% \fi^^A meta-comment
%
% \changes{v2.95}{2002/06/20}{first version after splitting \file{scrclass.dtx}}
% \changes{v3.36}{2022/02/14}{switch over from \cls*{scrdoc} to
%   \cls*{koma-script-source-doc}}
% \changes{v3.36}{2022/02/14}{whole implementation documentation in English}
%
% \GetFileInfo{scrkernel-pseudolengths.dtx}
% \title{Handling of Lengths Stored in Macros for
%   \href{https://komascript.de}{\KOMAScript} Letter Class and Packages}
% \author{\href{mailto:komascript@gmx.info}{Markus Kohm}}
% \date{Revision \fileversion{} of \filedate}
% \maketitle
% \begin{abstract}
%   \file{scrkernel-pseudolength.dtx} provides storing lengths in macros. This
%   feature has been introduced with \cls*{scrlttr2} in 2002, because at that
%   time there where only 256 skip registers for \LaTeX{} lengths and
%   \cls*{scrlttr2} needs several lengths to specify the positions of several
%   notepaper elements. Some time later The \LaTeX{} Team (at long last) has
%   decided to recommend \eTeX{} as \TeX{} engine for
%   \LaTeX.\!\footnote{Currently \pdfTeX{} with \eTeX{} extensions is the
%     recommended \TeX{} engine for \LaTeX.} \,Therefore the usage of the so
%   called \emph{pseudo lengths} in \KOMAScript{} wouldn't be necessary any
%   longer. But they exist and will be used at least for compatibility also in
%   future versions of \cls*{scrlttr2} and \pkg*{scrletter}.
% \end{abstract}
% \tableofcontents
%
% \section{User Manual}
%
% You can find the user documentation the commands implemented here in the
% \KOMAScript{} manual, either the German \file{scrguide} or the English
% \file{scrguien}.
%
% \MaybeStop{\PrintIndex}
%
% \section{Implementation of Package \pkg*{typearea} and Additional Class
%   Features}
%
%    \begin{macrocode}
%<*letter>
%    \end{macrocode}
% 
% \subsection{Options}
% The method of pseudo lengths is not influenced by options.
%
%
% \subsection{Commands and macros for pseudo lengths}
%
% For the calculation of the positions of several elements of the notepaper
% several lengths are needed. To not use a lot \LaTeX{} lengths (and therefore
% \TeX{} skip registers) they are stored in macros. So we also need some
% additional commands to not only store lengths values in macros but also for
% arithmetic operations on such macros and even to test, if a pseudo lengths
% exists or not.
%
%
% \begin{command}{\Ifplength}
% \changes{v3.27}{2019/03/29}{added}
% \begin{macro}{\if@plength}
% \changes{v3.27}{2019/03/29}{added}
% \changes{v3.36}{2022/02/14}{deprecated}
% Test whether or not a given pseudo-length (\texttt{\#1}) already exists. If
% so execute argument \texttt{\#2}, otherwise \texttt{\#3}.
%    \begin{macrocode}
%<*body>
\newcommand*{\Ifplength}[1]{%
  \@ifundefined{ltr@len@#1}{\@secondoftwo}{\@firstoftwo}%
}
\newcommand*{\if@plength}{%
%<class>  \ClassWarning{\KOMAClassName}{%
%<package>  \PackageWarning{scrletter}{%
    Internal macro `\string\if@plength' is deprecated.\MessageBreak
    Please use `\string\Ifplength' instead}%
  \Ifplength
}
%    \end{macrocode}
% \end{macro}^^A \if@plength
% \end{command}^^A \Ifplength
%
%
% \begin{command}{\newplength}
% \changes{v2.8q}{2001/10/06}{added}
% \changes{v2.8q}{2001/10/06}{retired compatibility to
%   \cls[https://www.ctan.org/pkg/koma-script-obsolete]{scrlettr}}
% \changes{v3.26}{2018/04/26}{user command instead of internal macro}
% \changes{v3.27}{2019/03/29}{changed error message}
% \begin{macro}{\@newplength}
% \changes{v3.36}{2022/02/14}{deprecated}
% Define a new pseudo length (\texttt{\#1}) and initialize it with 0.
%    \begin{macrocode}
\newcommand*{\newplength}[1]{%
  \@ifundefined{ltr@len@#1}{%
    \expandafter\let\csname ltr@len@#1\endcsname=\z@%
  }{%
%<class>    \ClassError{scrlttr2%
%<package>    \PackageError{scrletter%
    }{%
      pseudo-length \expandafter\string\csname ltr@len@#1\endcsname
      already defined%
    }{%
      You've tried to define a new pseudo-length using\MessageBreak
      \string\@newplength\space
      or \string\newplength.\MessageBreak
      Please, try another name%
    }%
  }%
}
\newcommand*{\@newplength}{%
%<class>  \ClassWarning{\KOMAClassName}{%
%<package>  \PackageWarning{scrletter}{%
    Internal macro `\string\@newplength' is deprecated.\MessageBreak
    Please use `\string\newplength' instead}%
  \newplength
}
%    \end{macrocode}
% \end{macro}
% \end{command}
%
%
% \begin{command}{\useplength}
% \changes{v2.8q}{2001/10/06}{added}
% \changes{v2.97c}{2007/09/17}{with \eTeX{} using \cs{dimexpr} instead of \cs{number}}
% \changes{v3.25}{2017/11/29}{\eTeX{} is mandatory}
% \changes{v3.25}{2017/11/29}{\cs{dimexpr} replaced by \cs{glueexpr}}
% Read the value of a pseudo length like a skip register. This can be done
% using \cs{glueexpr}.
%    \begin{macrocode}
\newcommand*{\useplength}[1]{%
  \glueexpr \csname ltr@len@#1\endcsname\relax}%
%    \end{macrocode}
% \end{command}
%
% \begin{command}{\setlengthtoplength}
% \changes{v2.8q}{2001/10/06}{added}
% Set a real \LaTeX{} length (usually a \TeX{} skip, but \TeX{} dimensions are
% also valid) to a multiple of a pseudo length. The factor is given by the
% optional argument \texttt{\#1}. The length is mandatory argument \textrm{\#2}
% and the name of the pseudo length the also mandatory \texttt{\#3}.
%    \begin{macrocode}
\newcommand*{\setlengthtoplength}[3][]{%
  \setlength{#2}{\useplength{#3}}%
  \setlength{#2}{#1#2}}
%    \end{macrocode}
% \end{command}
%
% \begin{command}{\setplength}
% \changes{v2.8q}{2001/10/06}{added}
% \changes{v3.25}{2017/11/29}{\cs{glueexpr} eingefügt}
% \changes{v3.36}{2018/04/26}{user command instead of internal macro}
% \begin{macro}{\@setplength}
% \changes{v3.36}{2022/02/14}{deprecated}
% We also need a command to set a pseudo length (\texttt{\#2}) to a new value
% (\texttt{\#3}). Locally we use a length to do so, because we want error
% messages about illegal values here and not when using the pseudo value. Once
% more an optional factor (\texttt{\#1}) is provided (but does not make much sense).
%    \begin{macrocode}
\newcommand*{\setplength}[3][]{%
  \begingroup%
    \setlength{\@tempskipa}{\glueexpr #3\relax}%
    \setlength{\@tempskipa}{#1\@tempskipa}%
    \edef\@tempa{\noexpand\endgroup%
      \noexpand\expandafter\noexpand\renewcommand\noexpand\expandafter*%
      \noexpand\csname ltr@len@#2\noexpand\endcsname{\the\@tempskipa}%
    }%
  \@tempa
}
\newcommand*{\@setplength}{%
%<class>  \ClassWarning{\KOMAClassName}{%
%<package>  \PackageWarning{scrletter}{%
    Internal macro `\string\@setplength' is deprecated.\MessageBreak
    Please use `\string\setplength' instead}%
  \setplength
}
%    \end{macrocode}
% \end{macro}
% \end{command}
%
%
% \begin{command}{\setplengthtowidth,\setplengthtoheight,\setplengthtodepth,
%                 \setplengthtototalheight}
% \changes{v3.26}{2018/04/26}{added}
% First three commands are similar to \cs{settowidth}, \cs{settoheight} and
% \cs{settodepth} but with pseudo length instead of a \LaTeX{} length. The
% last one is a combination of \cs{setplengthtoheight} + \cs{setplengthtodepth}.
%    \begin{macrocode}
\newcommand*{\setplengthtowidth}[3][]{%
  \begingroup
    \settowidth{\@tempdima}{#3}%
    \setlength{\@tempdima}{#1\@tempdima}%
    \edef\@tempa{\noexpand\endgroup
      \noexpand\expandafter\noexpand\renewcommand\noexpand\expandafter*%
      \noexpand\csname ltr@len@#2\noexpand\endcsname{\the\@tempdima}%
    }%
  \@tempa
}  
\newcommand*{\setplengthtoheight}[3][]{%
  \begingroup
    \settoheight{\@tempdima}{#3}%
    \setlength{\@tempdima}{#1\@tempdima}%
    \edef\@tempa{\noexpand\endgroup
      \noexpand\expandafter\noexpand\renewcommand\noexpand\expandafter*%
      \noexpand\csname ltr@len@#2\noexpand\endcsname{\the\@tempdima}%
    }%
  \@tempa
}  
\newcommand*{\setplengthtodepth}[3][]{%
  \begingroup
    \settodepth{\@tempdima}{#3}%
    \setlength{\@tempdima}{#1\@tempdima}%
    \edef\@tempa{\noexpand\endgroup
      \noexpand\expandafter\noexpand\renewcommand\noexpand\expandafter*%
      \noexpand\csname ltr@len@#2\noexpand\endcsname{\the\@tempdima}%
    }%
  \@tempa
}  
\newcommand*{\setplengthtototalheight}[3][]{%
  \begingroup
    \settoheight{\@tempdima}{#3}%
    \settodepth{\@tempdimb}{#3}%
    \addtolength{\@tempdima}{\@tempdimb}%
    \setlength{\@tempdima}{#1\@tempdima}%
    \edef\@tempa{\noexpand\endgroup
      \noexpand\expandafter\noexpand\renewcommand\noexpand\expandafter*%
      \noexpand\csname ltr@len@#2\noexpand\endcsname{\the\@tempdima}%
    }%
  \@tempa
}  
%    \end{macrocode}
% \end{command}
%
%
% \begin{command}{\addtolengthplength}
%   \changes{v2.8q}{2001/10/06}{added}
% This provides a plus operation of a pseudo length \texttt{\#3} to a \LaTeX{}
% length \texttt{\#2}. Again an optional factor \texttt{\#1} is possible.
%    \begin{macrocode}
\newcommand*{\addtolengthplength}[3][]{%
  \begingroup%
    \setlengthtoplength[{#1}]{\@tempskipa}{#3}%
    \edef\@tempa{\endgroup%
      \noexpand\addtolength{#2}{\the\@tempskipa}}%
  \@tempa%
}
%    \end{macrocode}
% \end{command}
%
%
% \begin{command}{\addtoplength}
% \changes{v2.8q}{2001/10/06}{added}
% \changes{v3.25}{2017/11/29}{using \cs{glueexpr}}
% \changes{v3.36}{2018/04/26}{user command instead of internal macro}
% \begin{macro}{\@addtoplength}
% \changes{v3.36}{2022/02/14}{deprecated}
% This provides a plus operation for one pseudo length \texttt{\#3} to another
% pseudo length \texttt{\#2}. Again an optional factor \texttt{\#1} is possible.
%    \begin{macrocode}
\newcommand*{\addtoplength}[3][]{%
  \begingroup%
    \setlength{\@tempskipa}{\glueexpr #3\relax}%
    \setlength{\@tempskipa}{#1\@tempskipa}%
    \addtolengthplength{\@tempskipa}{#2}%
    \edef\@tempa{\noexpand\endgroup%
      \noexpand\expandafter\noexpand\renewcommand\noexpand\expandafter*%
      \noexpand\csname ltr@len@#2\noexpand\endcsname{\the\@tempskipa}%
      }%
  \@tempa%
}
\newcommand*{\@addtoplength}{%
%<class>  \ClassWarning{\KOMAClassName}{%
%<package>  \PackageWarning{scrletter}{%
    Internal macro `\string\@addtoplength' is deprecated.\MessageBreak
    Please use `\string\addtoplength' instead}%
  \addtoplength}
%</body>
%    \end{macrocode}
% \end{macro}
% \end{command}
%
%
%    \begin{macrocode}
%</letter>
%    \end{macrocode}
% 
% \Finale
% \PrintChanges
% 
\endinput
% Local Variables:
% mode: doctex
% ispell-local-dictionary: "en_US"
% eval: (flyspell-mode 1)
% TeX-master: t
% TeX-engine: luatex-dev
% eval: (setcar (or (cl-member "Index" (setq-local TeX-command-list (copy-alist TeX-command-list)) :key #'car :test #'string-equal) (setq-local TeX-command-list (cons nil TeX-command-list))) '("Index" "mkindex %s" TeX-run-index nil t :help "makeindex for dtx"))
% End: