1
% System stylesheet for the new LaTeX writer, newlatex2e.
3
% Major parts of the rendering are done in this stylesheet and not in the
6
% For development notes, see notes.txt.
8
% User documentation (in the stylesheet for now; that may change though):
11
% All uppercase letters in macro names have a specific meaning.
12
% \D...: All macros introduced by the Docutils LaTeX writer start with "D".
13
% \DS<name>: Setup function (called at the bottom of this stylesheet).
14
% \DN<nodename>{<contents>}: Handler for Docutils document tree node `node`; called by
16
% \DEV<name>: External variable, set by the Python module.
17
% \DEC<name>: External command. It is called by the Python module and must be
18
% defined in this stylesheet.
19
% \DN<nodename>A<attribute>{<number>}{<attribute>}{<value>}{<nodename>}{<contents>}:
20
% Attribute handler for `attribute` set on nodes of type `nodename`.
21
% See below for a discussion of attribute handlers.
22
% \DA<attribute>{<number>}{<attribute>}{<value>}{<nodename>}{<contents>}:
23
% Attribute handler for all `attribute`. Called only when no specific
24
% \DN<nodename>A<attribute> handler is defined.
25
% \DN<nodename>C<class>{<contents>}:
26
% Handler for `class`, when set on nodes of type `nodename`.
27
% \DC<class>{<contents>}:
28
% Handler for `class`. Called only when no specific \DN<nodename>C<class>
30
% \D<name>: Generic variable or function.
35
% ---------------------------------------------------------------------------
37
% Having to intersperse code with \makeatletter-\makeatother pairs is very
38
% annoying, so we call \makeatletter at the top and \makeatother at the
39
% bottom. Just be aware that you cannot use "@" as a text character inside
4
% http://docutils.python-hosting.com/wiki/NewLatex
43
% Print-mode (as opposed to online mode e.g. with Adobe Reader).
44
% This causes for example blue hyperlinks.
7
45
\providecommand{\Dprinting}{false}
47
% \DSearly is called right after \documentclass.
10
48
\providecommand{\DSearly}{}
49
% \DSlate is called at the end of the stylesheet (right before the document
11
51
\providecommand{\DSlate}{}
53
% Use the KOMA script article class.
13
54
\providecommand{\Ddocumentclass}{scrartcl}
14
55
\providecommand{\Ddocumentoptions}{a4paper}
16
\documentclass[\Ddocumentoptions]{\Ddocumentclass}
56
\providecommand{\DSdocumentclass}{
57
\documentclass[\Ddocumentoptions]{\Ddocumentclass} }
59
% Todo: This should be movable to the bottom, but it isn't as long as
60
% we use \usepackage commands at the top level of this stylesheet
61
% (which we shouldn't).
64
\providecommand{\DSpackages}{
65
% Load miscellaneous packages.
66
% Note 1: Many of the packages loaded here are used throughout this stylesheet.
67
% If one of these packages does not work on your system or in your scenario,
68
% please let us know, so we can consider making the package optional.
69
% Note 2: It would appear cleaner to load packages where they are used.
70
% However, since using a wrong package loading order can lead to *very*
71
% subtle bugs, we centralize the loading of most packages here.
72
\DSfontencoding % load font encoding packages
73
\DSlanguage % load babel
74
% Using \ifthenelse conditionals.
75
\usepackage{ifthen} % before hyperref (really!)
76
% There is not support for *not* using hyperref because it's used in many
77
% places. If this is a problem (e.g. because hyperref doesn't work on your
78
% system), please let us know.
79
\usepackage[colorlinks=false,pdfborder={0 0 0}]{hyperref}
80
% Get color, e.g. for links and system messages.
82
% Get \textnhtt macro (non-hyphenating type writer).
86
% We use longtable to create tables.
87
\usepackage{longtable}
90
% These packages might be useful (some just add magic pixie dust), so
94
% Add some missing symbols like \textonehalf.
21
98
\providecommand{\DSfontencoding}{
22
% Set up font encoding.
23
% AE is a T1-emulation. It provides most characters and features
24
% as T1-encoded fonts but doesn't use ugly bitmap fonts.
99
% Set up font encoding. Called by \DSpackages.
100
% AE is a T1 emulation. It provides mostly the same characters and
101
% features as T1-encoded fonts but doesn't use bitmap fonts (which are
102
% unsuitable for online reading and subtle for printers).
26
104
% Provide the characters not contained in AE from EC bitmap fonts.
27
105
\usepackage{aecompl}
55
\providecommand{\Dprovidecounter}[1]{%
131
\providecommand{\Dprovidecounter}[2]{%
56
132
% Like \newcounter except that it doesn't crash if the counter
58
\@ifundefined{c@#1}{\newcounter{#1}}{}
134
\@ifundefined{c@#1}{\newcounter{#1}\setcounter{#1}{#2}}{}
61
137
\Dprovidelength{\Dboxparindent}{\parindent}
62
\providecommand{\Dmakeboxminipage}[1]{%
63
% Make minipage for use in a box created by \Dmakefbox.
64
\begin{minipage}[t]{0.9\linewidth}%
65
\setlength{\parindent}{\Dboxparindent}%
69
\providecommand{\Dmakefbox}[1]{%
70
% Make a centered, framed box. Useful e.g. for admonitions.
71
\vspace{0.4\baselineskip}%
73
\fbox{\Dmakeboxminipage{#1}}%
75
\vspace{0.4\baselineskip}%
77
139
\providecommand{\Dmakebox}[1]{%
78
140
% Make a centered, frameless box. Useful e.g. for block quotes.
79
141
% Do not use minipages here, but create pseudo-lists to allow
151
\providecommand{\Dmakefbox}[1]{%
152
% Make a centered, framed box. Useful e.g. for admonitions.
153
\vspace{0.4\baselineskip}%
156
\begin{minipage}[t]{0.9\linewidth}%
157
\setlength{\parindent}{\Dboxparindent}%
162
\vspace{0.4\baselineskip}%
90
\RequirePackage{ifthen}
91
\providecommand{\Dfrenchspacing}{true}
92
\ifthenelse{\equal{\Dfrenchspacing}{true}}{\frenchspacing}{}
165
% We do not currently recognize the difference between an end-sentence and a
166
% mid-sentence period (". " vs. ". " in plain text). So \frenchspacing is
168
\providecommand{\DSfrenchspacing}{\frenchspacing}
95
171
\Dprovidelength{\Dblocklevelvspace}{%
96
172
% Space between block-level elements other than paragraphs.
97
173
0.7\baselineskip plus 0.3\baselineskip minus 0.2\baselineskip%
99
\providecommand{\Dauxiliaryspace}{%
175
\providecommand{\DECauxiliaryspace}{%
100
176
\ifthenelse{\equal{\Dneedvspace}{true}}{\vspace{\Dblocklevelvspace}}{}%
103
\providecommand{\Dparagraphspace}{\par}
179
\providecommand{\DECparagraphspace}{\par}
104
180
\providecommand{\Dneedvspace}{true}
107
\providecommand{\DSlinks}{
108
% Targets and references.
109
\RequirePackage[colorlinks=false,pdfborder={0 0 0}]{hyperref}
111
\providecommand{\Draisedlink}[1]{\Hy@raisedlink{##1}}
114
% We're assuming here that the "refid" and "refuri" attributes occur
115
% only in inline context (in TextElements).
116
\providecommand{\DArefid}[5]{%
117
\ifthenelse{\equal{##4}{reference}}{%
118
\Dexplicitreference{\###3}{##5}%
120
% If this is not a target node (targets with refids are
121
% uninteresting and should be silently dropped).
122
\ifthenelse{\not\equal{##4}{target}}{%
123
% If this is a footnote reference, call special macro.
124
\ifthenelse{\equal{##4}{footnotereference}}{%
125
\Dimplicitfootnotereference{\###3}{##5}%
127
\ifthenelse{\equal{##4}{citationreference}}{%
128
\Dimplicitcitationreference{\###3}{##5}%
130
\Dimplicitreference{\###3}{##5}%
136
\providecommand{\DArefuri}[5]{%
137
\ifthenelse{\equal{##4}{target}}{%
138
% Hyperlink targets can (and should be) ignored because they are
141
% We only have explicit URI references, so one macro suffices.
142
\Durireference{##3}{##5}%
146
\providecommand{\DAids}[5]{%
148
\ifthenelse{\equal{##4}{footnotereference}}{%
150
\renewcommand{\HyperRaiseLinkDefault}{%
151
% Dirty hack to make backrefs to footnote references work.
152
% For some reason, \baselineskip is 0pt in fn references.
153
0.5\Doriginalbaselineskip%
155
\Draisedlink{\hypertarget{##3}{}}##5%
158
\Draisedlink{\hypertarget{##3}{}}##5%
161
% Color in references.
162
\RequirePackage{color}
163
\providecommand{\Dimplicitreference}[2]{%
164
% Create implicit reference to ID. Implicit references occur
165
% e.g. in TOC-backlinks of section titles. Parameters:
170
\providecommand{\Dimplicitfootnotereference}[2]{%
171
% Ditto, but for the special case of footnotes.
172
% We want them to be rendered like explicit references.
173
\Dexplicitreference{##1}{##2}%
175
\providecommand{\Dimplicitcitationreference}[2]{%
176
% Ditto for citation references.
177
\Dimplicitfootnotereference{##1}{##2}%
179
\ifthenelse{\equal{\Dprinting}{true}}{
180
\providecommand{\Dexplicitreferencecolor}{black}
182
\providecommand{\Dexplicitreferencecolor}{blue}
184
\providecommand{\Dexplicitreference}[2]{%
185
% Create explicit reference to ID, e.g. created with "foo_".
189
\href{##1}{{\color{\Dexplicitreferencecolor}##2}}%
191
\providecommand{\Durireferencecolor}{\Dexplicitreferencecolor}
192
\providecommand{\Durireference}[2]{%
193
% Create reference to URI. Parameters:
196
\href{##1}{{\color{\Durireferencecolor}##2}}%
201
182
\providecommand{\DSlanguage}{%
203
\ifthenelse{\equal{\Dlanguagebabel}{}}{}{
204
\RequirePackage[\Dlanguagebabel]{babel}
184
\usepackage[\DEVlanguagebabel]{babel}
187
\providecommand{\Difdefined}[3]{\@ifundefined{#1}{#3}{#2}}
189
% Handler for 'classes' attribute (called for each class attribute).
211
190
\providecommand{\DAclasses}[5]{%
191
% Dispatch to \DN<nodename>C<class>.
212
192
\Difdefined{DN#4C#3}{%
213
193
% Pass only contents, nothing else!
214
194
\csname DN#4C#3\endcsname{#5}%
196
% Otherwise, dispatch to \DC<class>.
216
197
\Difdefined{DC#3}{%
217
198
\csname DC#3\endcsname{#5}%
224
\providecommand{\Difdefined}[3]{\@ifundefined{#1}{#3}{#2}}
226
\providecommand{\Dattr}[5]{%
227
% Global attribute dispatcher.
205
\providecommand{\DECattr}[5]{%
206
% Global attribute dispatcher, called inside the document tree.
229
208
% 1. Attribute number.
230
209
% 2. Attribute name.
231
210
% 3. Attribute value.
233
212
% 5. Node contents.
234
\Difdefined{DN#4A#2V#3}{%
235
\csname DN#4A#2V#3\endcsname{#1}{#2}{#3}{#4}{#5}%
236
}{\Difdefined{DN#4A#2}{%
213
\Difdefined{DN#4A#2}{%
214
% Dispatch to \DN<nodename>A<attribute>.
237
215
\csname DN#4A#2\endcsname{#1}{#2}{#3}{#4}{#5}%
238
}{\Difdefined{DA#2V#3}{%
239
\csname DA#2V#3\endcsname{#1}{#2}{#3}{#4}{#5}%
240
216
}{\Difdefined{DA#2}{%
217
% Otherwise dispatch to \DA<attribute>.
241
218
\csname DA#2\endcsname{#1}{#2}{#3}{#4}{#5}%
220
% Otherwise simply run the contents without calling a handler.
225
% ---------- Link handling ----------
226
% Targets and references.
228
\providecommand{\Draisedlink}[1]{%
229
% Anchors are placed on the base line by default. This is a bad thing for
230
% inline context, so we raise the anchor (normally by \baselineskip).
235
% We're assuming here that the "refid" and "refuri" attributes occur
236
% only in inline context (in TextElements).
237
\providecommand{\DArefid}[5]{%
238
\ifthenelse{\equal{#4}{reference}}{%
239
\Dexplicitreference{\##3}{#5}%
241
% If this is not a target node (targets with refids are
242
% uninteresting and should be silently dropped).
243
\ifthenelse{\not\equal{#4}{target}}{%
244
% If this is a footnote reference, call special macro.
245
\ifthenelse{\equal{#4}{footnotereference}}{%
246
\Dimplicitfootnotereference{\##3}{#5}%
248
\ifthenelse{\equal{#4}{citationreference}}{%
249
\Dimplicitcitationreference{\##3}{#5}%
251
\Dimplicitreference{\##3}{#5}%
257
\providecommand{\DArefuri}[5]{%
258
\ifthenelse{\equal{#4}{target}}{%
259
% The node name is 'target', so this is a hyperlink target, like this:
261
% Hyperlink targets are ignored because they are invisible.
263
% If a non-target node has a refuri attribute, it must be an explicit URI
264
% reference (i.e. node name is 'reference').
265
\Durireference{#3}{#5}%
269
\providecommand{\DAids}[5]{%
271
\ifthenelse{\equal{#4}{footnotereference}}{%
273
\renewcommand{\HyperRaiseLinkDefault}{%
274
% Dirty hack to make backrefs to footnote references work.
275
% For some reason, \baselineskip is 0pt in fn references.
276
0.5\Doriginalbaselineskip%
278
\Draisedlink{\hypertarget{#3}{}}#5%
281
\Draisedlink{\hypertarget{#3}{}}#5%
284
\providecommand{\Dimplicitreference}[2]{%
285
% Create implicit reference to ID. Implicit references occur
286
% e.g. in TOC-backlinks of section titles. Parameters:
291
\providecommand{\Dimplicitfootnotereference}[2]{%
292
% Ditto, but for the special case of footnotes.
293
% We want them to be rendered like explicit references.
294
\Dexplicitreference{#1}{#2}%
296
\providecommand{\Dimplicitcitationreference}[2]{%
297
% Ditto for citation references.
298
\Dimplicitfootnotereference{#1}{#2}%
300
\providecommand{\Dcolorexplicitreference}{%
301
\ifthenelse{\equal{\Dprinting}{true}}{\color{black}}{\color{blue}}%
303
\providecommand{\Dexplicitreference}[2]{%
304
% Create explicit reference to ID, e.g. created with "foo_".
308
\href{#1}{{\Dcolorexplicitreference#2}}%
310
\providecommand{\Dcolorurireference}{\Dcolorexplicitreference}
311
\providecommand{\Durireference}[2]{%
312
% Create reference to URI. Parameters:
315
\href{#1}{{\Dcolorurireference#2}}%
318
\Dprovidecounter{Dpdfbookmarkid}{0}%
319
\providecommand{\Dpdfbookmark}[1]{%
320
% Temporarily decrement Desctionlevel counter.
321
\addtocounter{Dsectionlevel}{-1}%
322
%\typeout{\arabic{Dsectionlevel}}%
324
%\typeout{docutils\roman{Dpdfbookmarkid}}%
326
\pdfbookmark[\arabic{Dsectionlevel}]{#1}{docutils\arabic{Dpdfbookmarkid}}%
327
\addtocounter{Dsectionlevel}{1}%
328
\addtocounter{Dpdfbookmarkid}{1}%
330
% ---------- End of Link Handling ----------
246
332
\providecommand{\DNparagraph}[1]{%
247
\ifthenelse{\equal{\Dparagraphindented}{true}}{\indent}{\noindent}%
333
\ifthenelse{\equal{\DEVparagraphindented}{true}}{\indent}{\noindent}%
250
336
\providecommand{\Dformatboxtitle}[1]{{\Large\textbf{#1}}}
321
\providecommand{\Dhassubtitle}{false}
322
409
\providecommand{\DNtitle}[1]{%
323
\csname D\Dparent title\endcsname{#1}%
410
% Dispatch to \D<parent>title.
411
\csname D\DEVparent title\endcsname{#1}%
325
413
\providecommand{\DNsubtitle}[1]{%
326
\csname D\Dparent subtitle\endcsname{#1}%
328
\newcounter{Dpdfbookmarkid}
329
\setcounter{Dpdfbookmarkid}{0}
330
\providecommand{\Dpdfbookmark}[1]{%
331
% Temporarily decrement Desctionlevel counter.
332
\addtocounter{Dsectionlevel}{-1}%
333
%\typeout{\arabic{Dsectionlevel}}%
335
%\typeout{docutils\roman{Dpdfbookmarkid}}%
337
\pdfbookmark[\arabic{Dsectionlevel}]{#1}{docutils\arabic{Dpdfbookmarkid}}%
338
\addtocounter{Dsectionlevel}{1}%
339
\addtocounter{Dpdfbookmarkid}{1}%
414
% Dispatch to \D<parent>subtitle.
415
\csname D\DEVparent subtitle\endcsname{#1}%
342
%\providecommand{\DNliteralblock}[1]{\begin{quote}\ttfamily\raggedright#1\end{quote}}
343
418
\providecommand{\DNliteralblock}[1]{%
344
419
\Dmakelistenvironment{}{%
345
420
\ifthenelse{\equal{\Dinsidetabular}{true}}{%
350
425
\raggedright\item\noindent\nohyphens{\textnhtt{#1\Dfinalstrut}}%
353
\providecommand{\DNdoctestblock}[1]{%
354
% Treat doctest blocks the same as literal blocks.
357
\RequirePackage{hyphenat}
428
\providecommand{\DNdoctestblock}[1]{\DNliteralblock{#1}}
358
429
\providecommand{\DNliteral}[1]{\textnhtt{#1}}
359
430
\providecommand{\DNemphasis}[1]{\emph{#1}}
360
431
\providecommand{\DNstrong}[1]{\textbf{#1}}
361
\providecommand{\Dvisitdocument}{\begin{document}\noindent}
362
\providecommand{\Ddepartdocument}{\end{document}}
432
\providecommand{\DECvisitdocument}{\begin{document}\noindent}
433
\providecommand{\DECdepartdocument}{\end{document}}
363
434
\providecommand{\DNtopic}[1]{%
364
\ifthenelse{\equal{\DcurrentNtopicAcontents}{1}}{%
435
\ifthenelse{\equal{\DEVcurrentNtopicAcontents}{1}}{%
365
436
\addtocounter{Dtoclevel}{1}%
800
874
\providecommand{\Dthislabel}{}
801
875
\providecommand{\DNlabel}[1]{%
802
\renewcommand{\Dthislabel}{#1}
803
\ifthenelse{\not\equal{\Dsinglebackref}{}}{%
876
% Footnote or citatation label.
877
\renewcommand{\Dthislabel}{#1}%
878
\ifthenelse{\not\equal{\DEVsinglebackref}{}}{%
804
879
\let\Doriginallabel=\Dthislabel%
805
880
\def\Dthislabel{%
806
\Dsinglefootnotebacklink{\Dsinglebackref}{\Doriginallabel}%
881
\Dsinglefootnotebacklink{\DEVsinglebackref}{\Doriginallabel}%
809
\ifthenelse{\equal{\Dparent}{footnote}}{%
884
\ifthenelse{\equal{\DEVparent}{footnote}}{%
810
885
% Footnote label.
811
886
\Dformatfootnotelabel{\Dthislabel}%
813
\ifthenelse{\equal{\Dparent}{citation}}{%
888
\ifthenelse{\equal{\DEVparent}{citation}}{%
814
889
% Citation label.
815
890
\Dformatcitationlabel{\Dthislabel}%
818
893
% If there are multiple backrefs, add them now.
819
\Dformatmultiplebackrefs{\Dmultiplebackrefs}%
894
\Dformatmultiplebackrefs{\DEVmultiplebackrefs}%
821
896
\providecommand{\Dsinglefootnotebacklink}[2]{%
822
897
% Create normal backlink of a footnote label. Parameters:
1021
1094
\providecommand{\DNfigureAalign}[5]{%
1022
1095
% Hack to make it work Right Now.
1023
%\def\DcurrentNimageAwidth{\DcurrentNfigureAwidth}%
1096
%\def\DEVcurrentNimageAwidth{\DEVcurrentNfigureAwidth}%
1025
%\def\DcurrentNimageAwidth{\linewidth}%
1098
%\def\DEVcurrentNimageAwidth{\linewidth}%
1026
1099
\DNimageAalign{#1}{#2}{#3}{#4}{%
1027
1100
\begin{minipage}[b]{0.4\linewidth}#5\end{minipage}}%
1028
%\let\DcurrentNimageAwidth=\relax%
1101
%\let\DEVcurrentNimageAwidth=\relax%
1030
%\let\DcurrentNimageAwidth=\relax%
1103
%\let\DEVcurrentNimageAwidth=\relax%
1032
1105
\providecommand{\DNcaption}[1]{\par\noindent{\slshape#1}}
1033
\providecommand{\DNlegend}[1]{\Dauxiliaryspace#1}
1106
\providecommand{\DNlegend}[1]{\DECauxiliaryspace#1}
1035
1108
\providecommand{\DCborder}[1]{\fbox{#1}}
1036
1109
% No padding between image and border.
1040
1113
% Need to replace with language-specific stuff. Maybe look at
1041
1114
% csquotes.sty and ask the author for permission to use parts of it.
1042
\providecommand{\Dtextleftdblquote}{``}
1043
\providecommand{\Dtextrightdblquote}{''}
1115
\providecommand{\DECtextleftdblquote}{``}
1116
\providecommand{\DECtextrightdblquote}{''}
1045
1118
% Table of contents:
1046
1119
\Dprovidelength{\Dtocininitialsectnumwidth}{2.4em}
1047
1120
\Dprovidelength{\Dtocadditionalsectnumwidth}{0.7em}
1048
1121
% Level inside a table of contents. While this is at -1, we are not
1049
1122
% inside a TOC.
1050
\Dprovidecounter{Dtoclevel}%
1051
\setcounter{Dtoclevel}{-1}
1123
\Dprovidecounter{Dtoclevel}{-1}%
1052
1124
\providecommand{\Dlocaltoc}{false}%
1053
1125
\providecommand{\DNtopicClocal}[1]{%
1054
1126
\renewcommand{\Dlocaltoc}{true}%
1091
% For \Dpixelunit, the length value is pre-multiplied with 0.75, so by
1163
% For \DECpixelunit, the length value is pre-multiplied with 0.75, so by
1092
1164
% specifying "pt" we get the same notion of "pixel" as graphicx.
1093
\providecommand{\Dpixelunit}{pt}
1165
\providecommand{\DECpixelunit}{pt}
1094
1166
% Normally lengths are relative to the current linewidth.
1095
\providecommand{\Drelativeunit}{\linewidth}
1098
%\RequirePackage{fixmath}
1099
%\RequirePackage{amsmath}
1167
\providecommand{\DECrelativeunit}{\linewidth}
1170
% ACTION: These commands actually *do* something.
1171
% Ultimately, everything should be done here, and no active content should be
1172
% above (not even \usepackage).