| 1 |
% !TeX root = ../easyfloats.tex |
| 2 |
|
| 3 |
% Copyright © 2020 E. Zöllner |
| 4 |
% Alternatively to the terms of the LPPL, at your choice, |
| 5 |
% you can redistribute and/or modify this file under the |
| 6 |
% terms of the Do What The Fuck You Want To Public License, Version 2, |
| 7 |
% as published by Sam Hocevar. See http://www.wtfpl.net/about/. |
| 8 |
|
| 9 |
% Defines additional macros which are not provided |
| 10 |
% by the document class or other packages. |
| 11 |
% |
| 12 |
% \TikZ |
| 13 |
% Typesets the name of the TikZ package. |
| 14 |
% dtxdescribe defines the \tikz macro for that |
| 15 |
% but it's wrong, the Z is not capitalized. |
| 16 |
% |
| 17 |
% \eTeX |
| 18 |
% Typesets the name of eTeX. |
| 19 |
% In standard LaTeX there are \TeX, \LaTeX and \LaTeXe. |
| 20 |
% metalogo and dtxdescribe define more logos. |
| 21 |
% But I have failed to find a package which provides |
| 22 |
% the eTeX logo. |
| 23 |
% In contrast to the other logo macros \eTeX includes a |
| 24 |
% link to the eTeX manual on CTAN. |
| 25 |
% |
| 26 |
% \radioon |
| 27 |
% draws an activated radio button |
| 28 |
% \radiooff |
| 29 |
% draws a deactivated radio button |
| 30 |
% |
| 31 |
% \DescribeMacro{<name>} |
| 32 |
% \DescribeEnv{<name>} |
| 33 |
% \DescribeKey{<name>} |
| 34 |
% \DescribeHandler{<name>} |
| 35 |
% Prints the name in the margin, similar to the dtxdescribe package. |
| 36 |
% A link target and \ignorespaces are added in description-links.tex. |
| 37 |
% |
| 38 |
% \cmd{<name>} |
| 39 |
% To reference a command described with \DescribeMacro. |
| 40 |
% |
| 41 |
% \env{<name>} |
| 42 |
% To reference an environment described with \DescribeEnv. |
| 43 |
% |
| 44 |
% \handler{<name>} |
| 45 |
% To reference a handler described with \DescribeHandler. |
| 46 |
% |
| 47 |
% \filename{<filename>} |
| 48 |
% Typesets a file name in the pdf. |
| 49 |
% |
| 50 |
% \pkg{<name>} |
| 51 |
% To reference a package. |
| 52 |
% |
| 53 |
% \tikzlibrary{<name>} |
| 54 |
% To reference a TikZ library. |
| 55 |
% |
| 56 |
% \meta{<name>} |
| 57 |
% Similar to the dtxdescribe package. |
| 58 |
% |
| 59 |
% \pkgoptn{<option>} |
| 60 |
% Typesets a package option in the pdf. |
| 61 |
% \key{<option>} |
| 62 |
% Typesets a macro/environment option in the pdf. |
| 63 |
% When using the dtxdescribe package \optn is used for both macro options and package options. |
| 64 |
% However, I am using pgfkeys for macro options and standard LaTeX |
| 65 |
% for package options making the two types of options quite different. |
| 66 |
% Unlike some other packages the easyfloats package does not allow to |
| 67 |
% pass macro options as package options. |
| 68 |
% Therefore I like to have a better distinction between them even |
| 69 |
% if they are formatted in the same way. |
| 70 |
% Also, dtxdescribe defines two different macros for the description: |
| 71 |
% \DescribeOption for package/class options and |
| 72 |
% \DescribeKey for macro/environment options. |
| 73 |
% So it is only consistent to have two different macros for typesetting |
| 74 |
% macro/environment and package/class options. |
| 75 |
% I have defined \optn to print an error in order to avoid confusion. |
| 76 |
% \val{<value>} |
| 77 |
% typesets the value of a key. Package options don't have values. |
| 78 |
% |
| 79 |
% \errormessage{<message>} |
| 80 |
% Typesets an error message in the pdf. Changes category codes so that |
| 81 |
% control sequences and active characters do *not* need to be prefixed |
| 82 |
% by \string. |
| 83 |
% |
| 84 |
% \sectionname{<title>} |
| 85 |
% Format the name of a section of a different document which I am referring to. |
| 86 |
% For sections of this document use \cref or \Cref instead. |
| 87 |
% |
| 88 |
% \newlicense{<name>}{<display text>}{<url>} |
| 89 |
% \license{<name>} |
| 90 |
% Define a license in the preamble with displayed name and URL with \newlicense |
| 91 |
% and use it in the document with \license. |
| 92 |
% Changes catcodes for the <url> only so that special characters |
| 93 |
% can be used there without worrying (except for curly braces). |
| 94 |
% |
| 95 |
% \formatcode{<texcode>} |
| 96 |
% Formats inline code. |
| 97 |
% It does not change catcodes or performs any other kind of magic. |
| 98 |
% <texcode> is executed as TeX code. |
| 99 |
% |
| 100 |
% \formatlabel{<label>} |
| 101 |
% How to format the name of a label used in an example. |
| 102 |
% |
| 103 |
% \formatcaption{<label>} |
| 104 |
% How to format the caption used in an example. |
| 105 |
% |
| 106 |
% \notocspace |
| 107 |
% inserts a negative vertical space in the table of contents |
| 108 |
% in order to cancel out an undesired space after a section |
| 109 |
|
| 110 |
\usepackage{relsize} |
| 111 |
|
| 112 |
|
| 113 |
\makeatletter |
| 114 |
\newcommand{\version}{\newcommand\theversion} |
| 115 |
\newcommand{\package}{\newcommand\thepackage} |
| 116 |
\newcommand{\thedate}{\@date} |
| 117 |
\AtBeginDocument{% |
| 118 |
\let\thedate=\@date |
| 119 |
\ifundef{\theversion}{}{\appto\@date{\strut\\\strut\thepackage~\theversion}}% |
| 120 |
} |
| 121 |
\makeatother |
| 122 |
|
| 123 |
\makeatletter |
| 124 |
\newcommand\parskipintoc[1]{% |
| 125 |
\def\@starttoc##1{% |
| 126 |
\begingroup |
| 127 |
\makeatletter |
| 128 |
\parskip=#1\relax |
| 129 |
\@input{\jobname.##1}% |
| 130 |
\if@filesw |
| 131 |
\expandafter\newwrite\csname tf@##1\endcsname |
| 132 |
\immediate\openout\csname tf@##1\endcsname \jobname.##1\relax |
| 133 |
\fi |
| 134 |
\@nobreakfalse |
| 135 |
\endgroup |
| 136 |
} |
| 137 |
} |
| 138 |
\makeatother |
| 139 |
\parskipintoc{0pt plus .6em minus 1pt} |
| 140 |
|
| 141 |
\newcommand{\bigpar}{\par{\centering*~*~*\pagebreak[3]\par}} |
| 142 |
\newcommand{\bigparinlist}{\par\medskip\pagebreak[3]\par} |
| 143 |
\let\OriginalItemize=\itemize |
| 144 |
\def\itemize{\OriginalItemize\let\bigpar\bigparinlist} |
| 145 |
|
| 146 |
\newcommand{\eTeX}{\texorpdfstring{\href{https://ctan.org/pkg/etex}{\ensuremath{\varepsilon}-\TeX}}{eTeX}} |
| 147 |
\newcommand{\TikZ}{Ti\emph{k}Z} |
| 148 |
|
| 149 |
\newcommand{\radioon}{\radio{\fill circle (.45);}} |
| 150 |
\newcommand{\radiooff}{\radio\relax} |
| 151 |
\newcommand{\radio}[1]{\tikz[x=1ex,y=1ex,baseline=-.6ex,very thin]{\draw circle (.75);#1}} |
| 152 |
|
| 153 |
|
| 154 |
\newcommand{\filename}{\emph} |
| 155 |
|
| 156 |
% links are added in description-links.tex |
| 157 |
\newcommand\cmd[1]{\texttt{\string#1}} |
| 158 |
\newcommand\env[1]{\texttt{#1}} |
| 159 |
\newcommand\optn[1]{\texttt{#1}} |
| 160 |
\newcommand\meta[1]{\ensuremath{\langle}\textit{#1}\ensuremath{\rangle}} |
| 161 |
\newcommand\pkg[1]{\textsf{#1}} |
| 162 |
\newcommand\tikzlibrary[1]{\textsf{#1}} |
| 163 |
|
| 164 |
\newcommand{\pkgoptn}{\optn} |
| 165 |
\newcommand{\key}{\optn} |
| 166 |
\let\pkgoptn=\optn |
| 167 |
\let\key=\optn |
| 168 |
\let\handler=\optn |
| 169 |
% Do *not* add the optional argument, otherwise \renewcommand would not only redefine \optn |
| 170 |
% but also two internal macros which \pkgoptn and \key depend on. |
| 171 |
\renewcommand{\optn}[1]{\PackageError{macros}{\string\optn\space is ambiguous}{Please use \string\key\space for macro/environment options and \string\pkgoptn\space for package/class options.}} |
| 172 |
|
| 173 |
\newcommand{\val}[1]{#1} |
| 174 |
|
| 175 |
\makeatletter |
| 176 |
\newcommand\MacroFont{% |
| 177 |
% copied from dtxdescribe.sty |
| 178 |
\fontencoding\encodingdefault |
| 179 |
\fontfamily\ttdefault |
| 180 |
\fontseries\mddefault |
| 181 |
\fontshape\updefault |
| 182 |
\small |
| 183 |
} |
| 184 |
\DeclareDocumentCommand{\MarginParForDescribe}{om}{% |
| 185 |
\leavevmode |
| 186 |
\marginpar{% |
| 187 |
\raggedleft |
| 188 |
\makebox[0pt][r]{% |
| 189 |
\strut |
| 190 |
\IfValueT{#1}{{\scriptsize\sffamily#1}\quad}% |
| 191 |
\MacroFont |
| 192 |
#2% |
| 193 |
}% |
| 194 |
}% |
| 195 |
} |
| 196 |
% link target and \ignorespaces are added in description-links.tex |
| 197 |
\NewDocumentCommand{\DescribeMacro}{m}{\MarginParForDescribe{\string#1}} |
| 198 |
\NewDocumentCommand{\DescribeEnv}{m}{\MarginParForDescribe[Env]{#1}} |
| 199 |
\NewDocumentCommand{\DescribeKey}{m}{\MarginParForDescribe[Key]{#1}} |
| 200 |
\NewDocumentCommand{\DescribeHandler}{m}{\MarginParForDescribe[Handler]{#1}} |
| 201 |
% \valdoc (defined in description-links.tex) is used for values to keys |
| 202 |
% \pkgoptndoc (defined in description-links.tex) is used for package options |
| 203 |
|
| 204 |
\newcommand{\errormessage}{% |
| 205 |
\begingroup |
| 206 |
\let\do=\@makeother |
| 207 |
\dospecials |
| 208 |
\@makeother` |
| 209 |
\catcode`{=1 |
| 210 |
\catcode`}=2 |
| 211 |
\catcode` =10 |
| 212 |
\do@errormessage |
| 213 |
} |
| 214 |
\newcommand{\do@errormessage}[1]{% |
| 215 |
\endgroup |
| 216 |
\enquote{\texttt{#1}}% |
| 217 |
} |
| 218 |
\makeatother |
| 219 |
|
| 220 |
|
| 221 |
\newrobustcmd{\sectionname}[1]{{\let\formatcode\formatcodeinsection\emph{#1}}} |
| 222 |
|
| 223 |
|
| 224 |
\makeatletter |
| 225 |
\newcommand{\license@csname}[1]{license@cs@#1} |
| 226 |
\newcommand{\FormatLicense}{\emph} |
| 227 |
|
| 228 |
\newcommand{\newlicense}[2]{% |
| 229 |
\begingroup |
| 230 |
\let\do=\@makeother |
| 231 |
\dospecials |
| 232 |
\catcode`{=1 |
| 233 |
\catcode`}=2 |
| 234 |
\newlicense@do{#1}{#2}% |
| 235 |
} |
| 236 |
\newcommand{\newlicense@do}[3]{% #1: name, #2: display text, #3: url |
| 237 |
\endgroup |
| 238 |
\expandafter \newcommand \csname\license@csname{#1}\endcsname{\href{#3}{\FormatLicense{#2}}}% |
| 239 |
} |
| 240 |
|
| 241 |
\newcommand{\license}[1]{% #1: name |
| 242 |
\ifcsname\license@csname{#1}\endcsname |
| 243 |
\csname\license@csname{#1}\endcsname |
| 244 |
\else |
| 245 |
\PackageError{macros}{license name `#1' undefined}{}% |
| 246 |
\fi |
| 247 |
} |
| 248 |
|
| 249 |
|
| 250 |
\newcommand\notocspace{\addtocontents{toc}{\vspace*{-.8em}}} |
| 251 |
|
| 252 |
|
| 253 |
\newcommand\UnderscoreSubscript{_} |
| 254 |
\ExplSyntaxOn |
| 255 |
\NewDocumentCommand\formatlabel{m}{% |
| 256 |
\group_begin: |
| 257 |
\def\l_format_label_name_tl{#1} |
| 258 |
\exp_args:NNo \tl_replace_all:Nnn \l_format_label_name_tl {\UnderscoreSubscript}{\textunderscore} |
| 259 |
\texttt{\l_format_label_name_tl} |
| 260 |
\group_end: |
| 261 |
} |
| 262 |
\ExplSyntaxOff |
| 263 |
\let\formatcaption=\formatlabel |
| 264 |
|
| 265 |
|
| 266 |
% ---------- \formatcode --------- |
| 267 |
|
| 268 |
\newcommand{\formatcode}[1]{{\ttfamily\smaller[.5]\fboxsep=.5pt\colorbox{codebackground!50}{\vphantom\}\colorlet{linkcolor}{codelinkcolor}#1}}} |
| 269 |
\newcommand{\formatchar}[1]{\formatcode{\char`#1}} |
| 270 |
\newcommand{\formatcodeinsection}[1]{{\ttfamily#1}} |
| 271 |
\newcommand{\formatcodeinmarginpar}[1]{\formatcodeinsection{\small#1}} |
| 272 |
|
| 273 |
% patch section commands and toc to use \formatcodeinsection instead of \formatcode |
| 274 |
\newcommand{\patchsection}[3]{% #1: command to be patched, #2: code to be inserted before, #3 code to be appended |
| 275 |
\expandafter\let\csname @@originalsec@\string#1\endcsname #1% |
| 276 |
\expandafter\def\csname @@sec@\string#1\endcsname##1##2{#2\csname @@originalsec@\string#1\endcsname##1{##2}#3}% |
| 277 |
\def#1##1##{\csname @@sec@\string#1\endcsname{##1}}% |
| 278 |
} |
| 279 |
\@tfor \@sec@cmd :=\section\subsection\subsubsection \do{% |
| 280 |
\expandafter\expandafter\expandafter\patchsection\expandafter\@sec@cmd\expandafter{% |
| 281 |
\csname My\expandafter\string\@sec@cmd Hook\endcsname |
| 282 |
\let\@original@formatcode=\formatcode |
| 283 |
\let\formatcode=\formatcodeinsection |
| 284 |
}{% |
| 285 |
\let\formatcode=\@original@formatcode |
| 286 |
}% |
| 287 |
} |
| 288 |
\let\@@original@toc=\tableofcontents |
| 289 |
\def\tableofcontents{{\let\formatcode\formatcodeinsection\DisableLinks\@@original@toc}} |
| 290 |
|
| 291 |
% patch \marginpar to use \formatcodeinmarginpar instead of \formatcode |
| 292 |
\let\@@original@marginpar=\marginpar |
| 293 |
\renewcommand\marginpar[1]{\@@original@marginpar{\let\formatcode=\formatcodeinmarginpar#1}} |
| 294 |
|
| 295 |
|
| 296 |
\makeatother |