| 1 |
%% docutils.sty: macros for Docutils LaTeX output. |
| 2 |
%% |
| 3 |
%% Copyright © 2020, 2024 Günter Milde |
| 4 |
%% Released under the terms of the `2-Clause BSD license`, in short: |
| 5 |
%% |
| 6 |
%% Copying and distribution of this file, with or without modification, |
| 7 |
%% are permitted in any medium without royalty provided the copyright |
| 8 |
%% notice and this notice are preserved. |
| 9 |
%% This file is offered as-is, without any warranty. |
| 10 |
|
| 11 |
% docutils.sty |
| 12 |
% ************ |
| 13 |
% |
| 14 |
% .. contents:: |
| 15 |
% .. include:: README.md |
| 16 |
% :parser: commonmark |
| 17 |
% |
| 18 |
% Implementation |
| 19 |
% ============== |
| 20 |
% |
| 21 |
% :: |
| 22 |
|
| 23 |
\NeedsTeXFormat{LaTeX2e} |
| 24 |
\ProvidesPackage{docutils} |
| 25 |
[2026-05-06 macros for Docutils LaTeX output] |
| 26 |
|
| 27 |
% Helpers |
| 28 |
% ------- |
| 29 |
% |
| 30 |
% duclass:: |
| 31 |
|
| 32 |
% class handling for environments (block-level elements) |
| 33 |
% \begin{DUclass}{spam} tries \DUCLASSspam and |
| 34 |
% \end{DUclass}{spam} tries \endDUCLASSspam |
| 35 |
\ifdefined\DUclass |
| 36 |
\else % poor man's "provideenvironment" |
| 37 |
\newenvironment{DUclass}[1]% |
| 38 |
{% "#1" does not work in end-part of environment. |
| 39 |
\def\DocutilsClassFunctionName{DUCLASS#1} |
| 40 |
\csname \DocutilsClassFunctionName \endcsname}% |
| 41 |
{\csname end\DocutilsClassFunctionName \endcsname}% |
| 42 |
\fi |
| 43 |
|
| 44 |
% providelength:: |
| 45 |
|
| 46 |
% Provide a length variable and set default, if it is new |
| 47 |
\providecommand*{\DUprovidelength}[2]{% |
| 48 |
\ifdefined#1 |
| 49 |
\else |
| 50 |
\newlength{#1}\setlength{#1}{#2}% |
| 51 |
\fi |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
% Configuration defaults |
| 56 |
% ---------------------- |
| 57 |
% |
| 58 |
% See `Generating LaTeX with Docutils`_ for details. |
| 59 |
% |
| 60 |
% abstract:: |
| 61 |
|
| 62 |
\providecommand*{\DUCLASSabstract}{ |
| 63 |
\renewcommand{\DUtitle}[1]{\centerline{\textbf{##1}}} |
| 64 |
} |
| 65 |
|
| 66 |
% dedication:: |
| 67 |
|
| 68 |
% special topic for dedications |
| 69 |
\providecommand*{\DUCLASSdedication}{% |
| 70 |
\renewenvironment{quote}{\begin{center}}{\end{center}}% |
| 71 |
} |
| 72 |
|
| 73 |
% .. TODO: add \em to set dedication text in italics? |
| 74 |
% |
| 75 |
% docinfo:: |
| 76 |
|
| 77 |
% width of docinfo table |
| 78 |
\DUprovidelength{\DUdocinfowidth}{0.9\linewidth} |
| 79 |
|
| 80 |
% error:: |
| 81 |
|
| 82 |
\providecommand*{\DUCLASSerror}{\color{red}} |
| 83 |
|
| 84 |
% highlight_rules:: |
| 85 |
|
| 86 |
% basic code highlight: |
| 87 |
\providecommand*\DUrolecomment[1]{\textcolor[rgb]{0.40,0.40,0.40}{#1}} |
| 88 |
\providecommand*\DUroledeleted[1]{\textcolor[rgb]{0.40,0.40,0.40}{#1}} |
| 89 |
\providecommand*\DUrolekeyword[1]{\textbf{#1}} |
| 90 |
\providecommand*\DUrolestring[1]{\textit{#1}} |
| 91 |
|
| 92 |
% Elements |
| 93 |
% -------- |
| 94 |
% |
| 95 |
% Definitions for unknown or to-be-configured Docutils elements. |
| 96 |
% |
| 97 |
% admonition:: |
| 98 |
|
| 99 |
% admonition environment (specially marked topic) |
| 100 |
\ifdefined\DUadmonition |
| 101 |
\else % poor man's "provideenvironment" |
| 102 |
\newbox{\DUadmonitionbox} |
| 103 |
\newenvironment{DUadmonition}% |
| 104 |
{\begin{center} |
| 105 |
\begin{lrbox}{\DUadmonitionbox} |
| 106 |
\begin{minipage}{0.9\linewidth} |
| 107 |
}% |
| 108 |
{ \end{minipage} |
| 109 |
\end{lrbox} |
| 110 |
\fbox{\usebox{\DUadmonitionbox}} |
| 111 |
\end{center} |
| 112 |
} |
| 113 |
\fi |
| 114 |
|
| 115 |
% fieldlist:: |
| 116 |
|
| 117 |
% field list environment (for separate configuration of `field lists`) |
| 118 |
\ifdefined\DUfieldlist |
| 119 |
\else |
| 120 |
\newenvironment{DUfieldlist}% |
| 121 |
{\quote\description} |
| 122 |
{\enddescription\endquote} |
| 123 |
\fi |
| 124 |
|
| 125 |
% footnotes:: |
| 126 |
|
| 127 |
% numbered or symbol footnotes with hyperlinks and backlinks |
| 128 |
\providecommand*{\DUfootnotemark}[3]{% |
| 129 |
\raisebox{1em}{\hypertarget{#1}{}}% |
| 130 |
\hyperref[#2]{\textsuperscript{#3}}% |
| 131 |
} |
| 132 |
\providecommand{\DUfootnotetext}[4]{% |
| 133 |
\begingroup% |
| 134 |
\renewcommand{\thefootnote}{% |
| 135 |
\protect\phantomsection\protect\label{#1} |
| 136 |
\protect\hyperlink{#2}{#3}}% |
| 137 |
\footnotetext{#4}% |
| 138 |
\endgroup% |
| 139 |
} |
| 140 |
|
| 141 |
% bracket_footnoterefs:: |
| 142 |
|
| 143 |
% use full-size footnotemarks with brackets |
| 144 |
\providecommand*{\DUbracketfootnotemark}[3]{% |
| 145 |
\raisebox{1em}{\hypertarget{#1}{}}% |
| 146 |
\hyperref[#2]{[#3]}% |
| 147 |
} |
| 148 |
|
| 149 |
% inline:: |
| 150 |
|
| 151 |
% custom inline roles: \DUrole{#1}{#2} tries \DUrole#1{#2} |
| 152 |
\providecommand*{\DUrole}[2]{% |
| 153 |
\ifcsname DUrole#1\endcsname% |
| 154 |
\csname DUrole#1\endcsname{#2}% |
| 155 |
\else% |
| 156 |
#2% |
| 157 |
\fi% |
| 158 |
} |
| 159 |
|
| 160 |
% Definitions for `semantic HTML inline markup`__ and representation of edits |
| 161 |
% |
| 162 |
% __ https://docutils.sourceforge.io/docs/ref/rst/definitions.html#additional-roles-for-html |
| 163 |
|
| 164 |
% inline role b:: |
| 165 |
|
| 166 |
\providecommand{\DUroleb}{\textbf} |
| 167 |
|
| 168 |
% inline role del:: |
| 169 |
|
| 170 |
\providecommand{\DUroledel}{\st} |
| 171 |
|
| 172 |
% inline role dfn:: |
| 173 |
|
| 174 |
\providecommand{\DUroledfn}{\emph} |
| 175 |
|
| 176 |
% inline role i:: |
| 177 |
|
| 178 |
\providecommand{\DUrolei}{\textit} |
| 179 |
|
| 180 |
% inline role ins:: |
| 181 |
|
| 182 |
\providecommand{\DUroleins}{\ul} |
| 183 |
|
| 184 |
% inline role kbd:: |
| 185 |
|
| 186 |
\providecommand{\DUrolekbd}{\texttt} |
| 187 |
|
| 188 |
% inline role mark:: |
| 189 |
|
| 190 |
\providecommand{\DUrolemark}{\hl} |
| 191 |
|
| 192 |
% inline role q:: |
| 193 |
|
| 194 |
\providecommand{\DUroleq}[1]{“#1”} |
| 195 |
|
| 196 |
% inline role s:: |
| 197 |
|
| 198 |
\providecommand{\DUroles}{\st} |
| 199 |
|
| 200 |
% inline role small:: |
| 201 |
|
| 202 |
\providecommand{\DUrolesmall}[1]{{\footnotesize #1}} |
| 203 |
|
| 204 |
% inline role st:: |
| 205 |
|
| 206 |
\providecommand{\DUroledel}{\st} |
| 207 |
|
| 208 |
% inline role u:: |
| 209 |
|
| 210 |
\providecommand{\DUroleu}{\ul} |
| 211 |
|
| 212 |
% inline role var:: |
| 213 |
|
| 214 |
\providecommand{\DUrolevar}{\textit} |
| 215 |
|
| 216 |
% Fallback hacks (Docutils loads "soul" for better implementation) |
| 217 |
\providecommand{\hl}{\underline} |
| 218 |
\providecommand{\st}[1]{% |
| 219 |
\raisebox{1ex}{\underline{\smash{\raisebox{-1ex}{#1}}}}% |
| 220 |
} |
| 221 |
\providecommand{\ul}{\underline} |
| 222 |
|
| 223 |
% legend:: |
| 224 |
|
| 225 |
% legend environment (in figures and formal tables) |
| 226 |
\ifdefined\DUlegend |
| 227 |
\else |
| 228 |
\newenvironment{DUlegend}{\small}{} |
| 229 |
\fi |
| 230 |
|
| 231 |
% lineblock:: |
| 232 |
|
| 233 |
% line block environment |
| 234 |
\DUprovidelength{\DUlineblockindent}{2.5em} |
| 235 |
\ifdefined\DUlineblock |
| 236 |
\else |
| 237 |
\newenvironment{DUlineblock}[1]{% |
| 238 |
\list{}{\setlength{\partopsep}{\parskip} |
| 239 |
\addtolength{\partopsep}{\baselineskip} |
| 240 |
\setlength{\topsep}{0pt} |
| 241 |
\setlength{\itemsep}{0.15\baselineskip} |
| 242 |
\setlength{\parsep}{0pt} |
| 243 |
\setlength{\leftmargin}{#1}} |
| 244 |
\raggedright |
| 245 |
} |
| 246 |
{\endlist} |
| 247 |
\fi |
| 248 |
|
| 249 |
% optionlist:: |
| 250 |
|
| 251 |
% list of command line options |
| 252 |
\providecommand*{\DUoptionlistlabel}[1]{\bfseries #1 \hfill} |
| 253 |
\DUprovidelength{\DUoptionlistindent}{3cm} |
| 254 |
\ifdefined\DUoptionlist |
| 255 |
\else |
| 256 |
\newenvironment{DUoptionlist}{% |
| 257 |
\list{}{\setlength{\labelwidth}{\DUoptionlistindent} |
| 258 |
\setlength{\rightmargin}{1cm} |
| 259 |
\setlength{\leftmargin}{\rightmargin} |
| 260 |
\addtolength{\leftmargin}{\labelwidth} |
| 261 |
\addtolength{\leftmargin}{\labelsep} |
| 262 |
\renewcommand{\makelabel}{\DUoptionlistlabel}} |
| 263 |
} |
| 264 |
{\endlist} |
| 265 |
\fi |
| 266 |
|
| 267 |
% rubric:: |
| 268 |
|
| 269 |
% informal heading |
| 270 |
\providecommand*{\DUrubric}[1]{\subsubsection*{\emph{#1}}} |
| 271 |
|
| 272 |
% sidebar:: |
| 273 |
|
| 274 |
% text outside the main text flow |
| 275 |
\providecommand{\DUsidebar}[1]{% |
| 276 |
\begin{center} |
| 277 |
\colorbox[gray]{0.80}{\parbox{0.9\linewidth}{#1}} |
| 278 |
\end{center} |
| 279 |
} |
| 280 |
|
| 281 |
% title:: |
| 282 |
|
| 283 |
% title for topics, admonitions, unsupported section levels, and sidebar |
| 284 |
\providecommand*{\DUtitle}[1]{% |
| 285 |
\smallskip\noindent\textbf{#1}\smallskip} |
| 286 |
|
| 287 |
% subtitle:: |
| 288 |
|
| 289 |
% subtitle (for sidebar) |
| 290 |
\providecommand*{\DUsubtitle}[1]{\par\emph{#1}\smallskip} |
| 291 |
|
| 292 |
% documentsubtitle:: |
| 293 |
|
| 294 |
% subtitle (in document title) |
| 295 |
\providecommand*{\DUdocumentsubtitle}[1]{{\large #1}} |
| 296 |
|
| 297 |
% titlereference:: |
| 298 |
|
| 299 |
% titlereference standard role |
| 300 |
\providecommand*{\DUroletitlereference}[1]{\textsl{#1}} |
| 301 |
|
| 302 |
% transition:: |
| 303 |
|
| 304 |
% transition (break / fancybreak / anonymous section) |
| 305 |
\providecommand*{\DUtransition}{% |
| 306 |
\hspace*{\fill}\hrulefill\hspace*{\fill} |
| 307 |
\vskip 0.5\baselineskip |
| 308 |
} |
| 309 |
|
| 310 |
% Length Units |
| 311 |
% ------------ |
| 312 |
% |
| 313 |
% Emulating `CSS3 length units`_ unknown to LaTeX. |
| 314 |
% |
| 315 |
% rem:: |
| 316 |
|
| 317 |
\DUprovidelength{\DUremdimen}{1em} |
| 318 |
|
| 319 |
% vmin:: |
| 320 |
|
| 321 |
\AtBeginDocument{ |
| 322 |
\ifdim\paperwidth>\paperheight\relax |
| 323 |
\DUprovidelength{\DUvmindimen}{0.01\paperheight} |
| 324 |
\else |
| 325 |
\DUprovidelength{\DUvmindimen}{0.01\paperwidth} |
| 326 |
\fi |
| 327 |
} |
| 328 |
|
| 329 |
% vmax:: |
| 330 |
|
| 331 |
\AtBeginDocument{ |
| 332 |
\ifdim\paperwidth>\paperheight\relax |
| 333 |
\DUprovidelength{\DUvmaxdimen}{0.01\paperwidth} |
| 334 |
\else |
| 335 |
\DUprovidelength{\DUvmaxdimen}{0.01\paperheight} |
| 336 |
\fi |
| 337 |
} |
| 338 |
|
| 339 |
|
| 340 |
% .. References: |
| 341 |
% |
| 342 |
% .. _Generating LaTeX with Docutils: |
| 343 |
% https://docutils.sourceforge.io/docs/user/latex.html |
| 344 |
% .. _CSS3 length units: https://www.w3.org/TR/css-values-3/#lengths |