summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/tabfigures/tabfigures.dtx
blob: 41271b742e86dbaba814b09aefa4edfdd9cb3f2f (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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
% \iffalse meta-comment
%
% Copyright (c) 2007 by Andreas B\"uhmann
% Copyright (c) 2012 by Michael Ummels <michael.ummels@rwth-aachen.de>
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3c
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Michael Ummels.
%
% This work consists of the files tabfigures.dtx, tabfigures.ins and
% the derived files tabfigures.sty and tabfigures.pdf.
%
% \fi
%
%\iffalse
%<*driver>
\ProvidesFile{tabfigures.dtx}[2012/01/24 v1.1 Patches for using tabular figures]
%</driver>
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{tabfigures}[2012/01/24 v1.1 Patches for using tabular figures]
%<*driver>
\documentclass[fleqn]{ltxdoc}

\usepackage[T1]{fontenc}
\IfFileExists{MinionPro.sty}{
  \usepackage[smallfamily]{MinionPro}
  \usepackage[scaled=0.8]{berasans}
  \usepackage[scaled=0.8]{beramono}
}{
  \usepackage{lmodern}
}
\usepackage[toc,eqno,enum,bib,lineno,debug]{tabfigures}
\usepackage[fleqn]{mathtools}
\usepackage{hologo}
\usepackage{array}
\usepackage{hypdoc}
\usepackage{microtype}

\hypersetup{
  bookmarksnumbered,
  colorlinks=false,
  pdfborder={0 0 0},
  pdftitle={Using tabular figures with LaTeX},
  pdfauthor={Andreas B\"uhmann, Michael Ummels}
}

% markup
\newcommand*\pkg[1]{\textsf{#1}}
\let\cls\pkg
\let\bst\pkg

\makeatletter
\let\Tf\tabfig@tbf
\makeatother

\newenvironment{sample}{%
  \begin{trivlist}%
  \item
}{%
  \end{trivlist}%
}

\begin{document}
\DocInput{tabfigures.dtx}
\end{document}
%</driver>
%<*doc>
%\fi
%
% \CheckSum{242}
% \CharacterTable
%  {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
%   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
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
% \GetFileInfo{tabfigures.dtx}
%
% \title{Using tabular figures with \LaTeX}
% \author{Andreas B\"uhmann \and Michael Ummels}
% \date{\fileversion\ -- \filedate}
% \maketitle
%
% \begin{abstract}
%  The \pkg{tabfigures} package is a collection of patches for using
%  tabular figures in some LaTeX environments where numbers should
%  line up vertically such as the table of contents and enumerations.
% \end{abstract}
%  
%
% \section{Introduction}
% 
% Traditionally, there has been no distinction between proportional
% figures (\proportionalfigures{0123456789}) and tabular figures%
% \marginpar{%
%   \raggedleft\LARGE
%   \begin{tabular}[t]{r>{\Tf}r}
%     51 & 51 \\
%     60 & 60 \\
%   \end{tabular}
% } ({\Tf 0123456789}) in \LaTeX. Effectively, the fonts commonly in use
% with \LaTeX\ only include figures of uniform width. This is why, with fonts
% like Minion Pro, which use proportional figures by default, you
% have to specifically adapt your document class or even the \LaTeX\
% kernel to employ tabular figures in the right places:
% the table of contents, enumerations and other material where
% numbers should line up vertically. The \pkg{tabfigures} package tries
% to assist you in the most common situations.
% Throughout this document, tabular figures are colored
% \textcolor{green!50!black}{green}.
%
% \section{Usage}
%
% The current version of this package requires \eTeX\ and the
% \pkg{etoolbox} package (version 2.0a or later). You can load this
% package by putting
% \begin{quote}
% |\usepackage|\oarg{options}|{tabfigures}|
% \end{quote}
% in the preamble of your document. The options, which are described
% in the next sections, control in which parts of your document
% tabular figures are used. (If no options are specified, the package has
% no effect.)
%
% To have any effect, this package relies on the existence of a command
% |\tbfigures| to switch to tabular figures. For instance, the
% \pkg{MinionPro} package defines this command. (More precisely,
% the \pkg{fontaxes} package, which is included by \pkg{MinionPro},
% defines this command). However, this package can also be used as a
% companion to the \pkg{fontspec} package: if \pkg{fontspec} is
% loaded (and |\tbfigures| is not defined), this package defines
% |\tbfigures| as an alias for |\addfontfeatures{Numbers=Monospaced}|.
% In this way, \pkg{tabfigures} can also be used with \hologo{XeTeX} and
% \hologo{LuaTeX} (provided a suitable OpenType font is loaded with
% \pkg{fontspec}).
%
% \section{Options}
%
% \DescribeMacro{toc}
% The \hyperdef{sample}{toc}{|toc|} option controls whether
% tabular figures are used for the numbering and page numbers in the
% table of contents, the list of tables/figures, and similar lists.
%   \begin{sample}
%     \contentsline{section}{%
%       \numberline{4}Moving Information Around}{65}{sample.toc} %
%     \contentsline{subsection}{%
%       \numberline{4.1}The Table of Contents}{66}{sample.toc} %
%     \contentsline{subsection}{%
%       \numberline{4.2}Cross-References}{67}{sample.toc} %
%   \end{sample}
%
% \noindent\DescribeMacro{eqno}
% The |eqno| option enables tabular figures in equation numbers.
%   \begin{sample}
%     \setlength{\abovedisplayskip}{0pt}%
%     \setlength{\belowdisplayskip}{0pt}%
%     \setcounter{equation}{18}%
%     \begin{align}
%       x&=y       & X&=Y       & a&=b+c\\
%       x'&=y'     & X'&=Y'     & a'&=b\\
%       x+x'&=y+y' & X+X'&=Y+Y' & a'b&=c'b
%     \end{align}
%   \end{sample}
%
% \noindent\DescribeMacro{enum}
% The |enum| option turns on tabular figures in enumerations.
%   \begin{sample}
%     \begin{enumerate} \setcounter{enumi}{38}
%     \item The world's fastest supercomputer will have its speed
%       measured in ``petaflops'', which represent 1,000 trillion
%       calculations per second.
%     \item The medical name for the part of the brain associated with
%       teenage sulking is ``superior temporal sulcus''.
%     \item Some Royal Mail stamps, which of course carry the Queen's
%       image, are printed in Holland.
%     \end{enumerate}
%   \end{sample}
%
% \noindent\DescribeMacro{bib}
% The |bib| option activates tabular figures for the labels in the bibliography.
%   \begin{sample}
%     \renewcommand\section[2]{}%
%     \begin{thebibliography}{99}
%     \bibitem[19]{b19} Leslie Lamport. \LaTeX: A Document Preparation
%       System. Addison-Wesley, Reading, MA, 2nd Edition, 1994.
%     \bibitem[20]{b20} American Mathematical Society. User's Guide
%       for the \pkg{amsmath} Package (Version 2.0). Revised, 2002.
%     \bibitem[21]{b21} BBC News.
%       \href{http://www.bbc.co.uk/blogs/magazinemonitor/2006/12/100_things_we_didnt_know_last_2.shtml}%
%       {100 Things We Didn't Know Last Year.} 28 December 2006.
%     \end{thebibliography}
%   \end{sample}
% (The previous examples have been taken from these sources.)
% \medskip
%
% \noindent\DescribeMacro{lineno}
% The |lineno| option enables tabular figures for line numbers
% in conjunction with the \pkg{doc}, \pkg{hypdoc}, \pkg{listings} or
% \pkg{fancyvrb} package.
% \setcounter{CodelineNo}{48}%
%    \begin{macrocode}
\DeclareOption{eqno}{%
  \AtBeginDocument{%
    \@ifpackageloaded{amsmath}{%
%    \end{macrocode}
%
% \section{Compatibility}
%
% This package has been designed to work with the default settings of
% the standard document classes \cls{article}, \cls{report} and
% \cls{book}, their \pkg{KOMA-Script} counterparts, the \cls{memoir}
% class, the \pkg{amsmath} package, and the standard bibliographic
% styles \bst{numeric} and \bst{alphabetic} of \pkg{biblatex} v0.6a.
%
% \StopEventually
%
% \iffalse
%</doc>
% \fi
%
% \section{Implementation}
%
% \global\setcounter{CodelineNo}{0}
% Ease patching of commands. We store the original meaning of |\cmd|
% in a safe place and access it later (in the redefinition) with
% |\tabfig@\cmd|.
%    \begin{macrocode}
%<*package>
\RequirePackage{etoolbox}
\newcommand*\tabfig@warning[1]{%
  \PackageWarningNoLine{tabfigures}{Command \string#1 could not be patched}}
%    \end{macrocode}
% Debugging.
%    \begin{macrocode}
\newif\iftabfig@debug\tabfig@debugfalse
\DeclareOption{debug}{\tabfig@debugtrue}
%    \end{macrocode}
%
% \subsection{Equation numbers}
% We distinguish between the two most frequent cases: \pkg{amsmath}
% and standard \LaTeX. All of the following patches work by injecting
% |\tabfig@tbf| in the right place. They try to do this as robustly as
% possible by reusing the original definition.
%    \begin{macrocode}
\DeclareOption{eqno}{%
  \AtBeginDocument{%
    \@ifpackageloaded{amsmath}{%
      \let\tabfig@maketag@@@\maketag@@@
      \def\maketag@@@#1{\tabfig@maketag@@@{\tabfig@ttbf{#1}}}%
    }{%
      \expandafter\def\expandafter\tabfig@eqnnum\@eqnnum
      \patchcmd{\tabfig@eqnnum}%
        {\theequation}{\tabfig@ttbf{\theequation}}%
        {\def\@eqnnum{{\tabfig@eqnnum}}}%
        {\tabfig@warning{\@eqnnum}}%
    }%
  }%
}
%    \end{macrocode}
% 
% \subsection{Table of contents}
% And similar lists such as list of figures and list of tables.
%    \begin{macrocode}
\DeclareOption{toc}{%
  \AtBeginDocument{%
%    \end{macrocode}
% Generic. First two command that are used in formatting the lists by
% default.
%    \begin{macrocode}
    \let\tabfig@@dottedtocline\@dottedtocline
    \def\@dottedtocline#1#2#3#4#5{%
      \tabfig@@dottedtocline{#1}{#2}{#3}{#4}{\tabfig@ttbf{#5}}%
    }%
    \let\tabfig@numberline\numberline
    \def\numberline#1{\tabfig@numberline{\tabfig@ttbf{#1}}}%
%    \end{macrocode}
% Then a bunch of |\l@|\meta{level} commands for usually available
% entry types, which might not use the commands from above.
%    \begin{macrocode}
    \let\tabfig@l@part\l@part
    \def\l@part#1#2{\tabfig@l@part{#1}{\tabfig@ttbf{#2}}}
    \let\tabfig@l@chapter\l@chapter
    \def\l@chapter#1#2{\tabfig@l@chapter{#1}{\tabfig@ttbf{#2}}}
    \let\tabfig@l@section\l@section
    \def\l@section#1#2{\tabfig@l@section{#1}{\tabfig@ttbf{#2}}}
    \let\tabfig@l@subsection\l@subsection
    \def\l@subsection#1#2{\tabfig@l@subsection{#1}{\tabfig@ttbf{#2}}}
    \let\tabfig@l@subsubsection\l@subsubsection
    \def\l@subsubsection#1#2{\tabfig@l@subsubsection{#1}{\tabfig@ttbf{#2}}}
    \let\tabfig@l@paragraph\l@paragraph
    \def\l@paragraph#1#2{\tabfig@l@paragraph{#1}{\tabfig@ttbf{#2}}}
    \let\tabfig@l@subparagraph\l@subparagraph
    \def\l@subparagraph#1#2{\tabfig@l@subparagraph{#1}{\tabfig@ttbf{#2}}}
    \let\tabfig@l@figure\l@figure
    \def\l@figure#1#2{\tabfig@l@figure{#1}{\tabfig@ttbf{#2}}}
    \let\tabfig@l@table\l@table
    \def\l@table#1#2{\tabfig@l@table{#1}{\tabfig@ttbf{#2}}}
%    \end{macrocode}
% Special support for parts and chapters in \pkg{memoir}.
%    \begin{macrocode}
    \@ifclassloaded{memoir}{%
      \apptocmd{\cftpartpresnum}%
        {\tabfig@tbf}{}{\tabfig@warning{\cftpartpresnum}}%
      \apptocmd{\cftchapterpresnum}%
        {\tabfig@tbf}{}{\tabfig@warning{\cftchapterpresnum}}%
    }{}%
  }%
}
%    \end{macrocode}
% 
% \subsection{Enumerations}
% Labels in enumerations.
%    \begin{macrocode}
\DeclareOption{enum}{%
  \AtBeginDocument{%
    \patchcmd{\labelenumi}%
      {\theenumi}{\tabfig@ttbf{\theenumi}}%
      {}{\tabfig@warning{\labelenumi}}%
    \patchcmd{\labelenumii}%
      {\theenumii}{\tabfig@ttbf{\theenumii}}%
      {}{\tabfig@warning{\labelenumii}}%
    \patchcmd{\labelenumiii}%
      {\theenumiii}{\tabfig@ttbf{\theenumiii}}%
      {}{\tabfig@warning{\labelenumiii}}%
    \patchcmd{\labelenumiv}%
      {\theenumiv}{\tabfig@ttbf{\theenumiv}}%
      {}{\tabfig@warning{\labelenumiv}}%
  }%
}
%    \end{macrocode}
% 
% \subsection{Bibliography}
% Labels in the bibliography.
%    \begin{macrocode}
\DeclareOption{bib}{%
  \AtBeginDocument{%
    \let\tabfig@@biblabel\@biblabel
    \def\@biblabel#1{\tabfig@@biblabel{\tabfig@ttbf{#1}}}%
    \@ifpackageloaded{biblatex}{%
      \DeclareFieldFormat{labelnumberwidth}{\mkbibbrackets{\tabfig@ttbf{#1}}}%
      \DeclareFieldFormat{labelalphawidth}{\mkbibbrackets{\tabfig@ttbf{#1}}}%
    }{}%
  }%
}
%    \end{macrocode}
%
% \subsection{Line numbers}
%    \begin{macrocode}
\DeclareOption{lineno}{%
  \AtBeginDocument{%
%    \end{macrocode}
% Support for the \pkg{doc} and \pkg{hypdoc} packages.
%    \begin{macrocode}
    \@ifpackageloaded{hypdoc}{%
      \ifpatchable{\theCodelineNo}{\HDorg@theCodelineNo}{%
        \patchcmd{\HDorg@theCodelineNo}%
          {\arabic{CodelineNo}}%
          {\tabfig@ttbf{\arabic{CodelineNo}}}%
          {}{\tabfig@warning{\HDorg@theCodelineNo}}%
      }{%
        \patchcmd{\theCodelineNo}%
          {\arabic{CodelineNo}}%
          {\tabfig@ttbf{\arabic{CodelineNo}}}%
          {}{\tabfig@warning{\theCodelineNo}}%
      }%
    }{%
      \@ifpackageloaded{doc}{%
        \patchcmd{\theCodelineNo}%
          {\arabic{CodelineNo}}%
          {\tabfig@ttbf{\arabic{CodelineNo}}}%
          {}{\tabfig@warning{\theCodelineNo}}%
      }{}%
    }%
%    \end{macrocode}
% Support for the \pkg{listings} package.
%    \begin{macrocode}
    \@ifpackageloaded{listings}{%
      \apptocmd{\lst@numberstyle}{\tabfig@tbf}%
        {}{\tabfig@warning{\lst@numberstyle}}%
    }{}%
%    \end{macrocode}
% Support for the \pkg{fancyvrb} package.
%    \begin{macrocode}
    \@ifpackageloaded{fancyvrb}{%
      \patchcmd{\theFancyVerbLine}%
        {\arabic{FancyVerbLine}}%
        {\tabfig@ttbf{\arabic{FancyVerbLine}}}%
        {}{\tabfig@warning{\theFancyVerbLine}}%
    }{}
  }%
}
\ProcessOptions\relax
%    \end{macrocode}
%
% \subsection{Auxiliary macros}
% These commands are used for switching to tabular figures. This can be
% redefined to allow debugging, disabling, etc.
%    \begin{macrocode}
\newcommand*\tabfig@tbf{\tbfigures}
\DeclareTextFontCommand{\tabfig@ttbf}{\tabfig@tbf}
%    \end{macrocode}
% Visual debugging: Set tabular figures (produced by this package) in
% green.
%    \begin{macrocode}
\iftabfig@debug
  \RequirePackage{xcolor}%
  \colorlet{tabfig@debug}{green!50!black}%
  \renewcommand\tabfig@tbf{\tbfigures\color{tabfig@debug}}%
\fi
%    \end{macrocode}
% Check if figure versions are supported at all. If not, we cannot do
% anything useful.
%    \begin{macrocode}
\AtBeginDocument{%
  \@ifundefined{tbfigures}{%
    \@ifpackageloaded{fontspec}{%
      \def\tbfigures{\addfontfeatures{Numbers=Monospaced}}%
    }{%
      \PackageWarningNoLine{tabfigures}{There is no command
        \string\tbfigures\space to support tabular figures}%
      \let\tabfig@tbf\@empty
    }%
  }{}%
}
%</package>
%    \end{macrocode}
%
% \Finale
\endinput