| 1 |
docutils.sty |
| 2 |
************ |
| 3 |
Style file for docutils LaTeX output |
| 4 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 5 |
|
| 6 |
:Copyright: © 2020 Günter Milde |
| 7 |
:Licence: Released under the terms of the `2-Clause BSD license`_, in short: |
| 8 |
|
| 9 |
Copying and distribution of this file, with or without modification, |
| 10 |
are permitted in any medium without royalty provided the copyright |
| 11 |
notice and this notice are preserved. |
| 12 |
This file is offered as-is, without any warranty. |
| 13 |
|
| 14 |
.. _2-Clause BSD license: http://www.spdx.org/licenses/BSD-2-Clause |
| 15 |
|
| 16 |
|
| 17 |
:Abstract: |
| 18 |
Helper commands and element definitions for Docutils_ LaTeX output. |
| 19 |
|
| 20 |
:Changelog: |
| 21 |
.. class:: borderless |
| 22 |
|
| 23 |
====== ========== ========================================================= |
| 24 |
0.1 2020-08-28 initial version |
| 25 |
====== ========== ========================================================= |
| 26 |
|
| 27 |
Installation |
| 28 |
============ |
| 29 |
|
| 30 |
Copy/Move/Link ``docutils.sty`` to a suitable place in the “TeX Directory |
| 31 |
Structure” (TDS_) and run ``texhash``, or place it in the current working |
| 32 |
directory (e.g. for testing). |
| 33 |
|
| 34 |
Usage |
| 35 |
===== |
| 36 |
|
| 37 |
When generating LaTeX documents from reStructuredText sources, |
| 38 |
specify this package with the `"stylesheet"`_ configuration_ option, e.g. |
| 39 |
``rst2latex --stylesheet=docutils``. |
| 40 |
Alternatively, the Docutils `LaTeX writer` will extract required definitions |
| 41 |
and insert them into the preamble of generated documents |
| 42 |
(see `Docutils LaTeX Writer`_ for details). |
| 43 |
|
| 44 |
|
| 45 |
Implementation |
| 46 |
============== |
| 47 |
|
| 48 |
:: |
| 49 |
|
| 50 |
\NeedsTeXFormat{LaTeX2e} |
| 51 |
\ProvidesPackage{docutils} |
| 52 |
[2020/08/28 v0.1 macros for Docutils LaTeX output] |
| 53 |
|
| 54 |
|
| 55 |
Helpers |
| 56 |
------- |
| 57 |
|
| 58 |
duclass:: |
| 59 |
|
| 60 |
% class handling for environments (block-level elements) |
| 61 |
% \begin{DUclass}{spam} tries \DUCLASSspam and |
| 62 |
% \end{DUclass}{spam} tries \endDUCLASSspam |
| 63 |
\ifx\DUclass\undefined % poor man's "provideenvironment" |
| 64 |
\newenvironment{DUclass}[1]% |
| 65 |
{% "#1" does not work in end-part of environment. |
| 66 |
\def\DocutilsClassFunctionName{DUCLASS#1} |
| 67 |
\csname \DocutilsClassFunctionName \endcsname}% |
| 68 |
{\csname end\DocutilsClassFunctionName \endcsname}% |
| 69 |
\fi |
| 70 |
|
| 71 |
providelength:: |
| 72 |
|
| 73 |
% Provide a length variable and set default, if it is new |
| 74 |
\providecommand*{\DUprovidelength}[2]{ |
| 75 |
\ifthenelse{\isundefined{#1}}{\newlength{#1}\setlength{#1}{#2}}{} |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
Configuration defaults |
| 80 |
---------------------- |
| 81 |
|
| 82 |
See `Docutils LaTeX Writer`_ for details. |
| 83 |
|
| 84 |
abstract:: |
| 85 |
|
| 86 |
\providecommand*{\DUCLASSabstract}{ |
| 87 |
\renewcommand{\DUtitle}[1]{\centerline{\textbf{##1}}} |
| 88 |
} |
| 89 |
|
| 90 |
dedication:: |
| 91 |
|
| 92 |
% special topic for dedications |
| 93 |
\providecommand*{\DUCLASSdedication}{% |
| 94 |
\renewenvironment{quote}{\begin{center}}{\end{center}}% |
| 95 |
} |
| 96 |
|
| 97 |
TODO: add \em to set dedication text in italics? |
| 98 |
|
| 99 |
docinfo:: |
| 100 |
|
| 101 |
% width of docinfo table |
| 102 |
\DUprovidelength{\DUdocinfowidth}{0.9\linewidth} |
| 103 |
|
| 104 |
error:: |
| 105 |
|
| 106 |
\providecommand*{\DUCLASSerror}{\color{red}} |
| 107 |
|
| 108 |
highlight_rules:: |
| 109 |
|
| 110 |
% basic code highlight: |
| 111 |
\providecommand*\DUrolecomment[1]{\textcolor[rgb]{0.40,0.40,0.40}{#1}} |
| 112 |
\providecommand*\DUroledeleted[1]{\textcolor[rgb]{0.40,0.40,0.40}{#1}} |
| 113 |
\providecommand*\DUrolekeyword[1]{\textbf{#1}} |
| 114 |
\providecommand*\DUrolestring[1]{\textit{#1}} |
| 115 |
|
| 116 |
Elements |
| 117 |
-------- |
| 118 |
|
| 119 |
Definitions for unknown or to-be-configured Docutils elements |
| 120 |
and roles (inline elements). |
| 121 |
|
| 122 |
admonition:: |
| 123 |
|
| 124 |
% admonition environment (specially marked topic) |
| 125 |
\ifx\DUadmonition\undefined % poor man's "provideenvironment" |
| 126 |
\newbox{\DUadmonitionbox} |
| 127 |
\newenvironment{DUadmonition}% |
| 128 |
{\begin{center} |
| 129 |
\begin{lrbox}{\DUadmonitionbox} |
| 130 |
\begin{minipage}{0.9\linewidth} |
| 131 |
}% |
| 132 |
{ \end{minipage} |
| 133 |
\end{lrbox} |
| 134 |
\fbox{\usebox{\DUadmonitionbox}} |
| 135 |
\end{center} |
| 136 |
} |
| 137 |
\fi |
| 138 |
|
| 139 |
fieldlist:: |
| 140 |
|
| 141 |
% field list environment (for separate configuration of `field lists`) |
| 142 |
\ifthenelse{\isundefined{\DUfieldlist}}{ |
| 143 |
\newenvironment{DUfieldlist}% |
| 144 |
{\quote\description} |
| 145 |
{\enddescription\endquote} |
| 146 |
}{} |
| 147 |
|
| 148 |
footnotes:: |
| 149 |
|
| 150 |
% numerical or symbol footnotes with hyperlinks and backlinks |
| 151 |
\providecommand*{\DUfootnotemark}[3]{% |
| 152 |
\raisebox{1em}{\hypertarget{#1}{}}% |
| 153 |
\hyperlink{#2}{\textsuperscript{#3}}% |
| 154 |
} |
| 155 |
\providecommand{\DUfootnotetext}[4]{% |
| 156 |
\begingroup% |
| 157 |
\renewcommand{\thefootnote}{% |
| 158 |
\protect\raisebox{1em}{\protect\hypertarget{#1}{}}% |
| 159 |
\protect\hyperlink{#2}{#3}}% |
| 160 |
\footnotetext{#4}% |
| 161 |
\endgroup% |
| 162 |
} |
| 163 |
|
| 164 |
inline:: |
| 165 |
|
| 166 |
% custom inline roles: \DUrole{#1}{#2} tries \DUrole#1{#2} |
| 167 |
\providecommand*{\DUrole}[2]{% |
| 168 |
\ifcsname DUrole#1\endcsname% |
| 169 |
\csname DUrole#1\endcsname{#2}% |
| 170 |
\else% |
| 171 |
#2% |
| 172 |
\fi% |
| 173 |
} |
| 174 |
|
| 175 |
legend:: |
| 176 |
|
| 177 |
% legend environment (in figures and formal tables) |
| 178 |
\ifthenelse{\isundefined{\DUlegend}}{ |
| 179 |
\newenvironment{DUlegend}{\small}{} |
| 180 |
}{} |
| 181 |
|
| 182 |
lineblock:: |
| 183 |
|
| 184 |
% line block environment |
| 185 |
\DUprovidelength{\DUlineblockindent}{2.5em} |
| 186 |
\ifthenelse{\isundefined{\DUlineblock}}{ |
| 187 |
\newenvironment{DUlineblock}[1]{% |
| 188 |
\list{}{\setlength{\partopsep}{\parskip} |
| 189 |
\addtolength{\partopsep}{\baselineskip} |
| 190 |
\setlength{\topsep}{0pt} |
| 191 |
\setlength{\itemsep}{0.15\baselineskip} |
| 192 |
\setlength{\parsep}{0pt} |
| 193 |
\setlength{\leftmargin}{#1}} |
| 194 |
\raggedright |
| 195 |
} |
| 196 |
{\endlist} |
| 197 |
}{} |
| 198 |
|
| 199 |
optionlist:: |
| 200 |
|
| 201 |
% list of command line options |
| 202 |
\providecommand*{\DUoptionlistlabel}[1]{\bfseries #1 \hfill} |
| 203 |
\DUprovidelength{\DUoptionlistindent}{3cm} |
| 204 |
\ifthenelse{\isundefined{\DUoptionlist}}{ |
| 205 |
\newenvironment{DUoptionlist}{% |
| 206 |
\list{}{\setlength{\labelwidth}{\DUoptionlistindent} |
| 207 |
\setlength{\rightmargin}{1cm} |
| 208 |
\setlength{\leftmargin}{\rightmargin} |
| 209 |
\addtolength{\leftmargin}{\labelwidth} |
| 210 |
\addtolength{\leftmargin}{\labelsep} |
| 211 |
\renewcommand{\makelabel}{\DUoptionlistlabel}} |
| 212 |
} |
| 213 |
{\endlist} |
| 214 |
}{} |
| 215 |
|
| 216 |
rubric:: |
| 217 |
|
| 218 |
% informal heading |
| 219 |
\providecommand*{\DUrubric}[1]{\subsubsection*{\emph{#1}}} |
| 220 |
|
| 221 |
sidebar:: |
| 222 |
|
| 223 |
% text outside the main text flow |
| 224 |
\providecommand{\DUsidebar}[1]{% |
| 225 |
\begin{center} |
| 226 |
\colorbox[gray]{0.80}{\parbox{0.9\linewidth}{#1}} |
| 227 |
\end{center} |
| 228 |
} |
| 229 |
|
| 230 |
title:: |
| 231 |
|
| 232 |
% title for topics, admonitions, unsupported section levels, and sidebar |
| 233 |
\providecommand*{\DUtitle}[1]{\subsubsection*{#1}} |
| 234 |
|
| 235 |
subtitle:: |
| 236 |
|
| 237 |
% subtitle (for sidebar) |
| 238 |
\providecommand*{\DUsubtitle}[1]{\par\emph{#1}\smallskip} |
| 239 |
|
| 240 |
documentsubtitle:: |
| 241 |
|
| 242 |
% subtitle (in document title) |
| 243 |
\providecommand*{\DUdocumentsubtitle}[1]{{\large #1}} |
| 244 |
|
| 245 |
titlereference:: |
| 246 |
|
| 247 |
% titlereference standard role |
| 248 |
\providecommand*{\DUroletitlereference}[1]{\textsl{#1}} |
| 249 |
|
| 250 |
transition:: |
| 251 |
|
| 252 |
% transition (break / fancybreak / anonymous section) |
| 253 |
\providecommand*{\DUtransition}{% |
| 254 |
\hspace*{\fill}\hrulefill\hspace*{\fill} |
| 255 |
\vskip 0.5\baselineskip |
| 256 |
} |
| 257 |
|
| 258 |
References |
| 259 |
========== |
| 260 |
|
| 261 |
.. [Docutils] https://docutils.sourceforge.io/ |
| 262 |
|
| 263 |
.. _Docutils Document Tree: |
| 264 |
https://docutils.sourceforge.io/docs/ref/doctree.html |
| 265 |
|
| 266 |
.. _Docutils LaTeX Writer: |
| 267 |
https://docutils.sourceforge.io/docs/user/latex.html |
| 268 |
|
| 269 |
.. _Configuration: |
| 270 |
https://docutils.sourceforge.io/docs/user/config.html |
| 271 |
|
| 272 |
.. _"stylesheet": |
| 273 |
https://docutils.sourceforge.io/docs/user/config.html#stylesheet-latex-writers |
| 274 |
|
| 275 |
.. _TDS: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=tds |