Debian Codegraph @

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

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (c) 2007 by Andreas B\"uhmann
4 % Copyright (c) 2012 by Michael Ummels <[email protected]>
5 %
6 % This work may be distributed and/or modified under the
7 % conditions of the LaTeX Project Public License, either version 1.3c
8 % of this license or (at your option) any later version.
9 % The latest version of this license is in
10 % http://www.latex-project.org/lppl.txt
11 % and version 1.3 or later is part of all distributions of LaTeX
12 % version 2005/12/01 or later.
13 %
14 % This work has the LPPL maintenance status `maintained'.
15 %
16 % The Current Maintainer of this work is Michael Ummels.
17 %
18 % This work consists of the files tabfigures.dtx, tabfigures.ins and
19 % the derived files tabfigures.sty and tabfigures.pdf.
20 %
21 % \fi
22 %
23 %\iffalse
24 %<*driver>
25 \ProvidesFile{tabfigures.dtx}[2012/01/24 v1.1 Patches for using tabular figures]
26 %</driver>
27 %<package>\NeedsTeXFormat{LaTeX2e}
28 %<package>\ProvidesPackage{tabfigures}[2012/01/24 v1.1 Patches for using tabular figures]
29 %<*driver>
30 \documentclass[fleqn]{ltxdoc}
31
32 \usepackage[T1]{fontenc}
33 \IfFileExists{MinionPro.sty}{
34 \usepackage[smallfamily]{MinionPro}
35 \usepackage[scaled=0.8]{berasans}
36 \usepackage[scaled=0.8]{beramono}
37 }{
38 \usepackage{lmodern}
39 }
40 \usepackage[toc,eqno,enum,bib,lineno,debug]{tabfigures}
41 \usepackage[fleqn]{mathtools}
42 \usepackage{hologo}
43 \usepackage{array}
44 \usepackage{hypdoc}
45 \usepackage{microtype}
46
47 \hypersetup{
48 bookmarksnumbered,
49 colorlinks=false,
50 pdfborder={0 0 0},
51 pdftitle={Using tabular figures with LaTeX},
52 pdfauthor={Andreas B\"uhmann, Michael Ummels}
53 }
54
55 % markup
56 \newcommand*\pkg[1]{\textsf{#1}}
57 \let\cls\pkg
58 \let\bst\pkg
59
60 \makeatletter
61 \let\Tf\tabfig@tbf
62 \makeatother
63
64 \newenvironment{sample}{%
65 \begin{trivlist}%
66 \item
67 }{%
68 \end{trivlist}%
69 }
70
71 \begin{document}
72 \DocInput{tabfigures.dtx}
73 \end{document}
74 %</driver>
75 %<*doc>
76 %\fi
77 %
78 % \CheckSum{242}
79 % \CharacterTable
80 % {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
81 % 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
82 % Digits \0\1\2\3\4\5\6\7\8\9
83 % Exclamation \! Double quote \" Hash (number) \#
84 % Dollar \$ Percent \% Ampersand \&
85 % Acute accent \' Left paren \( Right paren \)
86 % Asterisk \* Plus \+ Comma \,
87 % Minus \- Point \. Solidus \/
88 % Colon \: Semicolon \; Less than \<
89 % Equals \= Greater than \> Question mark \?
90 % Commercial at \@ Left bracket \[ Backslash \\
91 % Right bracket \] Circumflex \^ Underscore \_
92 % Grave accent \` Left brace \{ Vertical bar \|
93 % Right brace \} Tilde \~}
94 %
95 % \GetFileInfo{tabfigures.dtx}
96 %
97 % \title{Using tabular figures with \LaTeX}
98 % \author{Andreas B\"uhmann \and Michael Ummels}
99 % \date{\fileversion\ -- \filedate}
100 % \maketitle
101 %
102 % \begin{abstract}
103 % The \pkg{tabfigures} package is a collection of patches for using
104 % tabular figures in some LaTeX environments where numbers should
105 % line up vertically such as the table of contents and enumerations.
106 % \end{abstract}
107 %
108 %
109 % \section{Introduction}
110 %
111 % Traditionally, there has been no distinction between proportional
112 % figures (\proportionalfigures{0123456789}) and tabular figures%
113 % \marginpar{%
114 % \raggedleft\LARGE
115 % \begin{tabular}[t]{r>{\Tf}r}
116 % 51 & 51 \\
117 % 60 & 60 \\
118 % \end{tabular}
119 % } ({\Tf 0123456789}) in \LaTeX. Effectively, the fonts commonly in use
120 % with \LaTeX\ only include figures of uniform width. This is why, with fonts
121 % like Minion Pro, which use proportional figures by default, you
122 % have to specifically adapt your document class or even the \LaTeX\
123 % kernel to employ tabular figures in the right places:
124 % the table of contents, enumerations and other material where
125 % numbers should line up vertically. The \pkg{tabfigures} package tries
126 % to assist you in the most common situations.
127 % Throughout this document, tabular figures are colored
128 % \textcolor{green!50!black}{green}.
129 %
130 % \section{Usage}
131 %
132 % The current version of this package requires \eTeX\ and the
133 % \pkg{etoolbox} package (version 2.0a or later). You can load this
134 % package by putting
135 % \begin{quote}
136 % |\usepackage|\oarg{options}|{tabfigures}|
137 % \end{quote}
138 % in the preamble of your document. The options, which are described
139 % in the next sections, control in which parts of your document
140 % tabular figures are used. (If no options are specified, the package has
141 % no effect.)
142 %
143 % To have any effect, this package relies on the existence of a command
144 % |\tbfigures| to switch to tabular figures. For instance, the
145 % \pkg{MinionPro} package defines this command. (More precisely,
146 % the \pkg{fontaxes} package, which is included by \pkg{MinionPro},
147 % defines this command). However, this package can also be used as a
148 % companion to the \pkg{fontspec} package: if \pkg{fontspec} is
149 % loaded (and |\tbfigures| is not defined), this package defines
150 % |\tbfigures| as an alias for |\addfontfeatures{Numbers=Monospaced}|.
151 % In this way, \pkg{tabfigures} can also be used with \hologo{XeTeX} and
152 % \hologo{LuaTeX} (provided a suitable OpenType font is loaded with
153 % \pkg{fontspec}).
154 %
155 % \section{Options}
156 %
157 % \DescribeMacro{toc}
158 % The \hyperdef{sample}{toc}{|toc|} option controls whether
159 % tabular figures are used for the numbering and page numbers in the
160 % table of contents, the list of tables/figures, and similar lists.
161 % \begin{sample}
162 % \contentsline{section}{%
163 % \numberline{4}Moving Information Around}{65}{sample.toc} %
164 % \contentsline{subsection}{%
165 % \numberline{4.1}The Table of Contents}{66}{sample.toc} %
166 % \contentsline{subsection}{%
167 % \numberline{4.2}Cross-References}{67}{sample.toc} %
168 % \end{sample}
169 %
170 % \noindent\DescribeMacro{eqno}
171 % The |eqno| option enables tabular figures in equation numbers.
172 % \begin{sample}
173 % \setlength{\abovedisplayskip}{0pt}%
174 % \setlength{\belowdisplayskip}{0pt}%
175 % \setcounter{equation}{18}%
176 % \begin{align}
177 % x&=y & X&=Y & a&=b+c\\
178 % x'&=y' & X'&=Y' & a'&=b\\
179 % x+x'&=y+y' & X+X'&=Y+Y' & a'b&=c'b
180 % \end{align}
181 % \end{sample}
182 %
183 % \noindent\DescribeMacro{enum}
184 % The |enum| option turns on tabular figures in enumerations.
185 % \begin{sample}
186 % \begin{enumerate} \setcounter{enumi}{38}
187 % \item The world's fastest supercomputer will have its speed
188 % measured in ``petaflops'', which represent 1,000 trillion
189 % calculations per second.
190 % \item The medical name for the part of the brain associated with
191 % teenage sulking is ``superior temporal sulcus''.
192 % \item Some Royal Mail stamps, which of course carry the Queen's
193 % image, are printed in Holland.
194 % \end{enumerate}
195 % \end{sample}
196 %
197 % \noindent\DescribeMacro{bib}
198 % The |bib| option activates tabular figures for the labels in the bibliography.
199 % \begin{sample}
200 % \renewcommand\section[2]{}%
201 % \begin{thebibliography}{99}
202 % \bibitem[19]{b19} Leslie Lamport. \LaTeX: A Document Preparation
203 % System. Addison-Wesley, Reading, MA, 2nd Edition, 1994.
204 % \bibitem[20]{b20} American Mathematical Society. User's Guide
205 % for the \pkg{amsmath} Package (Version 2.0). Revised, 2002.
206 % \bibitem[21]{b21} BBC News.
207 % \href{http://www.bbc.co.uk/blogs/magazinemonitor/2006/12/100_things_we_didnt_know_last_2.shtml}%
208 % {100 Things We Didn't Know Last Year.} 28 December 2006.
209 % \end{thebibliography}
210 % \end{sample}
211 % (The previous examples have been taken from these sources.)
212 % \medskip
213 %
214 % \noindent\DescribeMacro{lineno}
215 % The |lineno| option enables tabular figures for line numbers
216 % in conjunction with the \pkg{doc}, \pkg{hypdoc}, \pkg{listings} or
217 % \pkg{fancyvrb} package.
218 % \setcounter{CodelineNo}{48}%
219 % \begin{macrocode}
220 \DeclareOption{eqno}{%
221 \AtBeginDocument{%
222 \@ifpackageloaded{amsmath}{%
223 % \end{macrocode}
224 %
225 % \section{Compatibility}
226 %
227 % This package has been designed to work with the default settings of
228 % the standard document classes \cls{article}, \cls{report} and
229 % \cls{book}, their \pkg{KOMA-Script} counterparts, the \cls{memoir}
230 % class, the \pkg{amsmath} package, and the standard bibliographic
231 % styles \bst{numeric} and \bst{alphabetic} of \pkg{biblatex} v0.6a.
232 %
233 % \StopEventually
234 %
235 % \iffalse
236 %</doc>
237 % \fi
238 %
239 % \section{Implementation}
240 %
241 % \global\setcounter{CodelineNo}{0}
242 % Ease patching of commands. We store the original meaning of |\cmd|
243 % in a safe place and access it later (in the redefinition) with
244 % |\tabfig@\cmd|.
245 % \begin{macrocode}
246 %<*package>
247 \RequirePackage{etoolbox}
248 \newcommand*\tabfig@warning[1]{%
249 \PackageWarningNoLine{tabfigures}{Command \string#1 could not be patched}}
250 % \end{macrocode}
251 % Debugging.
252 % \begin{macrocode}
253 \newif\iftabfig@debug\tabfig@debugfalse
254 \DeclareOption{debug}{\tabfig@debugtrue}
255 % \end{macrocode}
256 %
257 % \subsection{Equation numbers}
258 % We distinguish between the two most frequent cases: \pkg{amsmath}
259 % and standard \LaTeX. All of the following patches work by injecting
260 % |\tabfig@tbf| in the right place. They try to do this as robustly as
261 % possible by reusing the original definition.
262 % \begin{macrocode}
263 \DeclareOption{eqno}{%
264 \AtBeginDocument{%
265 \@ifpackageloaded{amsmath}{%
266 \let\tabfig@maketag@@@\maketag@@@
267 \def\maketag@@@#1{\tabfig@maketag@@@{\tabfig@ttbf{#1}}}%
268 }{%
269 \expandafter\def\expandafter\tabfig@eqnnum\@eqnnum
270 \patchcmd{\tabfig@eqnnum}%
271 {\theequation}{\tabfig@ttbf{\theequation}}%
272 {\def\@eqnnum{{\tabfig@eqnnum}}}%
273 {\tabfig@warning{\@eqnnum}}%
274 }%
275 }%
276 }
277 % \end{macrocode}
278 %
279 % \subsection{Table of contents}
280 % And similar lists such as list of figures and list of tables.
281 % \begin{macrocode}
282 \DeclareOption{toc}{%
283 \AtBeginDocument{%
284 % \end{macrocode}
285 % Generic. First two command that are used in formatting the lists by
286 % default.
287 % \begin{macrocode}
288 \let\tabfig@@dottedtocline\@dottedtocline
289 \def\@dottedtocline#1#2#3#4#5{%
290 \tabfig@@dottedtocline{#1}{#2}{#3}{#4}{\tabfig@ttbf{#5}}%
291 }%
292 \let\tabfig@numberline\numberline
293 \def\numberline#1{\tabfig@numberline{\tabfig@ttbf{#1}}}%
294 % \end{macrocode}
295 % Then a bunch of |\l@|\meta{level} commands for usually available
296 % entry types, which might not use the commands from above.
297 % \begin{macrocode}
298 \let\tabfig@l@part\l@part
299 \def\l@part#1#2{\tabfig@l@part{#1}{\tabfig@ttbf{#2}}}
300 \let\tabfig@l@chapter\l@chapter
301 \def\l@chapter#1#2{\tabfig@l@chapter{#1}{\tabfig@ttbf{#2}}}
302 \let\tabfig@l@section\l@section
303 \def\l@section#1#2{\tabfig@l@section{#1}{\tabfig@ttbf{#2}}}
304 \let\tabfig@l@subsection\l@subsection
305 \def\l@subsection#1#2{\tabfig@l@subsection{#1}{\tabfig@ttbf{#2}}}
306 \let\tabfig@l@subsubsection\l@subsubsection
307 \def\l@subsubsection#1#2{\tabfig@l@subsubsection{#1}{\tabfig@ttbf{#2}}}
308 \let\tabfig@l@paragraph\l@paragraph
309 \def\l@paragraph#1#2{\tabfig@l@paragraph{#1}{\tabfig@ttbf{#2}}}
310 \let\tabfig@l@subparagraph\l@subparagraph
311 \def\l@subparagraph#1#2{\tabfig@l@subparagraph{#1}{\tabfig@ttbf{#2}}}
312 \let\tabfig@l@figure\l@figure
313 \def\l@figure#1#2{\tabfig@l@figure{#1}{\tabfig@ttbf{#2}}}
314 \let\tabfig@l@table\l@table
315 \def\l@table#1#2{\tabfig@l@table{#1}{\tabfig@ttbf{#2}}}
316 % \end{macrocode}
317 % Special support for parts and chapters in \pkg{memoir}.
318 % \begin{macrocode}
319 \@ifclassloaded{memoir}{%
320 \apptocmd{\cftpartpresnum}%
321 {\tabfig@tbf}{}{\tabfig@warning{\cftpartpresnum}}%
322 \apptocmd{\cftchapterpresnum}%
323 {\tabfig@tbf}{}{\tabfig@warning{\cftchapterpresnum}}%
324 }{}%
325 }%
326 }
327 % \end{macrocode}
328 %
329 % \subsection{Enumerations}
330 % Labels in enumerations.
331 % \begin{macrocode}
332 \DeclareOption{enum}{%
333 \AtBeginDocument{%
334 \patchcmd{\labelenumi}%
335 {\theenumi}{\tabfig@ttbf{\theenumi}}%
336 {}{\tabfig@warning{\labelenumi}}%
337 \patchcmd{\labelenumii}%
338 {\theenumii}{\tabfig@ttbf{\theenumii}}%
339 {}{\tabfig@warning{\labelenumii}}%
340 \patchcmd{\labelenumiii}%
341 {\theenumiii}{\tabfig@ttbf{\theenumiii}}%
342 {}{\tabfig@warning{\labelenumiii}}%
343 \patchcmd{\labelenumiv}%
344 {\theenumiv}{\tabfig@ttbf{\theenumiv}}%
345 {}{\tabfig@warning{\labelenumiv}}%
346 }%
347 }
348 % \end{macrocode}
349 %
350 % \subsection{Bibliography}
351 % Labels in the bibliography.
352 % \begin{macrocode}
353 \DeclareOption{bib}{%
354 \AtBeginDocument{%
355 \let\tabfig@@biblabel\@biblabel
356 \def\@biblabel#1{\tabfig@@biblabel{\tabfig@ttbf{#1}}}%
357 \@ifpackageloaded{biblatex}{%
358 \DeclareFieldFormat{labelnumberwidth}{\mkbibbrackets{\tabfig@ttbf{#1}}}%
359 \DeclareFieldFormat{labelalphawidth}{\mkbibbrackets{\tabfig@ttbf{#1}}}%
360 }{}%
361 }%
362 }
363 % \end{macrocode}
364 %
365 % \subsection{Line numbers}
366 % \begin{macrocode}
367 \DeclareOption{lineno}{%
368 \AtBeginDocument{%
369 % \end{macrocode}
370 % Support for the \pkg{doc} and \pkg{hypdoc} packages.
371 % \begin{macrocode}
372 \@ifpackageloaded{hypdoc}{%
373 \ifpatchable{\theCodelineNo}{\HDorg@theCodelineNo}{%
374 \patchcmd{\HDorg@theCodelineNo}%
375 {\arabic{CodelineNo}}%
376 {\tabfig@ttbf{\arabic{CodelineNo}}}%
377 {}{\tabfig@warning{\HDorg@theCodelineNo}}%
378 }{%
379 \patchcmd{\theCodelineNo}%
380 {\arabic{CodelineNo}}%
381 {\tabfig@ttbf{\arabic{CodelineNo}}}%
382 {}{\tabfig@warning{\theCodelineNo}}%
383 }%
384 }{%
385 \@ifpackageloaded{doc}{%
386 \patchcmd{\theCodelineNo}%
387 {\arabic{CodelineNo}}%
388 {\tabfig@ttbf{\arabic{CodelineNo}}}%
389 {}{\tabfig@warning{\theCodelineNo}}%
390 }{}%
391 }%
392 % \end{macrocode}
393 % Support for the \pkg{listings} package.
394 % \begin{macrocode}
395 \@ifpackageloaded{listings}{%
396 \apptocmd{\lst@numberstyle}{\tabfig@tbf}%
397 {}{\tabfig@warning{\lst@numberstyle}}%
398 }{}%
399 % \end{macrocode}
400 % Support for the \pkg{fancyvrb} package.
401 % \begin{macrocode}
402 \@ifpackageloaded{fancyvrb}{%
403 \patchcmd{\theFancyVerbLine}%
404 {\arabic{FancyVerbLine}}%
405 {\tabfig@ttbf{\arabic{FancyVerbLine}}}%
406 {}{\tabfig@warning{\theFancyVerbLine}}%
407 }{}
408 }%
409 }
410 \ProcessOptions\relax
411 % \end{macrocode}
412 %
413 % \subsection{Auxiliary macros}
414 % These commands are used for switching to tabular figures. This can be
415 % redefined to allow debugging, disabling, etc.
416 % \begin{macrocode}
417 \newcommand*\tabfig@tbf{\tbfigures}
418 \DeclareTextFontCommand{\tabfig@ttbf}{\tabfig@tbf}
419 % \end{macrocode}
420 % Visual debugging: Set tabular figures (produced by this package) in
421 % green.
422 % \begin{macrocode}
423 \iftabfig@debug
424 \RequirePackage{xcolor}%
425 \colorlet{tabfig@debug}{green!50!black}%
426 \renewcommand\tabfig@tbf{\tbfigures\color{tabfig@debug}}%
427 \fi
428 % \end{macrocode}
429 % Check if figure versions are supported at all. If not, we cannot do
430 % anything useful.
431 % \begin{macrocode}
432 \AtBeginDocument{%
433 \@ifundefined{tbfigures}{%
434 \@ifpackageloaded{fontspec}{%
435 \def\tbfigures{\addfontfeatures{Numbers=Monospaced}}%
436 }{%
437 \PackageWarningNoLine{tabfigures}{There is no command
438 \string\tbfigures\space to support tabular figures}%
439 \let\tabfig@tbf\@empty
440 }%
441 }{}%
442 }
443 %</package>
444 % \end{macrocode}
445 %
446 % \Finale
447 \endinput