Debian Codegraph @

texmf-dist/source/latex/everysel/everysel.dtx

raw
1 % \iffalse meta-comment
2 %
3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4 %
5 % Copyright (C) Martin Schröder, 1994–2001
6 % Marei Peischl (peiTeX) <[email protected]>, 2021
7 %
8 % This work may be distributed and/or modified under the
9 % conditions of the LaTeX Project Public License, either version 1.3c
10 % of this license or (at your option) any later version.
11 % The latest version of this license is in
12 % http://www.latex-project.org/lppl.txt
13 % and version 1.3c or later is part of all distributions of LaTeX
14 % version 2005/12/01 or later.
15 %
16 % This work has the LPPL maintenance status `maintained'.
17 %
18 % The Current Maintainer of this work is
19 % Marei Peischl <[email protected]>.
20 %
21 % This work consists of the files
22 % README.md
23 % everysel.dtx
24 % everysel.ins
25 % and the derived files
26 % everysel.sty
27 % everysel-2011/10/28.sty
28 % everysel.pdf
29 %
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31 %
32 % \fi
33 % \iffalse
34 %<package|fallback>\NeedsTeXFormat{LaTeX2e}[1995/12/01]
35 %<package>\ProvidesPackage{everysel}
36 %<package> [2021/01/20 v2.1 EverySelectfont Package (MS)]
37 %
38 %<*driver>
39 \documentclass[a4paper]{ltxdoc}
40 \usepackage[T1]{fontenc}
41 \usepackage{url}
42 \usepackage[toc]{multitoc}
43 \usepackage{lmodern,microtype}
44 \usepackage{geometry}
45 \usepackage{everysel}
46 \GetFileInfo{everysel.sty}
47 \RecordChanges % Gather update information
48 \EnableCrossrefs
49 %%\DisableCrossrefs% Say \DisableCrossrefs if index is ready
50 \CodelineIndex % Index code by line number
51 %\OnlyDescription % comment out for implementation details
52 %%\OldMakeIndex % use if your MakeIndex is pre-v2.9
53 \setcounter{IndexColumns}{1}
54 % onecolumn glossary
55 %% \makeatletter
56 %% \renewenvironment{theglossary}{%
57 %% \glossary@prologue
58 %% \setlength\emergencystretch{5em}
59 %% \GlossaryParms \let\item\@idxitem \ignorespaces}{}
60 %% \makeatother
61 \setlength{\IndexMin}{40ex}
62 \setlength{\columnseprule}{.4pt}
63 \addtolength{\oddsidemargin}{2cm}
64 \addtolength{\textwidth}{-2cm}
65 \raggedright % otherwise we get over/underfull hboxes
66 \begin{document}
67 \DocInput{everysel.dtx}
68 \PrintChanges
69 % Make sure that the index is not printed twice
70 % (ltxdoc.cfg might have a second \PrintIndex command)
71 \let\PrintChanges\relax
72 \end{document}
73 %</driver>
74 % \fi
75 % \CheckSum{189}
76 %% \CharacterTable
77 %% {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
78 %% 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
79 %% Digits \0\1\2\3\4\5\6\7\8\9
80 %% Exclamation \! Double quote \" Hash (number) \#
81 %% Dollar \$ Percent \% Ampersand \&
82 %% Acute accent \' Left paren \( Right paren \)
83 %% Asterisk \* Plus \+ Comma \,
84 %% Minus \- Point \. Solidus \/
85 %% Colon \: Semicolon \; Less than \<
86 %% Equals \= Greater than \> Question mark \?
87 %% Commercial at \@ Left bracket \[ Backslash \\
88 %% Right bracket \] Circumflex \^ Underscore \_
89 %% Grave accent \` Left brace \{ Vertical bar \|
90 %% Right brace \} Tilde \~}
91 %
92 % \changes{v1.00}{1996-05-24}{New}
93 % \changes{v1.02}{1998-04-11}{Minor documentation enhancements}
94 % \changes{v1.02}{1998-08-09}{Minor documentation enhancements}
95 % \changes{v1.03}{1999/06/08}{Moved to LPPL}
96 % \changes{v1.1}{2009/05/30}{New address, LPPL 1.3}
97 %
98 %
99 % ^^A -----------------------------
100 %
101 % \pagestyle{headings}
102 %
103 % \newcommand*{\file}[1]{\texttt{#1}}
104 % \newcommand*{\package}[1]{\textsf{#1}}
105 % \hyphenation{every-select-font}
106 %
107 %
108 % ^^A -----------------------------
109 %
110 % \changes{v1.01}{1997-03-09}{Fixed use of \cs{newline} in title.}
111 % \title{\unskip
112 % The obsolete \package{EverySel} package^^A
113 % \thanks{^^A
114 % The version umber of this file is \fileversion.\protect\newline
115 % The name \textsf{EverySel} is a tribute to the $8+3$ file-naming
116 % convention of certain ``operating systems'' and their ``file systems'';
117 % strictly speaking it should be \textsf{EverySelectfont}.}^^A
118 % }
119 % \author{Martin Schröder\thanks{maintained by Marei Peischl}}
120 % \maketitle
121 %
122 %
123 % ^^A -----------------------------
124 % \changes{v2.0}{2021/01/17}{Information on new kernel methods}
125 % \renewcommand*{\abstractname}{Why you should no longer use this package:}
126 % \begin{abstract}
127 % This packages provides hooks into the NFSS-command
128 % \cs{selectfont} called \cs{EverySelectfont} and
129 % \cs{AtNextSelectfont} analogous to \cs{AtBeginDocument}.
130 % In January 2021 the hook management \LaTeX{} provides since autumn 2020 the kernel directly contains these hooks. Information on their usage can be found in the the corresponding documentation for
131 % \package{lthooks}\cite{lthooks-doc} and look for Hooks provided in NFSS command.
132 % We only provide this package to allow backwards compatibility.
133 % For current versions of \LaTeX{} it's only mapping the hooks to the original \package{everysel} macros.
134 % In case you use an older \LaTeX{} format, \package{everysel} will automatically fallback to its' old implementation by loading \package{everysel-2011/10/28.sty}.
135 % \end{abstract}
136 %
137 % \pagestyle{headings}
138 %
139 %
140 % ^^A -----------------------------
141 %
142 % \tableofcontents
143 %
144 %
145 % ^^A -----------------------------
146 %
147 % \section{Introduction}
148 % ^^A
149 % This package provides the hooks \cs{EverySelectfont} and
150 % \cs{AtNextSelectfont} whose arguments are executed just after
151 % \LaTeX{} has loaded a new font using \cs{selectfont} (which means
152 % that it will be executed after \emph{every} font loaded via NFSS).
153 %
154 % An example application would be a package for setting ragged text
155 % which needs to distiguinsh between monospaced and proportional
156 % fonts.
157 % Such a package exists: \package{ragged2e}\cite{package:ragged2e}.
158 %
159 %
160 % ^^A -----------------------------
161 %
162 % \section{Usage}
163 % ^^A
164 % \DescribeMacro{\EverySelectfont}
165 % \cs{EverySelectfont}\marg{code} declares
166 % \mbox{$\langle$\emph{code}$\rangle$} that is saved internally
167 % and executed just after \emph{each} \cs{selectfont}.
168 %
169 % \emph{Warning:} The \mbox{$\langle$\emph{code}$\rangle$} is saved
170 % globally; there is currently no way to remove it.
171 %
172 % \DescribeMacro{\AtNextSelectfont}
173 % \cs{AtNextSelectfont}\marg{code} declares
174 % \mbox{$\langle$\emph{code}$\rangle$} that is saved internally
175 % and executed just after \emph{and only the next} \cs{selectfont}.
176 %
177 % Repeated use of the commands is permitted: the code in their
178 % argument is stored (and executed) in the order of their
179 % declarations.
180 %
181 % The argument of \cs{AtNextSelectfont} is executed \emph{after}
182 % the argument of \cs{EverySelectfont}.
183 %
184 %
185 % ^^A -----------------------------
186 %
187 % \section{Options}
188 % ^^A
189 % The package has no options.
190 %
191 %
192 % ^^A -----------------------------
193 %
194 % \section{Required packages}
195 % ^^A
196 % The package requires no further packages.
197 %
198 %
199 % ^^A -----------------------------
200 %
201 % \StopEventually{^^A
202 %
203 %
204 % ^^A -----------------------------
205 %
206 % \section{Acknowledgements}
207 % ^^A
208 % David Carlisle provided the solution for my problems with \cs{CheckCommand}.
209 %
210 % Thanks to the \LaTeX-Project-Team for creating solutions which made this an obsolete package. Special thanks to Ulrike Fischer to keep the maintainer up to date.
211 %
212 %
213 % ^^A -----------------------------
214 %
215 % \begin{thebibliography}{1}
216 % \raggedright
217 % \bibitem{lthooks-doc}
218 % Frank Mittelbach.
219 % \newblock The \package{ltshipout} package.
220 % \newblock \url{http://mirrors.ctan.org/macros/latex/base/lthooks-doc.pdf}
221 % \bibitem{package:tracefnt}
222 % Frank Mittelbach and Rainer Sch\"opf.
223 % \newblock The \package{tracefnt} package for use with the new
224 % font selection scheme.
225 % \newblock \url{http://mirrors.ctan.org/macros/latex/base/ltfsstrc.dtx}.
226 % \newblock \LaTeXe{} package.
227 % \bibitem{package:ragged2e}
228 % Martin Schr\"oder.
229 % \newblock The \package{ragged2e} package.
230 % \newblock \url{http://mirrors.ctan.org/macros/latex/contrib/supported/ms/ragged2e.dtx}.
231 % \newblock \LaTeXe{} package.
232 % \end{thebibliography}
233 %
234 % }
235 %
236 %
237 % ^^A -----------------------------
238 %
239 % \section{The Implementation}
240 % ^^A
241 % \changes{v2.0}{2021/01/17}{Emulate everysel if the kernel is new enough.}
242 % \iffalse
243 %<*package>
244 % \fi
245 % \begin{macrocode}
246 \providecommand\IfFormatAtLeastTF{\@ifl@t@r\fmtversion}
247 \IfFormatAtLeastTF{2021/01/05}{}{\input{everysel-2011-10-28.sty}}
248 \IfFormatAtLeastTF{2021/01/05}{}{\endinput}
249 \newcommand*{\EverySelectfont}[1]{\AddToHook{selectfont}{#1}}
250 \newcommand*{\AtNextSelectfont}[1]{\AddToHookNext{selectfont}{#1}}
251 % \end{macrocode}
252 % \changes{v2.1}{2021-01-20}{Add \textbackslash{}@EverySelectfont@Legacy + conditional warning}
253 % Some packages are using the intial hook of everysel internally (see also \url{https://github.com/latex3/latex2e/issues/474}).
254 % So Version 2.1 provides these macros to ensure compatibility.
255 % In case someone is changing the inital hook everysel will now show a warning to inform package authors to switch to lthooks instead.
256 % A future release is planned to always trigger this warning.
257 % \begin{macrocode}
258 \newcommand*\@EverySelectfont@Legacy{\let\@EverySelectfont@Init\undefined}
259 \newcommand*{\@EverySelectfont@Init}{\@EverySelectfont@Legacy}
260 \AddToHook{begindocument}{%
261 \expandafter\ifx\@EverySelectfont@Init\@EverySelectfont@Legacy\else
262 \PackageWarningNoLine{everysel}{%
263 Everysel is no longer required.,\MessageBreak
264 The LaTeX kernel is now providing the same functionality itself.,\MessageBreak
265 See the package documentation or lthooks-doc for further information.
266 }%
267 \fi
268 \@EverySelectfont@Init
269 }
270 % \end{macrocode}
271 % \iffalse
272 %</package>
273 % \fi
274 % ^^A -----------------------------
275 % \subsection{The original implementation by Martin Schröder}
276 % To provide compatibility for older \LaTeX{} formats we wrap the
277 % original implementation of \package{everysel} version 1.2 into
278 % the fallback package \package{everyshi-2011-01-10}.
279 % \iffalse
280 %<*fallback>
281 % \fi
282 % \subsubsection{Allocations}
283 % ^^A
284 % First we allocate the hooks
285 % \begin{macro}{\@EverySelectfont@EveryHook}
286 % The code to be executed just after the normal \cs{selectfont}.
287 % \begin{macrocode}
288 \newcommand{\@EverySelectfont@EveryHook}{}
289 % \end{macrocode}
290 % \end{macro}
291 %
292 % \begin{macro}{\@EverySelectfont@AtNextHook}
293 % The code to be executed just after the normal \cs{selectfont}
294 % and \cs{@EverySelectfont@EveryHook}.
295 % \begin{macrocode}
296 \newcommand{\@EverySelectfont@AtNextHook}{}
297 % \end{macrocode}
298 % \end{macro}
299 %
300 %
301 % ^^A -----------------------------
302 %
303 % \subsubsection{The user-visible commands}
304 % ^^A
305 % \begin{macro}{\EverySelectfont}
306 % \begin{macro}{\AtNextSelectfont}
307 % These commands are modeled after \cs{AtBeginDocument}.
308 % \begin{macrocode}
309 \newcommand*{\EverySelectfont}[1]
310 {\g@addto@macro\@EverySelectfont@EveryHook{#1}}
311 \newcommand*{\AtNextSelectfont}[1]
312 {\g@addto@macro\@EverySelectfont@AtNextHook{#1}}
313 % \end{macrocode}
314 % \end{macro}
315 % \end{macro}
316 %
317 %
318 % ^^A -----------------------------
319 %
320 % \subsubsection{Inserting the hooks}
321 % ^^A
322 % The hooks are placed \emph{inside} \cs{selectfont}.
323 % Unfortunately for us there are \emph{two} versions of
324 % \cs{selectfont} in normal \LaTeX: One is defined in the kernel and
325 % the other by the package \package{tracefnt}\cite{package:tracefnt}.
326 % The \package{CJK} also redefines \cs{selectfont}.
327 %
328 % So we have to check for three versions.
329 % \begin{macro}{\@EverySelectfont@Init}
330 % We do this in the macro \cs{@EverySelectfont@Init}, which is
331 % executed just after \cs{begin\{document\}} (with the aid of
332 % \cs{AtBeginDocument}), when we know for sure which version of
333 % \cs{selectfont} we have to overload.
334 % \begin{macrocode}
335 \newcommand*{\@EverySelectfont@Init}{%
336 \message{ABD: EverySelectfont initializing macros}%
337 % \end{macrocode}
338 % We have to distinguish three cases: \package{tracefnt},
339 % \package{CJK} and everything else.
340 % \begin{macrocode}
341 \@ifpackageloaded{tracefnt}{%
342 % \end{macrocode}
343 % And we have a problem: \cs{selectfont} is defined using
344 % \cs{DeclareRobustCommand}, which really defines
345 % \cs{selectfont\textvisiblespace}.
346 % So instead of simply using \cs{CheckCommand} we also have to use
347 % \cs{expandafter} and \cs{csname}\ldots\cs{endcsname}.
348 % \begin{macrocode}
349 \expandafter\CheckCommand\csname selectfont \endcsname{%
350 \ifx\f@linespread\baselinestretch \else
351 \set@fontsize\baselinestretch\f@size\f@baselineskip \fi
352 \xdef\font@name{%
353 \csname\curr@fontshape/\f@size\endcsname}%
354 \pickup@font
355 \font@name
356 \ifnum \tracingfonts>\tw@
357 \@font@info{Switching to \font@name}\fi
358 \size@update
359 \enc@update
360 }%
361 }{%
362 % \end{macrocode}
363 % The case with \package{CJK}
364 % \changes{v1.2}{2011-10-27}{Check for \package{CJK}.}
365 % \begin{macrocode}
366 \@ifpackageloaded{CJK}{%
367 \expandafter\CheckCommand\csname selectfont \endcsname{%
368 \ifx\f@linespread\baselinestretch \else
369 \set@fontsize\baselinestretch\f@size\f@baselineskip \fi
370 \xdef\font@name{%
371 \csname\curr@fontshape/\f@size\endcsname}%
372 \pickup@font
373 \font@name
374 \expandafter\ifx\csname CJK@\curr@fontshape\endcsname \relax
375 \else
376 \CJK@bold@false
377 \csname CJK@\curr@fontshape\endcsname
378 \fi
379 \size@update
380 \enc@update}%
381 }{%
382 % \end{macrocode}
383 % Now the default (no \package{tracefnt} and no \package{CJK}).
384 % \begin{macrocode}
385 \expandafter\CheckCommand\csname selectfont \endcsname{%
386 \ifx\f@linespread\baselinestretch \else
387 \set@fontsize\baselinestretch\f@size\f@baselineskip \fi
388 \xdef\font@name{%
389 \csname\curr@fontshape/\f@size\endcsname}%
390 \pickup@font
391 \font@name
392 \size@update
393 \enc@update
394 }%
395 }%
396 }%
397 % \end{macrocode}
398 % After the checks we can be sure we have the correct version of
399 % \cs{selectfont}, so we redefine it with our hooks.
400 % \begin{macrocode}
401 \DeclareRobustCommand{\selectfont}%
402 {%
403 \ifx\f@linespread\baselinestretch \else
404 \set@fontsize\baselinestretch\f@size\f@baselineskip \fi
405 \xdef\font@name{%
406 \csname\curr@fontshape/\f@size\endcsname}%
407 \pickup@font
408 \font@name
409 \@EverySelectfont@EveryHook
410 \@EverySelectfont@AtNextHook
411 % \end{macrocode}
412 % We have to reset \cs{@EverySelectfont@AtNextHook} after each use.
413 % \begin{macrocode}
414 \gdef\@EverySelectfont@AtNextHook{}%
415 \size@update
416 \enc@update
417 }%
418 % \end{macrocode}
419 % The additions of \package{tracefnt} to \cs{selectfont} can be
420 % implemented using \cs{EverySelectfont}.
421 % \begin{macrocode}
422 \@ifpackageloaded{tracefnt}{%
423 \EverySelectfont{%
424 \ifnum \tracingfonts>\tw@
425 \@font@info{Switching to \font@name}\fi}%
426 }{}%
427 % \end{macrocode}
428 % The additions of \package{CJK} to \cs{selectfont} can be
429 % implemented using \cs{EverySelectfont}.
430 % \changes{v1.2}{2011-10-27}{Check for \package{CJK}.}
431 % \begin{macrocode}
432 \@ifpackageloaded{CJK}{%
433 \EverySelectfont{%
434 \expandafter\ifx\csname CJK@\curr@fontshape\endcsname \relax
435 \else
436 \CJK@bold@false
437 \csname CJK@\curr@fontshape\endcsname
438 \fi}%
439 }{}%
440 % \end{macrocode}
441 % Since \cs{@EverySelectfont@Init} should only be used once it is
442 % self-destructing.
443 % \begin{macrocode}
444 \let\@EverySelectfont@Init\undefined
445 }
446 % \end{macrocode}
447 % Finally we insert \cs{EverySelectfont@Init} into \cs{begin\{document\}}.
448 % \begin{macrocode}
449 \AtBeginDocument{\@EverySelectfont@Init}
450 % \end{macrocode}
451 % \end{macro}
452 %
453 %
454 % ^^A -----------------------------
455 % \iffalse
456 %</fallback>
457 % \fi
458 %
459 %
460 % ^^A -----------------------------
461 %
462 % \Finale
463 % ^^A