docutils.sty 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. %% docutils.sty: macros for Docutils LaTeX output.
  2. %%
  3. %% Copyright © 2020 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. % .. include:: README.md
  11. %
  12. % Implementation
  13. % ==============
  14. %
  15. % ::
  16. \NeedsTeXFormat{LaTeX2e}
  17. \ProvidesPackage{docutils}
  18. [2021/05/18 macros for Docutils LaTeX output]
  19. % Helpers
  20. % -------
  21. %
  22. % duclass::
  23. % class handling for environments (block-level elements)
  24. % \begin{DUclass}{spam} tries \DUCLASSspam and
  25. % \end{DUclass}{spam} tries \endDUCLASSspam
  26. \ifx\DUclass\undefined % poor man's "provideenvironment"
  27. \newenvironment{DUclass}[1]%
  28. {% "#1" does not work in end-part of environment.
  29. \def\DocutilsClassFunctionName{DUCLASS#1}
  30. \csname \DocutilsClassFunctionName \endcsname}%
  31. {\csname end\DocutilsClassFunctionName \endcsname}%
  32. \fi
  33. % providelength::
  34. % Provide a length variable and set default, if it is new
  35. \providecommand*{\DUprovidelength}[2]{
  36. \ifthenelse{\isundefined{#1}}{\newlength{#1}\setlength{#1}{#2}}{}
  37. }
  38. % Configuration defaults
  39. % ----------------------
  40. %
  41. % See `Docutils LaTeX Writer`_ for details.
  42. %
  43. % abstract::
  44. \providecommand*{\DUCLASSabstract}{
  45. \renewcommand{\DUtitle}[1]{\centerline{\textbf{##1}}}
  46. }
  47. % dedication::
  48. % special topic for dedications
  49. \providecommand*{\DUCLASSdedication}{%
  50. \renewenvironment{quote}{\begin{center}}{\end{center}}%
  51. }
  52. % TODO: add \em to set dedication text in italics?
  53. %
  54. % docinfo::
  55. % width of docinfo table
  56. \DUprovidelength{\DUdocinfowidth}{0.9\linewidth}
  57. % error::
  58. \providecommand*{\DUCLASSerror}{\color{red}}
  59. % highlight_rules::
  60. % basic code highlight:
  61. \providecommand*\DUrolecomment[1]{\textcolor[rgb]{0.40,0.40,0.40}{#1}}
  62. \providecommand*\DUroledeleted[1]{\textcolor[rgb]{0.40,0.40,0.40}{#1}}
  63. \providecommand*\DUrolekeyword[1]{\textbf{#1}}
  64. \providecommand*\DUrolestring[1]{\textit{#1}}
  65. % Elements
  66. % --------
  67. %
  68. % Definitions for unknown or to-be-configured Docutils elements.
  69. %
  70. % admonition::
  71. % admonition environment (specially marked topic)
  72. \ifx\DUadmonition\undefined % poor man's "provideenvironment"
  73. \newbox{\DUadmonitionbox}
  74. \newenvironment{DUadmonition}%
  75. {\begin{center}
  76. \begin{lrbox}{\DUadmonitionbox}
  77. \begin{minipage}{0.9\linewidth}
  78. }%
  79. { \end{minipage}
  80. \end{lrbox}
  81. \fbox{\usebox{\DUadmonitionbox}}
  82. \end{center}
  83. }
  84. \fi
  85. % fieldlist::
  86. % field list environment (for separate configuration of `field lists`)
  87. \ifthenelse{\isundefined{\DUfieldlist}}{
  88. \newenvironment{DUfieldlist}%
  89. {\quote\description}
  90. {\enddescription\endquote}
  91. }{}
  92. % footnotes::
  93. % numerical or symbol footnotes with hyperlinks and backlinks
  94. \providecommand*{\DUfootnotemark}[3]{%
  95. \raisebox{1em}{\hypertarget{#1}{}}%
  96. \hyperlink{#2}{\textsuperscript{#3}}%
  97. }
  98. \providecommand{\DUfootnotetext}[4]{%
  99. \begingroup%
  100. \renewcommand{\thefootnote}{%
  101. \protect\raisebox{1em}{\protect\hypertarget{#1}{}}%
  102. \protect\hyperlink{#2}{#3}}%
  103. \footnotetext{#4}%
  104. \endgroup%
  105. }
  106. % inline::
  107. % custom inline roles: \DUrole{#1}{#2} tries \DUrole#1{#2}
  108. \providecommand*{\DUrole}[2]{%
  109. \ifcsname DUrole#1\endcsname%
  110. \csname DUrole#1\endcsname{#2}%
  111. \else%
  112. #2%
  113. \fi%
  114. }
  115. % legend::
  116. % legend environment (in figures and formal tables)
  117. \ifthenelse{\isundefined{\DUlegend}}{
  118. \newenvironment{DUlegend}{\small}{}
  119. }{}
  120. % lineblock::
  121. % line block environment
  122. \DUprovidelength{\DUlineblockindent}{2.5em}
  123. \ifthenelse{\isundefined{\DUlineblock}}{
  124. \newenvironment{DUlineblock}[1]{%
  125. \list{}{\setlength{\partopsep}{\parskip}
  126. \addtolength{\partopsep}{\baselineskip}
  127. \setlength{\topsep}{0pt}
  128. \setlength{\itemsep}{0.15\baselineskip}
  129. \setlength{\parsep}{0pt}
  130. \setlength{\leftmargin}{#1}}
  131. \raggedright
  132. }
  133. {\endlist}
  134. }{}
  135. % optionlist::
  136. % list of command line options
  137. \providecommand*{\DUoptionlistlabel}[1]{\bfseries #1 \hfill}
  138. \DUprovidelength{\DUoptionlistindent}{3cm}
  139. \ifthenelse{\isundefined{\DUoptionlist}}{
  140. \newenvironment{DUoptionlist}{%
  141. \list{}{\setlength{\labelwidth}{\DUoptionlistindent}
  142. \setlength{\rightmargin}{1cm}
  143. \setlength{\leftmargin}{\rightmargin}
  144. \addtolength{\leftmargin}{\labelwidth}
  145. \addtolength{\leftmargin}{\labelsep}
  146. \renewcommand{\makelabel}{\DUoptionlistlabel}}
  147. }
  148. {\endlist}
  149. }{}
  150. % rubric::
  151. % informal heading
  152. \providecommand*{\DUrubric}[1]{\subsubsection*{\emph{#1}}}
  153. % sidebar::
  154. % text outside the main text flow
  155. \providecommand{\DUsidebar}[1]{%
  156. \begin{center}
  157. \colorbox[gray]{0.80}{\parbox{0.9\linewidth}{#1}}
  158. \end{center}
  159. }
  160. % title::
  161. % title for topics, admonitions, unsupported section levels, and sidebar
  162. \providecommand*{\DUtitle}[1]{%
  163. \smallskip\noindent\textbf{#1}\smallskip}
  164. % subtitle::
  165. % subtitle (for sidebar)
  166. \providecommand*{\DUsubtitle}[1]{\par\emph{#1}\smallskip}
  167. % documentsubtitle::
  168. % subtitle (in document title)
  169. \providecommand*{\DUdocumentsubtitle}[1]{{\large #1}}
  170. % titlereference::
  171. % titlereference standard role
  172. \providecommand*{\DUroletitlereference}[1]{\textsl{#1}}
  173. % transition::
  174. % transition (break / fancybreak / anonymous section)
  175. \providecommand*{\DUtransition}{%
  176. \hspace*{\fill}\hrulefill\hspace*{\fill}
  177. \vskip 0.5\baselineskip
  178. }