| 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 |
\usepackage{etoolbox} |
| 10 |
\usepackage{pgfkeys} |
| 11 |
|
| 12 |
% Defines a macro to document a macro or environment key: |
| 13 |
% \keydoc{<keyname> = <allowedvalues>}{<keytype>} |
| 14 |
% \keydoc[<options>]{<keyname> = <allowedvalues>}{<keytype>} |
| 15 |
% Following text is assumed to be a description of the key. |
| 16 |
% If it is instead followed by another \keydoc it is assumed |
| 17 |
% that this key has no description. |
| 18 |
% If a description applies to two keys separate the \keydocs |
| 19 |
% by a slash. |
| 20 |
% Do *not* put an empty line between a \keydoc and it's description. |
| 21 |
% Spaces after (the second argument of) \keydoc are ignored. |
| 22 |
% <options> is a comma separated list of the following possible key=value pairs: |
| 23 |
% - target = the full key to another key. |
| 24 |
% The name of this key is made into a link to target. |
| 25 |
% This is used by \forwardingkeydoc. |
| 26 |
% - initial value |
| 27 |
% - default value |
| 28 |
% Values are separated by pipes. |
| 29 |
% Wildcards are put in angular brackets. |
| 30 |
% |
| 31 |
% The description of a \keydoc is assumed to reach up to the |
| 32 |
% next \keydoc, \section, \subsection or \subsubsection. |
| 33 |
% If that is not the case you must explicitly end it with |
| 34 |
% \endkeydoc |
| 35 |
% If the description of a \keydoc is ended by a \*section macro |
| 36 |
% there must be a \par (aka an empty line) before that \*section. |
| 37 |
% Otherwise \keydoc@descriptionsep will be inserted. |
| 38 |
% |
| 39 |
% There is a special macro for forwarding keys: |
| 40 |
% \forwardingkeydoc[<options>]{<keyname>} |
| 41 |
% In contrast to \keydoc, the target option can be a path, name or full key. |
| 42 |
% If target is not given it is tried to generate it by expanding |
| 43 |
% \TargetKey{<keypath>}{<keyname>} |
| 44 |
% This macro is given the path (without trailing slash) and name |
| 45 |
% of the key to be described and is expected to expand to a full key. |
| 46 |
% You must define it yourself if you want to leave out the optional argument. |
| 47 |
% |
| 48 |
% \forwardingkeydoc uses internally a more generalized macro: |
| 49 |
% \correspondingkeydoc[<options>]{<keyname>}{<keytype>} |
| 50 |
% target is as flexible as for \forwardingkeydoc |
| 51 |
% but it also takes a <keytype> like \keydoc. |
| 52 |
% |
| 53 |
% Examples for a key pattern can be specified with |
| 54 |
% \keylinktarget{<keyexample>} |
| 55 |
% It must be specified directly following the \keydoc it refers to. |
| 56 |
% |
| 57 |
% \key is redefined to link to \keydoc. |
| 58 |
% However, different environments can have different keys |
| 59 |
% with the same name. In that case a path must be set to |
| 60 |
% distinguish these keys: |
| 61 |
% \keydocpath{<path>} |
| 62 |
% Sets the path for all following \keydoc in the same group. |
| 63 |
% Unambiguous keys can be referenced without a path: |
| 64 |
% \key{sub} |
| 65 |
% For ambiguous keys the path must given as an optional argument: |
| 66 |
% \key[/object]{label} |
| 67 |
% Paths may *not* include a trailing slash. |
| 68 |
% |
| 69 |
% Internals: |
| 70 |
% \begin@keydoc is put before the first \keydoc. |
| 71 |
% \endkeydoc is put after the last description of a \keydoc. |
| 72 |
% \keydoc@beforekey is put before each \keydoc but only once |
| 73 |
% for \keydocs which belong together. |
| 74 |
% \keydoc@keysep is put between \keydocs which belong together. |
| 75 |
% \keydoc@descriptionsep is put between a \keydoc and it's description. |
| 76 |
% If a \keydoc is followed by a \par neither \keydoc@keysep |
| 77 |
% nor \keydoc@descriptionsep is inserted. |
| 78 |
|
| 79 |
|
| 80 |
\makeatletter |
| 81 |
|
| 82 |
% ---------- \keydoc settings --------- |
| 83 |
|
| 84 |
\newcommand{\begin@keydoc}{\begin{itemize}} |
| 85 |
\def \endkeydoc {\end{itemize}} |
| 86 |
|
| 87 |
\newcommand{\keydoc@beforekey}{\item} |
| 88 |
\newcommand{\keydoc@keysep}{~/ } |
| 89 |
\newcommand{\keydoc@descriptionsep}{\nopagebreak\par} |
| 90 |
|
| 91 |
\newcommand{\keydoc@mandatoryvalueformat}[1]{#1} |
| 92 |
\newcommand{\keydoc@optionalvalueformat}{\textcolor{gray}} |
| 93 |
|
| 94 |
\newcommand{\keydoc@keytype}[1]{\,\ensuremath{^{\pgfmanualcslinkpreskip=.33em\pgfmanualcslinkpostskip=\pgfmanualcslinkpreskip\LinkUnformattedKeyword{keytype}{#1}{\keytypesymbol{#1}}}}} |
| 95 |
\newcommand{\keytypedoc@keytype}[1]{\raisebox{.2ex}{\bfseries\keytypesymbol{#1}}} |
| 96 |
|
| 97 |
% ---------- key type symbols --------- |
| 98 |
|
| 99 |
\newcommand{\keytypesymbolformat}[1]{\hbox{\scriptsize(#1)}} |
| 100 |
\newcommand{\newkeytypesymbol}[2]{% #1: key type, #2: symbol |
| 101 |
\expandafter\newcommand\csname keytypesymbol@#1\endcsname{#2}% |
| 102 |
} |
| 103 |
\newcommand{\keytypesymbol}[1]{% #1: key type |
| 104 |
\@ifundefined{keytypesymbol@#1}% |
| 105 |
{\PackageError{keydoc}{undefined keytype `#1'}{}}% |
| 106 |
{\keytypesymbolformat{\csname keytypesymbol@#1\endcsname}}% |
| 107 |
} |
| 108 |
|
| 109 |
\newkeytypesymbol{storing key}{sto} |
| 110 |
\newkeytypesymbol{executed key}{exe} |
| 111 |
\newkeytypesymbol{boolean key}{bool} |
| 112 |
\newkeytypesymbol{forwarding key}{fwd} |
| 113 |
\newkeytypesymbol{handler}{hdl} |
| 114 |
\newkeytypesymbol{unknown key handler}{unk} |
| 115 |
|
| 116 |
|
| 117 |
% ---------- optional dependencies --------- |
| 118 |
|
| 119 |
\providecommand{\key}[2][]{% #1: key path/group, #2: key name |
| 120 |
\texttt{#2}% |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
% ---------- auxiliary macros --------- |
| 125 |
|
| 126 |
% \ifendsonspace{<text>}{<then>}{<else>} |
| 127 |
% Checks if the last token of <text> is a space. |
| 128 |
% If it is it expands to <then>{<text-without-last-space>}. |
| 129 |
% If it is not it expands to <else>{<text>}. |
| 130 |
% <text> may not contain \relax. |
| 131 |
\newcommand\ifendsonspace{\ifendson{ }} |
| 132 |
\newcommand\ifendson[2]{% |
| 133 |
\def\endson@check##1#1\relax.##2\relax\relax##3##4{% |
| 134 |
\if \relax\detokenize{##2}\relax |
| 135 |
\def\endson@do{##4}% |
| 136 |
\endson@stripandappto##1% |
| 137 |
\else |
| 138 |
\def\endson@do{##3{##1}}% |
| 139 |
\fi |
| 140 |
\endson@do |
| 141 |
}% |
| 142 |
\def\endson@stripandappto##1\relax.{\appto\endson@do{{##1}}}% |
| 143 |
\endson@check#2\relax.#1\relax.\relax\relax |
| 144 |
} |
| 145 |
|
| 146 |
% \newstripoptend{<cs>}{<suffix>} |
| 147 |
% Defines a new control sequence <cs> which checks if it's argument ends on <suffix>. |
| 148 |
% If the argument of <cs> ends on <suffix> it is stripped. |
| 149 |
% If the argument of <cs> does not end on <suffix> <cs> expands to the argument. |
| 150 |
% <cs> is expandable. |
| 151 |
% The number of required expansion steps depends on whether the argument ends on <suffix> or not. |
| 152 |
\newcommand\newstripoptend[2]{% #1: cs, #2: end |
| 153 |
\expandafter\def\csname\string#1@do\endcsname##1#2\relax.##2\relax\relax{% |
| 154 |
\if \relax\detokenize{##2}\relax |
| 155 |
\expandafter\@firstoftwo |
| 156 |
\else |
| 157 |
\expandafter\@secondoftwo |
| 158 |
\fi |
| 159 |
{\csname\string#1@strip\endcsname##1}% |
| 160 |
{##1}% |
| 161 |
}% |
| 162 |
\expandafter\def\csname\string#1@strip\endcsname##1\relax.{##1}% |
| 163 |
\newcommand#1[1]{\csname\string#1@do\endcsname##1\relax.#2\relax.\relax\relax}% |
| 164 |
} |
| 165 |
\newstripoptend\stripoptplus{ (+)} |
| 166 |
|
| 167 |
|
| 168 |
% ---------- \FormatKey --------- |
| 169 |
|
| 170 |
\newcommand{\FormatKey}[1]{% |
| 171 |
\def\FormatKeyText{}% |
| 172 |
\FormatKey@lookahead#1\pgfeov |
| 173 |
\let\FormatKey@original=\FormatKey |
| 174 |
\let\FormatKey=\@firstofone |
| 175 |
\KeyFormat@original@key{\FormatKeyText}% |
| 176 |
\let\FormatKey=\FormatKey@original |
| 177 |
} |
| 178 |
\newcommand{\FormatKey@lookahead}{% |
| 179 |
\futurelet \FormatKey@nexttoken \FormatKey@check |
| 180 |
} |
| 181 |
\newcommand{\FormatKey@check}{% |
| 182 |
\ifx \FormatKey@nexttoken (% |
| 183 |
\def\FormatKey@do{\FormatKey@optional}% |
| 184 |
\else\ifx \FormatKey@nexttoken <% |
| 185 |
\def\FormatKey@do{\FormatKey@var}% |
| 186 |
\else\ifcat \noexpand\FormatKey@nexttoken \space |
| 187 |
\def\FormatKey@do{\FormatKey@space}% |
| 188 |
\else\ifx \FormatKey@nexttoken \pgfeov |
| 189 |
\def\FormatKey@do{\FormatKey@endofloop}% |
| 190 |
\else\ifx \FormatKey@nexttoken \bgroup |
| 191 |
\def\FormatKey@do{\FormatKey@arg}% |
| 192 |
\else |
| 193 |
\def\FormatKey@do{\FormatKey@normaltoken}% |
| 194 |
\fi \fi \fi \fi \fi |
| 195 |
\FormatKey@do |
| 196 |
} |
| 197 |
\def\FormatKey@normaltoken#1{% |
| 198 |
\appto\FormatKeyText{#1}% |
| 199 |
\FormatKey@lookahead |
| 200 |
} |
| 201 |
\def\FormatKey@arg#1{% |
| 202 |
\let\FormatKey@text@backup=\FormatKeyText |
| 203 |
\def\FormatKeyText{}% |
| 204 |
\FormatKey@lookahead#1\pgfeov |
| 205 |
\eappto\FormatKey@text@backup{{\expandonce{\FormatKeyText}}}% |
| 206 |
\let\FormatKeyText=\FormatKey@text@backup |
| 207 |
\FormatKey@lookahead |
| 208 |
} |
| 209 |
\def\FormatKey@optional(#1){% |
| 210 |
\appto\FormatKeyText{{\normalfont\color{gray}(}}% |
| 211 |
\FormatKey@lookahead#1\pgfeov |
| 212 |
\appto\FormatKeyText{{\normalfont\color{gray})}}% |
| 213 |
\FormatKey@lookahead |
| 214 |
} |
| 215 |
\providecommand{\meta@nolink}{\meta} |
| 216 |
\def\FormatKey@var<#1>{% |
| 217 |
\appto\FormatKeyText{{\normalfont\meta@nolink{#1}}}% |
| 218 |
\FormatKey@lookahead |
| 219 |
} |
| 220 |
\@firstofone{\def\FormatKey@space} {% |
| 221 |
\appto\FormatKeyText{ }% |
| 222 |
\FormatKey@lookahead |
| 223 |
} |
| 224 |
\def\FormatKey@endofloop\pgfeov{% |
| 225 |
} |
| 226 |
|
| 227 |
\providecommand{\pgfeov}{\textcolor{red}{\textbf{eov, this should never be expanded}}} |
| 228 |
|
| 229 |
\let\KeyFormat@original@key=\key |
| 230 |
\renewcommand{\key}{\FormatKey} |
| 231 |
|
| 232 |
|
| 233 |
% ---------- format allowed values --------- |
| 234 |
|
| 235 |
\def\FormatVal@var#1{{\normalfont\meta{#1}}} |
| 236 |
\def\FormatVal@or{\unskip\,\ensuremath{|}\,\ignorespaces} |
| 237 |
|
| 238 |
\newcommand{\FormatValue}[1]{% |
| 239 |
\def\FormatValue@val{}% |
| 240 |
\expandafter\FormatValue@loop#1\pgfeov |
| 241 |
\FormatValue@val |
| 242 |
} |
| 243 |
\newcommand{\FormatValue@loop}{% |
| 244 |
\futurelet \FormatValue@nexttoken \FormatValue@check |
| 245 |
} |
| 246 |
\newcommand{\FormatValue@check}{% |
| 247 |
\ifx \FormatValue@nexttoken \pgfeov |
| 248 |
\def\FormatValue@do##1{}% |
| 249 |
\else\ifcat \noexpand\FormatValue@nexttoken \space |
| 250 |
\appto\FormatValue@val{ }% |
| 251 |
\def\FormatValue@do##1{\FormatValue@loop##1}% |
| 252 |
\else |
| 253 |
\def\FormatValue@do{\FormatValue@check@ii}% |
| 254 |
\fi \fi |
| 255 |
\FormatValue@do |
| 256 |
} |
| 257 |
\newcommand{\FormatValue@check@ii}[1]{% |
| 258 |
\if|\noexpand#1% |
| 259 |
\appto\FormatValue@val{\FormatVal@or}% |
| 260 |
\def\FormatValue@do{\FormatValue@loop}% |
| 261 |
\else\if<\noexpand#1% |
| 262 |
\def\FormatValue@do##1>{\appto\FormatValue@val{\FormatVal@var{##1}}\FormatValue@loop}% |
| 263 |
\else |
| 264 |
\appto\FormatValue@val{#1}% |
| 265 |
\def\FormatValue@do{\FormatValue@loop}% |
| 266 |
\fi \fi |
| 267 |
\FormatValue@do |
| 268 |
} |
| 269 |
|
| 270 |
|
| 271 |
% ---------- keyword --------- |
| 272 |
% This is a generalized api to link certain keywords. |
| 273 |
% Use the following macro in a description: |
| 274 |
% \NewKeyword[\unexpanded]{<keywordtype>}{<keyword>}{<formatmacro-bg>}{<formatmacro-fg>}{<text>} |
| 275 |
% Use the following macro in references: |
| 276 |
% \LinkKeyword{<keywordtype>}{<keyword>}<formatmacro-bg><formatmacro-fg>{<text>} |
| 277 |
% <keywordtype> and <keyword> are used to generate/ |
| 278 |
% link to a hyper link target. They are not visible |
| 279 |
% in the resulting document. |
| 280 |
% <formatmacro-bg/fg>: TeX code which takes one mandatory argument |
| 281 |
% and formats it as desired. Usually those passed to \NewKeyword are used |
| 282 |
% for both the description and the link. |
| 283 |
% Those passed to \LinkKeyword are used only if the link is undefined. |
| 284 |
% <formatmacro-bg> is applied before \FormatLink. |
| 285 |
% <formatmacro-fg> is applied inside of \FormatLink. |
| 286 |
% Setting a background color must happen in <formatmacro-bg> |
| 287 |
% otherwise it will cover the underline produced by \FormatLink. |
| 288 |
% Using \detokenize must happen in <formatmacro-fg> |
| 289 |
% otherwise \FormatLink will not be executed but printed to the pdf. |
| 290 |
% Changing the font can happen in either one. |
| 291 |
% <text>: TeX code to produce the displayed text. |
| 292 |
% The optional argument of \NewKeyword is a macro which |
| 293 |
% takes the <keyword> as argument and can protect it |
| 294 |
% from expansion when writing it to an auxiliary file. |
| 295 |
% If you try to link an undefined keyword you will |
| 296 |
% get a warning. |
| 297 |
% |
| 298 |
% You can define abbreviations so you do not always |
| 299 |
% need to type out the full name: |
| 300 |
% \AbbrevKeyword[\unexpanded]{<abbrevtype>}{<abbrevname>}{<fulltype>}{<fullname>} |
| 301 |
% If two abbreviations are ambiguous they will not |
| 302 |
% cause an error where they are defined but where |
| 303 |
% they are referenced so you can create abbreviations |
| 304 |
% automatically without trouble. |
| 305 |
% |
| 306 |
% In order to avoid warnings for undescribed keywords |
| 307 |
% \NoKeyword[\unexpanded]{<keywordtype>}{<keyword>}{<formatmacro-bg>}{<formatmacro-fg>} |
| 308 |
% can be used. It is used similar to \NewKeyword but |
| 309 |
% does not display any text and \LinkKeyword to this keyword |
| 310 |
% will not result in a link and will not give a warning. |
| 311 |
% The separation in <formatmacro-bg> and <formatmacro-fg> |
| 312 |
% is only for compatability with \NewKeyword. |
| 313 |
% |
| 314 |
% Links are defined in a temporary file which is loaded in the |
| 315 |
% preamble so that \LinkKeyword can be used before \NewKeyword. |
| 316 |
% I am not using the aux file for that because |
| 317 |
% (a) the aux file is loaded twice (once in \begin{document} |
| 318 |
% and once in \end{document}) and |
| 319 |
% (b) the aux file is loaded in a group so all definitions need |
| 320 |
% to be global but \newcommand can't do that and \gdef does not |
| 321 |
% check if a macro is already defined. |
| 322 |
|
| 323 |
|
| 324 |
% https://github.com/pgf-tikz/pgf/blob/master/tex/latex/pgf/doc/pgfmanual-en-macros.tex |
| 325 |
\colorlet{linkcolor}{black!8} |
| 326 |
\newdimen\pgfmanualcslinkpreskip |
| 327 |
\newdimen\pgfmanualcslinkpostskip |
| 328 |
\ifunderlinelinks |
| 329 |
\newcommand{\FormatLink}[1]{% |
| 330 |
\begingroup |
| 331 |
\setbox0=\hbox{#1}% |
| 332 |
\rlap{{% |
| 333 |
\keyword@original@color{linkcolor}% |
| 334 |
\dimen0\wd0 |
| 335 |
\advance\dimen0by-\pgfmanualcslinkpreskip |
| 336 |
\advance\dimen0by-\pgfmanualcslinkpostskip |
| 337 |
\hskip\pgfmanualcslinkpreskip |
| 338 |
\vrule width\dimen0 height-1pt depth1.6pt |
| 339 |
}}% |
| 340 |
\box0% |
| 341 |
\endgroup |
| 342 |
} |
| 343 |
\else |
| 344 |
\newcommand{\FormatLink}[1]{#1} |
| 345 |
\fi |
| 346 |
|
| 347 |
|
| 348 |
% is used in the first run when the keyword is not yet defined |
| 349 |
% or if an abbreviation is ambiguous |
| 350 |
\newcommand{\keyword@placeholder}[1]{% |
| 351 |
{\keyword@original@color{yellow}% |
| 352 |
#1% |
| 353 |
}% |
| 354 |
} |
| 355 |
\let\keyword@original@color=\color |
| 356 |
|
| 357 |
\newcommand{\keyword@targetname}[2]{% #1: keyword type, #2: name |
| 358 |
keyword:#1:#2% |
| 359 |
} |
| 360 |
\newcommand{\keyword@csname}[2]{% #1: keyword type, #2: name |
| 361 |
keyword@#1@#2% |
| 362 |
} |
| 363 |
\newcommand{\keyword@link}[3]{% #1: keyword type, #2: name, #3: text |
| 364 |
\hyperlink{\keyword@targetname{#1}{#2}}{#3}% |
| 365 |
} |
| 366 |
\newcommand{\DisableLinks}{% |
| 367 |
\let\keyword@link=\@thirdofthree |
| 368 |
\let\FormatLink=\@firstofone |
| 369 |
} |
| 370 |
\let\keyword@formatenable=\@firstofone |
| 371 |
\newrobustcmd{\keyword@new}[4]{% #1: keyword type, #2: name, #3: format macro bg, #4: format macro fg |
| 372 |
\expandafter\newcommand\csname\keyword@csname{#1}{#2}\endcsname[1]{\keyword@link{#1}{#2}{\keyword@formatenable{#3}{\FormatLink{\keyword@formatenable{#4}{##1}}}}}% |
| 373 |
} |
| 374 |
\newrobustcmd{\keyword@no}[4]{% #1: keyword type, #2: name, #3: format macro bg, #4: format macro fg |
| 375 |
\expandafter\newcommand\csname\keyword@csname{#1}{#2}\endcsname[1]{\keyword@formatenable{#3}{\keyword@formatenable{#4}{##1}}}% |
| 376 |
} |
| 377 |
\newrobustcmd{\keyword@abbrev}[4]{% #1: abbrev keyword type, #2: abbrev name, #3: full keyword type, #4: full name |
| 378 |
\IfKeywordUndefined{#3}{#4}{% |
| 379 |
\PackageError{keyword}{#3 `#4' (for which you wanted to add the abbreviation `#1@#2') is undefined}{}% |
| 380 |
}{\IfKeywordUndefined{#1}{#2}{% |
| 381 |
\expandafter\let \csname\keyword@csname{#1}{#2}\expandafter\endcsname \csname\keyword@csname{#3}{#4}\endcsname |
| 382 |
}{% |
| 383 |
\expandafter\def \csname\keyword@csname{#1}{#2}\endcsname ##1{\PackageWarning{keyword}{The abbreviation #1 `#2' is ambiguous. Please specify the full name for ##1}{}\keyword@placeholder{##1}}% |
| 384 |
}}% |
| 385 |
} |
| 386 |
\newcommand{\IfKeywordIsAbbrev}[4]{% key to be tested, reference key |
| 387 |
\expandafter\ifx \csname\keyword@csname{#1}{#2}\expandafter\endcsname \csname\keyword@csname{#3}{#4}\endcsname |
| 388 |
\expandafter \@firstoftwo |
| 389 |
\else |
| 390 |
\expandafter \@secondoftwo |
| 391 |
\fi |
| 392 |
} |
| 393 |
|
| 394 |
\newcommand{\LinkKeyword}[5]{% #1: keyword type, #2: name, #3: formatmacro bg, #4: formatmacro fg, #5: displayed text |
| 395 |
\IfKeywordUndefined{#1}{#2}{% |
| 396 |
\edef\do{\noexpand\PackageWarning{keydoc}{Either #1 `#2' is undefined or you need to rerun LaTeX}}% |
| 397 |
\do |
| 398 |
\keyword@placeholder{#3{#4{#5}}}% |
| 399 |
}{% |
| 400 |
\csname \keyword@csname{#1}{#2}\endcsname{#5}% |
| 401 |
}% |
| 402 |
} |
| 403 |
\newcommand{\LinkUnformattedKeyword}[3]{% #1: keyword type, #2: name, #3 displayed text |
| 404 |
\begingroup |
| 405 |
\let\keyword@formatenable=\@gobble |
| 406 |
\LinkKeyword{#1}{#2}\@firstofone\@firstofone{#3}% |
| 407 |
\endgroup |
| 408 |
} |
| 409 |
\newcommand{\IfKeywordUndefined}[2]{% #1: keyword type, #2: name, #3: then, #4: else |
| 410 |
\expandafter \ifx \csname\keyword@csname{#1}{#2}\endcsname \relax |
| 411 |
\expandafter\@firstoftwo |
| 412 |
\else |
| 413 |
\expandafter\@secondoftwo |
| 414 |
\fi |
| 415 |
} |
| 416 |
|
| 417 |
|
| 418 |
\newcommand\keyword@filename{\jobname.kw} |
| 419 |
|
| 420 |
\AtBeginDocument{% |
| 421 |
\IfFileExists{\keyword@filename}{% |
| 422 |
\makeatletter |
| 423 |
\input{\keyword@filename}% |
| 424 |
\makeatother |
| 425 |
}{} |
| 426 |
\newwrite\keyword@file |
| 427 |
\immediate\openout\keyword@file=\keyword@filename\relax |
| 428 |
} |
| 429 |
|
| 430 |
\newcommand{\NewKeyword}[6][\@firstofone]{% [#1: name protection], #2: type, #3: name, #4: format macro bg, #5: format macro fg, #6: text |
| 431 |
%https://tex.stackexchange.com/a/17138 |
| 432 |
\Hy@raisedlink{\hypertarget{\keyword@targetname{#2}{#3}}{}}% |
| 433 |
\if\relax\detokenize{#6}\relax |
| 434 |
\else |
| 435 |
#4{#5{#6}}% |
| 436 |
\fi |
| 437 |
\immediate\write\keyword@file{\keyword@new{#2}{#1{#3}}{\unexpanded{#4}}{\unexpanded{#5}}}% |
| 438 |
} |
| 439 |
\newcommand{\AbbrevKeyword}[5][\@firstofone]{% abbrev = full |
| 440 |
\immediate\write\keyword@file{\keyword@abbrev{#2}{#1{#3}} {#1{#4}}{#1{#5}}}% |
| 441 |
} |
| 442 |
\newrobustcmd{\NoKeyword}[5][\@firstofone]{% #2: keyword type, #3: name, #4: format macro bg, #5: format macro fg |
| 443 |
\immediate\write\keyword@file{\keyword@no{#2}{#1{#3}}{\unexpanded{#4}}{\unexpanded{#5}}}% |
| 444 |
} |
| 445 |
|
| 446 |
|
| 447 |
% ---------- \keydoc --------- |
| 448 |
|
| 449 |
\newif\if@inkeydoc |
| 450 |
\newif\ifkeydoc@isrelated |
| 451 |
|
| 452 |
\newcommand\keydoc@keypath{} |
| 453 |
\newcommand{\keydocpath}[1]{\def\keydoc@keypath{#1}} |
| 454 |
|
| 455 |
\pgfqkeys{/keydoc}{% |
| 456 |
target/.initial, |
| 457 |
target/.value required, |
| 458 |
% |
| 459 |
initial value/.initial, |
| 460 |
initial value/.value required, |
| 461 |
% |
| 462 |
default value/.initial, |
| 463 |
default value/.value required, |
| 464 |
} |
| 465 |
|
| 466 |
\newcommand{\keydoc@printvalues}{% |
| 467 |
\pgfkeysgetvalue{/keydoc/initial value}{\keydoc@initialvalue}% |
| 468 |
\pgfkeysgetvalue{/keydoc/default value}{\keydoc@defaultvalue}% |
| 469 |
\let\keydoc@initdefault=\@empty |
| 470 |
% |
| 471 |
\unless\ifx \keydoc@defaultvalue \pgfkeysnovalue@text |
| 472 |
\appto\keydoc@initdefault{\hyperref[initial-vs-default-values]{Default value}: \keydoc@defaultvalue.}% |
| 473 |
\fi |
| 474 |
\unless\ifx \keydoc@initialvalue \pgfkeysnovalue@text |
| 475 |
\unless\ifx \keydoc@initdefault \@empty |
| 476 |
\appto\keydoc@initdefault{ }% |
| 477 |
\fi |
| 478 |
\appto\keydoc@initdefault{\hyperref[initial-vs-default-values]{Initial value}: \keydoc@initialvalue.}% |
| 479 |
\fi |
| 480 |
\unless\ifx \keydoc@initdefault \@empty |
| 481 |
\\% |
| 482 |
{\MaxFontSize\footnotesize\keydoc@initdefault}% |
| 483 |
\fi |
| 484 |
\pgfkeyssetvalue{/keydoc/initial value}{\pgfkeysnovalue}% |
| 485 |
\pgfkeyssetvalue{/keydoc/default value}{\pgfkeysnovalue}% |
| 486 |
} |
| 487 |
\newcommand{\MaxFontSize}[1]{% |
| 488 |
#1% |
| 489 |
\def\MaxFontSize@do##1#1##2\relax{% |
| 490 |
\@tfor\MaxFontSize@fontsize:=##1\do{% |
| 491 |
\expandafter\let\MaxFontSize@fontsize=\relax |
| 492 |
}% |
| 493 |
}% |
| 494 |
\MaxFontSize@do\Huge\huge\LARGE\Large\large\normalsize\small\footnotesize\scriptsize\tiny\relax |
| 495 |
} |
| 496 |
|
| 497 |
\newcommand{\keydoc}[3][]{% [#1: options], #2: key name, #3: key type |
| 498 |
\unless \if@inkeydoc |
| 499 |
\begin@keydoc |
| 500 |
\keydoc@registerend |
| 501 |
\@inkeydoctrue |
| 502 |
\fi |
| 503 |
\pgfkeyssetvalue{/keydoc/target}{\pgfkeysnovalue}% |
| 504 |
\pgfqkeys{/keydoc}{#1}% |
| 505 |
\keydoc@parsekey#2=\relax% |
| 506 |
\def\keydoc@abbrev{% |
| 507 |
\AbbrevKeyword{key}{\keydoc@keypattern} {key}{\keydoc@keypath/\keydoc@keypattern}% |
| 508 |
\AbbrevKeyword{}{\keydoc@keypattern} {key}{\keydoc@keypath/\keydoc@keypattern}% |
| 509 |
}% |
| 510 |
\pgfkeysgetvalue{/keydoc/target}{\keydoc@targetkey}% |
| 511 |
\ifx \keydoc@targetkey \pgfkeysnovalue@text |
| 512 |
\let\keydoc@link=\@firstofone |
| 513 |
\else |
| 514 |
\def\keydoc@link{\LinkKeyword{key}{\keydoc@targetkey}\keydoc@key@bg\keydoc@original@key}% |
| 515 |
\IfKeywordUndefined{}{\keydoc@keypattern}{% |
| 516 |
% keep \keydoc@abbrev |
| 517 |
}{\IfKeywordIsAbbrev{}{\keydoc@keypattern} {key}{\keydoc@keypath/\keydoc@keypattern}{% |
| 518 |
% keep \keydoc@abbrev |
| 519 |
}{% |
| 520 |
\let\keydoc@abbrev=\relax |
| 521 |
}}% |
| 522 |
\fi |
| 523 |
\ifkeydoc@isrelated |
| 524 |
\keydoc@keysep |
| 525 |
\else |
| 526 |
\keydoc@beforekey |
| 527 |
\fi |
| 528 |
\edef\keydoc@do{% |
| 529 |
\noexpand\NewKeyword{key}{\keydoc@keypath/\keydoc@keypattern}{\noexpand\keydoc@key@bg}{\noexpand\keydoc@original@key}{\noexpand\keydoc@link{\keydoc@keypattern}% |
| 530 |
\noexpand\keydoc@valueformat{\keydoc@keyvalsep\noexpand\FormatValue\noexpand\keydoc@keyval}}% |
| 531 |
}% |
| 532 |
\keydoc@do |
| 533 |
\keydoc@abbrev |
| 534 |
\keydoc@keytype{#3}% |
| 535 |
\keydoc@isrelatedfalse |
| 536 |
\keydoc@lookahead |
| 537 |
} |
| 538 |
\def\keydoc@parsekey#1=#2\relax{% |
| 539 |
\if \relax\detokenize{#2}\relax |
| 540 |
\def\keydoc@keypattern{#1}% |
| 541 |
\def\keydoc@keyval{}% |
| 542 |
\def\keydoc@keyvalsep{}% |
| 543 |
\let\keydoc@valueformat=\@firstofone |
| 544 |
\else |
| 545 |
\expandafter\def\expandafter\keydoc@keyval\expandafter{\keydoc@stripeq#2\relax}% |
| 546 |
\expandafter\keydoc@checkifvalueisoptional\keydoc@keyval\relax |
| 547 |
\ifendsonspace{#1}{% |
| 548 |
\def\keydoc@keyvalsep{\ =}% |
| 549 |
\def\keydoc@keypattern%{#1 without space} |
| 550 |
}{% |
| 551 |
\def\keydoc@keyvalsep{=}% |
| 552 |
\def\keydoc@keypattern%{#1} |
| 553 |
}% |
| 554 |
\fi |
| 555 |
} |
| 556 |
\def\keydoc@stripeq#1=\relax{#1} |
| 557 |
\def\keydoc@checkifvalueisoptional#1#2\relax{% |
| 558 |
\pgfkeysgetvalue{/keydoc/default value}{\keydoc@defaultvalue}% |
| 559 |
\ifx?#1% |
| 560 |
\ifx \keydoc@defaultvalue \pgfkeysnovalue@text |
| 561 |
\ifx \keydoc@link \@firstofone |
| 562 |
\PackageWarning{keydoc}{keydoc with optional value but default value is not given}{}% |
| 563 |
\fi |
| 564 |
\fi |
| 565 |
\def\keydoc@keyval{#2}% |
| 566 |
\let\keydoc@valueformat=\keydoc@optionalvalueformat |
| 567 |
\else |
| 568 |
\unless\ifx \keydoc@defaultvalue \pgfkeysnovalue@text |
| 569 |
\PackageWarning{keydoc}{keydoc with default value but value is not optional}{}% |
| 570 |
\fi |
| 571 |
\let\keydoc@valueformat=\keydoc@mandatoryvalueformat |
| 572 |
\fi |
| 573 |
} |
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
\newcommand{\keydoc@lookahead}{% |
| 578 |
\futurelet \keydoc@nexttoken \keydoc@lookahead@check |
| 579 |
} |
| 580 |
\newcommand{\keydoc@lookahead@check}{% |
| 581 |
\ifcat \noexpand\keydoc@nexttoken \space |
| 582 |
\let\keydoc@lookahead@do=\keydoc@lookahead |
| 583 |
\let\keydoc@lookahead@gobble=\@firstofone |
| 584 |
\else\ifx \keydoc@nexttoken \par |
| 585 |
\let\keydoc@lookahead@do=\keydoc@afterlookahead |
| 586 |
\let\keydoc@lookahead@gobble=\@empty |
| 587 |
\else\ifx \keydoc@nexttoken /% |
| 588 |
\keydoc@isrelatedtrue |
| 589 |
\let\keydoc@lookahead@do=\keydoc@lookahead |
| 590 |
\let\keydoc@lookahead@gobble=\@gobble |
| 591 |
\else\ifx \keydoc@nexttoken \keydoc |
| 592 |
\let\keydoc@lookahead@do=\keydoc@afterlookahead |
| 593 |
\let\keydoc@lookahead@gobble=\@empty |
| 594 |
\else\ifx \keydoc@nexttoken \forwardingkeydoc |
| 595 |
\let\keydoc@lookahead@do=\keydoc@afterlookahead |
| 596 |
\let\keydoc@lookahead@gobble=\@empty |
| 597 |
\else\ifx \keydoc@nexttoken \correspondingkeydoc |
| 598 |
\let\keydoc@lookahead@do=\keydoc@afterlookahead |
| 599 |
\let\keydoc@lookahead@gobble=\@empty |
| 600 |
\else\ifx \keydoc@nexttoken \endkeydoc |
| 601 |
\let\keydoc@lookahead@do=\keydoc@afterlookahead |
| 602 |
\let\keydoc@lookahead@gobble=\@empty |
| 603 |
\else |
| 604 |
\ifkeydoc@isrelated |
| 605 |
\PackageError{keydoc}{expected another keydoc command after /}{}% |
| 606 |
\fi |
| 607 |
\keydoc@printvalues |
| 608 |
\keydoc@descriptionsep |
| 609 |
\let\keydoc@lookahead@do=\relax |
| 610 |
\let\keydoc@lookahead@gobble=\@empty |
| 611 |
\fi \fi \fi \fi \fi \fi \fi |
| 612 |
\expandafter \keydoc@lookahead@do \keydoc@lookahead@gobble |
| 613 |
} |
| 614 |
\newcommand{\keydoc@afterlookahead}{% |
| 615 |
\unless\ifkeydoc@isrelated |
| 616 |
\keydoc@printvalues |
| 617 |
\fi |
| 618 |
} |
| 619 |
\newcommand{\RegisterEnd}[1]{% |
| 620 |
\@tfor \@sec@cmd :=\section\subsection\subsubsection \do{% |
| 621 |
\expandafter\appto\csname My\expandafter\string\@sec@cmd Hook\endcsname{#1}% |
| 622 |
}% |
| 623 |
} |
| 624 |
\newcommand{\keydoc@registerend}{\RegisterEnd\endkeydoc} |
| 625 |
|
| 626 |
\newcommand{\keylinktarget}[1]{% |
| 627 |
\AbbrevKeyword{key}{\keydoc@keypath/#1} {key}{\keydoc@keypath/\keydoc@keypattern}% |
| 628 |
\AbbrevKeyword{key}{#1} {key}{\keydoc@keypath/\keydoc@keypattern}% |
| 629 |
\AbbrevKeyword{}{#1} {key}{\keydoc@keypath/\keydoc@keypattern}% |
| 630 |
\ignorespaces |
| 631 |
} |
| 632 |
|
| 633 |
\let\keydoc@original@key=\key |
| 634 |
\newcommand{\keydoc@key@bg}{\formatcode} |
| 635 |
% I cannot say \renewcommand{\key}[1][] because that would break \keydoc@original@key |
| 636 |
\renewcommand{\key}{% |
| 637 |
\@ifnextchar [ |
| 638 |
\key@withopt |
| 639 |
\key@withoutopt |
| 640 |
} |
| 641 |
\newcommand{\key@withopt}{} |
| 642 |
\def\key@withopt[#1]#2{% |
| 643 |
\ifx\relax#1\relax |
| 644 |
\LinkKeyword{key}{#2}\keydoc@key@bg\keydoc@original@key{#2}% |
| 645 |
\else |
| 646 |
\LinkKeyword{key}{#1/#2}\keydoc@key@bg\keydoc@original@key{#2}% |
| 647 |
\fi |
| 648 |
} |
| 649 |
\newcommand{\key@withoutopt}[1]{% |
| 650 |
\LinkKeyword{key}{#1}\keydoc@key@bg\keydoc@original@key{#1}% |
| 651 |
} |
| 652 |
|
| 653 |
\def\key@withopt@unformatted[#1]#2{% |
| 654 |
\ifx\relax#1\relax |
| 655 |
\LinkUnformattedKeyword{key}{#2}{#2}% |
| 656 |
\else |
| 657 |
\LinkUnformattedKeyword{key}{#1/#2}{#2}% |
| 658 |
\fi |
| 659 |
} |
| 660 |
|
| 661 |
|
| 662 |
% ---------- \forwardingkeydoc --------- |
| 663 |
|
| 664 |
\newcommand{\forwardingkeydoc}[2][]{% [#1: name, path or full key of target], #2: name |
| 665 |
\correspondingkeydoc[#1]{#2}{forwarding key}% |
| 666 |
} |
| 667 |
\newcommand{\correspondingkeydoc}[3][]{% [#1: options], #2: name, #3: key type |
| 668 |
\keydoc[#1, /utils/exec=\forwardingkeydoc@parsetarget{#2}]{#2}{#3}% |
| 669 |
} |
| 670 |
\newcommand{\forwardingkeydoc@parsetarget}[1]{% #1: this key name |
| 671 |
% parse target which may be a name, path or full key of corresponding key |
| 672 |
\pgfkeysgetvalue{/keydoc/target}{\forwardingkeydoc@targetkey}% |
| 673 |
\ifx\forwardingkeydoc@targetkey\pgfkeysnovalue@text |
| 674 |
\ifundef\TargetKey{% |
| 675 |
\PackageError{keydoc} |
| 676 |
{\string\TargetKey{<keypath>}{<keyname>} must be defined if the the optional argument of \forwardingkeydoc\space is not passed} |
| 677 |
{\string\TargetKey\space shall expand to path/name of the linked key given the path (without trailing slash) and name of the forwarding key.}% |
| 678 |
}{% |
| 679 |
\def\forwardingkeydoc@targetkey{\TargetKey{\keydoc@keypath}}% |
| 680 |
\edef\forwardingkeydoc@targetkey{\expandafter\forwardingkeydoc@targetkey\expandafter{\forwardingkeydoc@stripval#1=\relax}}% |
| 681 |
\expandafter\ifendsonspace\expandafter{\forwardingkeydoc@targetkey}% |
| 682 |
{\def\forwardingkeydoc@targetkey}% |
| 683 |
{\def\forwardingkeydoc@targetkey}% |
| 684 |
\pgfkeyslet{/keydoc/target}{\forwardingkeydoc@targetkey}% |
| 685 |
}% |
| 686 |
\else |
| 687 |
\forwardingkeydoc@parse{\forwardingkeydoc@targetkey}{\keydoc@keypath}{#1}% |
| 688 |
\pgfkeyslet{/keydoc/target}{\forwardingkeydoc@targetkey}% |
| 689 |
\fi |
| 690 |
} |
| 691 |
\newcommand\forwardingkeydoc@parse[3]{% #1: key name, key path or full key of target, #2: path of source, #3: name of source |
| 692 |
\IfStartsWithSlash{#1}{% |
| 693 |
\edef\forwardingkeydoc@targetkey@original{#1}% |
| 694 |
\edef\forwardingkeydoc@targetkey{#1/\forwardingkeydoc@stripval#3=\relax}% |
| 695 |
\expandafter\ifendsonspace\expandafter{\forwardingkeydoc@targetkey}% |
| 696 |
{\def\forwardingkeydoc@targetkey}% |
| 697 |
{\def\forwardingkeydoc@targetkey}% |
| 698 |
\IfKeywordUndefined{key}{\forwardingkeydoc@targetkey}{% |
| 699 |
\let\forwardingkeydoc@targetkey=\forwardingkeydoc@targetkey@original |
| 700 |
}{}% |
| 701 |
}{% |
| 702 |
\def\forwardingkeydoc@targetkey{#2/#1}% |
| 703 |
}% |
| 704 |
} |
| 705 |
\def\forwardingkeydoc@stripval#1=#2\relax{#1} |
| 706 |
|
| 707 |
\newcommand{\IfStartsWithSlash}[1]{% |
| 708 |
\expandafter\IfStartsWithSlash@do#1\relax |
| 709 |
} |
| 710 |
\def\IfStartsWithSlash@do#1#2\relax{% |
| 711 |
\ifx/#1% |
| 712 |
\expandafter\@firstoftwo |
| 713 |
\else |
| 714 |
\expandafter\@secondoftwo |
| 715 |
\fi |
| 716 |
} |
| 717 |
|
| 718 |
|
| 719 |
% ---------- \keytypedoc --------- |
| 720 |
|
| 721 |
\newcommand{\begin@keytypedoc}{\begin{itemize}} |
| 722 |
\def \endkeytypedoc {\end{itemize}} |
| 723 |
|
| 724 |
\newcommand{\keytypedoc@beforekeytype}{\item} |
| 725 |
\newcommand{\keytypedoc@format}[1]{\emph{#1}} |
| 726 |
\newcommand{\keytypedoc@descriptionsep}{:} |
| 727 |
|
| 728 |
\newif\if@inkeytypedoc |
| 729 |
|
| 730 |
\newcommand{\keytypeRAW}[1]{#1} |
| 731 |
\newcommand{\keytype@bg}[1]{#1} |
| 732 |
\newcommand{\keytype}{% [#1: type name], #2: displayed text (usually the type name, but can be another grammatic form) |
| 733 |
\@ifnextchar [ |
| 734 |
{\@keytype@do} |
| 735 |
{\@dblarg\@keytype@do}% |
| 736 |
} |
| 737 |
\def\@keytype@do[#1]#2{% |
| 738 |
\LinkKeyword{keytype}{#1}\keytype@bg\keytypeRAW{#2}% |
| 739 |
} |
| 740 |
|
| 741 |
\newcommand{\keytypedoc}[1]{% #1 key type name |
| 742 |
\unless \if@inkeytypedoc |
| 743 |
\begin@keytypedoc |
| 744 |
\keytypedoc@registerend |
| 745 |
\@inkeytypedoctrue |
| 746 |
\fi |
| 747 |
\keytypedoc@beforekeytype[\keytypedoc@keytype{#1}] |
| 748 |
\NewKeyword{keytype}{#1}{\keytype@bg}{\keytypeRAW}{\keytypedoc@format{#1}}% |
| 749 |
\keytypedoc@descriptionsep |
| 750 |
} |
| 751 |
|
| 752 |
\newcommand{\keytypedoc@registerend}{\RegisterEnd\endkeytypedoc} |
| 753 |
|
| 754 |
\makeatother |