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
|
\documentclass[a4paper]{article}
% generated by Docutils <http://docutils.sourceforge.net/>
\usepackage{fixltx2e} % LaTeX patches, \textsubscript
\usepackage{cmap} % fix search and cut-and-paste in Acrobat
\usepackage{ifthen}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
% code highlight rules:
\providecommand*\DUrolecomment[1]{\textcolor[rgb]{0.40,0.40,0.40}{#1}}
\providecommand*\DUroledeleted[1]{\textcolor[rgb]{0.40,0.40,0.40}{#1}}
\providecommand*\DUrolekeyword[1]{\textbf{#1}}
% \providecommand*\DUrolename[1]{\textcolor[rgb]{0.00,0.25,0.82}{#1}}
\providecommand*\DUrolebuiltin[1]{\textbf{#1}}
\providecommand*\DUrolestring[1]{\textit{#1}}
\usepackage{color}
\setcounter{secnumdepth}{0}
%%% Custom LaTeX preamble
% suppress the (LaTeX-added) References section heading
\AtBeginDocument{\renewcommand{\refname}{\vspace{-1em}}}
\newlength{\DUlineblockindent}
\setlength{\DUlineblockindent}{1em}
%%% User specified packages and stylesheets
\usepackage{palatino-optima-txtt}
\usepackage{microtype}
%%% Fallback definitions for Docutils-specific commands
% inline markup (custom roles)
% \DUrole{#1}{#2} tries \DUrole#1{#2}
\providecommand*{\DUrole}[2]{%
\ifcsname DUrole#1\endcsname%
\csname DUrole#1\endcsname{#2}%
\else% backwards compatibility: try \docutilsrole#1{#2}
\ifcsname docutilsrole#1\endcsname%
\csname docutilsrole#1\endcsname{#2}%
\else%
#2%
\fi%
\fi%
}
% hyperlinks:
\ifthenelse{\isundefined{\hypersetup}}{
\usepackage[colorlinks=true,linkcolor=blue,urlcolor=blue,citecolor=black]{hyperref}
\urlstyle{same} % normal text font (alternatives: tt, rm, sf)
}{}
%%% Body
\begin{document}
This is a test of the new ``code'' directive:
The example from Docutils TODO list:
%
\begin{quote}{\ttfamily \raggedright \noindent
\DUrole{keyword}{print}~\DUrole{literal}{\DUrole{string}{'This~is~Python~code.'}}~\\
\DUrole{keyword}{for}~\DUrole{name}{i}~\DUrole{operator}{\DUrole{word}{in}}~\DUrole{name}{\DUrole{builtin}{range}}\DUrole{punctuation}{(}\DUrole{literal}{\DUrole{number}{\DUrole{integer}{10}}}\DUrole{punctuation}{):}~\\
~~~~\DUrole{keyword}{print}~\DUrole{name}{i}
}
\end{quote}
Numbered lines:
%
\begin{quote}{\ttfamily \raggedright \noindent
\DUrole{ln}{1~}\DUrole{comment}{\#~This~is~Python~code,}~\\
\DUrole{ln}{2~}\DUrole{comment}{\#~that~prints~the~integers~from~0~to~9}~\\
\DUrole{ln}{3~}\DUrole{keyword}{for}~\DUrole{name}{i}~\DUrole{operator}{\DUrole{word}{in}}~\DUrole{name}{\DUrole{builtin}{range}}\DUrole{punctuation}{(}\DUrole{literal}{\DUrole{number}{\DUrole{integer}{10}}}\DUrole{punctuation}{):}~\\
\DUrole{ln}{4~}~~~~\DUrole{keyword}{print}~\DUrole{name}{i}
}
\end{quote}
Another example:
%
\begin{quote}{\ttfamily \raggedright \noindent
\DUrole{ln}{~7~}\DUrole{keyword}{def}~\DUrole{name}{\DUrole{function}{my\_function}}\DUrole{punctuation}{():}~\\
\DUrole{ln}{~8~}~~~~\DUrole{literal}{\DUrole{string}{\DUrole{doc}{"{}"{}"Test~the~lexer.\\
}}}\DUrole{ln}{~9~}\DUrole{literal}{\DUrole{string}{\DUrole{doc}{~~~~"{}"{}"}}}~\\
\DUrole{ln}{10~}~\\
\DUrole{ln}{11~}~~~~\DUrole{comment}{\#~and~now~for~something~completely~different}~\\
\DUrole{ln}{12~}~~~~\DUrole{keyword}{print}~\DUrole{literal}{\DUrole{number}{\DUrole{integer}{8}}}\DUrole{operator}{/}\DUrole{literal}{\DUrole{number}{\DUrole{integer}{2}}}
}
\end{quote}
And now some CSS:
%
\begin{quote}{\ttfamily \raggedright \noindent
\DUrole{name}{\DUrole{tag}{p}}\DUrole{name}{\DUrole{class}{.topic-title}}~\DUrole{punctuation}{\{}~\\
~~\DUrole{keyword}{font-weight}\DUrole{operator}{:}~\DUrole{keyword}{bold}~\DUrole{punctuation}{\}}~\\
~\\
\DUrole{name}{\DUrole{tag}{pre}}\DUrole{name}{\DUrole{class}{.address}}~\DUrole{punctuation}{\{}~\\
~~\DUrole{keyword}{margin-bottom}\DUrole{operator}{:}~\DUrole{literal}{\DUrole{number}{0}}~\DUrole{punctuation}{;}~\\
~~\DUrole{keyword}{margin-top}\DUrole{operator}{:}~\DUrole{literal}{\DUrole{number}{0}}~\DUrole{punctuation}{;}~\\
~~\DUrole{keyword}{font}\DUrole{operator}{:}~\DUrole{keyword}{inherit}~\DUrole{punctuation}{\}}
}
\end{quote}
as well as TeX:
%
\begin{quote}{\ttfamily \raggedright \noindent
\DUrole{comment}{\%~hyperlinks:\\
}\DUrole{keyword}{\textbackslash{}ifthenelse}\DUrole{name}{\DUrole{builtin}{\{}}\DUrole{keyword}{\textbackslash{}isundefined}\DUrole{name}{\DUrole{builtin}{\{}}\DUrole{keyword}{\textbackslash{}hypersetup}\DUrole{name}{\DUrole{builtin}{\}\}\{}}~\\
~~\DUrole{keyword}{\textbackslash{}usepackage}\DUrole{name}{\DUrole{attribute}{{[}linkcolor=blue,urlcolor=blue{]}}}\DUrole{name}{\DUrole{builtin}{\{}}hyperref\DUrole{name}{\DUrole{builtin}{\}}}~\\
~~\DUrole{keyword}{\textbackslash{}urlstyle}\DUrole{name}{\DUrole{builtin}{\{}}same\DUrole{name}{\DUrole{builtin}{\}}}~\DUrole{comment}{\%~normal~text~font~(alternatives:~tt,~rm,~sf)\\
}\DUrole{name}{\DUrole{builtin}{\}\{\}}}~\\
~\\
\DUrole{keyword}{\textbackslash{}begin}\DUrole{name}{\DUrole{builtin}{\{}}document\DUrole{name}{\DUrole{builtin}{\}}}~\\
~\\
The~area~of~a~circle~is~\DUrole{literal}{\DUrole{string}{\$}}\DUrole{name}{\DUrole{builtin}{A~}}\DUrole{operator}{=}\DUrole{name}{\DUrole{builtin}{~}}\DUrole{name}{\DUrole{variable}{\textbackslash{}pi}}\DUrole{operator}{/}\DUrole{literal}{\DUrole{number}{4}}\DUrole{name}{\DUrole{builtin}{~d\textasciicircum{}}}\DUrole{literal}{\DUrole{number}{2}}\DUrole{literal}{\DUrole{string}{\$}}~\\
~\\
\DUrole{keyword}{\textbackslash{}end}\DUrole{name}{\DUrole{builtin}{\{}}document\DUrole{name}{\DUrole{builtin}{\}}}
}
\end{quote}
and Lua:
%
\begin{quote}{\ttfamily \raggedright \noindent
\DUrole{keyword}{if}~\DUrole{operator}{\DUrole{word}{not}}~\DUrole{name}{modules}~\DUrole{keyword}{then}~\DUrole{name}{modules}~\DUrole{operator}{=}~\DUrole{punctuation}{\{}~\DUrole{punctuation}{\}}~\DUrole{keyword}{end}~\DUrole{name}{modules}~\DUrole{punctuation}{{[}}\DUrole{literal}{\DUrole{string}{\DUrole{single}{'}}}\DUrole{literal}{\DUrole{string}{char-def'}}\DUrole{punctuation}{{]}}~\DUrole{operator}{=}~\DUrole{punctuation}{\{}~\\
~~~~\DUrole{name}{version}~~~\DUrole{operator}{=}~\DUrole{literal}{\DUrole{number}{\DUrole{float}{1.001}}}\DUrole{punctuation}{,}~\\
~~~~\DUrole{name}{comment}~~~\DUrole{operator}{=}~\DUrole{literal}{\DUrole{string}{\DUrole{double}{"}}}\DUrole{literal}{\DUrole{string}{companion~to~char-ini.mkiv"}}\DUrole{punctuation}{,}~\\
~~~~\DUrole{name}{author}~~~~\DUrole{operator}{=}~\DUrole{literal}{\DUrole{string}{\DUrole{double}{"}}}\DUrole{literal}{\DUrole{string}{Hans~Hagen,~PRAGMA-ADE,~Hasselt~NL"}}\DUrole{punctuation}{,}~\\
~~~~\DUrole{name}{copyright}~\DUrole{operator}{=}~\DUrole{literal}{\DUrole{string}{\DUrole{double}{"}}}\DUrole{literal}{\DUrole{string}{PRAGMA~ADE~/~ConTeXt~Development~Team"}}\DUrole{punctuation}{,}~\\
~~~~\DUrole{name}{license}~~~\DUrole{operator}{=}~\DUrole{literal}{\DUrole{string}{\DUrole{double}{"}}}\DUrole{literal}{\DUrole{string}{see~context~related~readme~files"}}~\\
\DUrole{punctuation}{\}}~\\
~\\
\DUrole{comment}{\DUrole{multiline}{-{}-{[}{[}\\
The~first~version~of~this~table~was~generated~from~unicode~tables\\
but~after~that~was~mostly~updated~manual~using~data~present~in\\
ConTeXt~and~elsewhere.\\
{]}{]}}}\DUrole{comment}{\DUrole{single}{-{}-}}~\\
~\\
\DUrole{name}{characters}~\DUrole{operator}{=}~\DUrole{name}{characters}~\DUrole{operator}{\DUrole{word}{or}}~\DUrole{punctuation}{\{}~\DUrole{punctuation}{\}}~\\
~\\
\DUrole{name}{characters}\DUrole{punctuation}{.}\DUrole{name}{data}\DUrole{operator}{=}\DUrole{punctuation}{\{}~\\
~\DUrole{punctuation}{{[}}\DUrole{literal}{\DUrole{number}{\DUrole{hex}{0x0000}}}\DUrole{punctuation}{{]}}\DUrole{operator}{=}\DUrole{punctuation}{\{}~\\
~~\DUrole{name}{category}\DUrole{operator}{=}\DUrole{literal}{\DUrole{string}{\DUrole{double}{"}}}\DUrole{literal}{\DUrole{string}{cc"}}\DUrole{punctuation}{,}~\\
~~\DUrole{name}{description}\DUrole{operator}{=}\DUrole{literal}{\DUrole{string}{\DUrole{double}{"}}}\DUrole{literal}{\DUrole{string}{NULL"}}\DUrole{punctuation}{,}~\\
~~\DUrole{name}{direction}\DUrole{operator}{=}\DUrole{literal}{\DUrole{string}{\DUrole{double}{"}}}\DUrole{literal}{\DUrole{string}{bn"}}\DUrole{punctuation}{,}~\\
~~\DUrole{name}{linebreak}\DUrole{operator}{=}\DUrole{literal}{\DUrole{string}{\DUrole{double}{"}}}\DUrole{literal}{\DUrole{string}{cm"}}\DUrole{punctuation}{,}~\\
~~\DUrole{name}{unicodeslot}\DUrole{operator}{=}\DUrole{literal}{\DUrole{number}{\DUrole{hex}{0x0000}}}\DUrole{punctuation}{,}~\\
~\DUrole{punctuation}{\}}
}
\end{quote}
You can also highlight a diff:
%
\begin{quote}{\ttfamily \raggedright \noindent
\DUrole{generic}{\DUrole{heading}{Index:~html4css1.css\\
===================================================================\\
}}\DUrole{generic}{\DUrole{deleted}{-{}-{}-~html4css1.css~~~~~(Revision~7509)\\
}}\DUrole{generic}{\DUrole{inserted}{+++~html4css1.css~~~~~(Arbeitskopie)\\
}}\DUrole{generic}{\DUrole{subheading}{@@~-68,7~+68,7~@@\\
}}~\\
~div.attention~p.admonition-title,~div.caution~p.admonition-title,\\
~div.danger~p.admonition-title,~div.error~p.admonition-title,\\
\DUrole{generic}{\DUrole{deleted}{-div.warning~p.admonition-title~\{\\
}}\DUrole{generic}{\DUrole{inserted}{+div.warning~p.admonition-title,~.code~.error~\{\\
}}~~~color:~red~;\\
~~~font-weight:~bold~;\\
~~~font-family:~sans-serif~\}
}
\end{quote}
\section{Inline code%
\label{inline-code}%
}
Inline code in LaTeX \texttt{\DUrole{code}{\DUrole{tex}{\DUrole{literal}{\DUrole{string}{\$}}\DUrole{name}{\DUrole{variable}{\textbackslash{}alpha}}\DUrole{name}{\DUrole{builtin}{ }}\DUrole{operator}{=}\DUrole{name}{\DUrole{builtin}{ }}\DUrole{name}{\DUrole{variable}{\textbackslash{}int}}\DUrole{name}{\DUrole{builtin}{\_}}\DUrole{literal}{\DUrole{number}{0}}\DUrole{name}{\DUrole{builtin}{\textasciicircum{}}}\DUrole{name}{\DUrole{variable}{\textbackslash{}infty}}\DUrole{name}{\DUrole{builtin}{ f}}\DUrole{operator}{(}\DUrole{name}{\DUrole{builtin}{x}}\DUrole{operator}{)}\DUrole{name}{\DUrole{builtin}{ dx}}\DUrole{literal}{\DUrole{string}{\$}}}}} and
Python: \texttt{\DUrole{code}{\DUrole{testclass}{\DUrole{python}{\DUrole{keyword}{print}\DUrole{punctuation}{(}\DUrole{literal}{\DUrole{string}{"The end."}}\DUrole{punctuation}{)}}}}}.
\end{document}
|