| 1 |
% \iffalse meta-comment |
| 2 |
% !TeX spellcheck = en-US |
| 3 |
% |
| 4 |
% File: templatetools.sty |
| 5 |
% Version: 2023/03/26 v0.1 |
| 6 |
% Author: Matthias Pospiech |
| 7 |
% Email: <[email protected]> |
| 8 |
% |
| 9 |
% Copyright (C) 2023 by Matthias Pospiech <[email protected]> |
| 10 |
% --------------------------------------------------------------------------- |
| 11 |
% This work may be distributed and/or modified under the |
| 12 |
% conditions of the LaTeX Project Public License, either version 1.3 |
| 13 |
% of this license or (at your option) any later version. |
| 14 |
% The latest version of this license is in |
| 15 |
% http://www.latex-project.org/lppl.txt |
| 16 |
% and version 1.3 or later is part of all distributions of LaTeX |
| 17 |
% version 2005/12/01 or later. |
| 18 |
% |
| 19 |
% This work has the LPPL maintenance status `maintained'. |
| 20 |
% |
| 21 |
% The Current Maintainer of this work is Matthias Pospiech. |
| 22 |
% |
| 23 |
% This work consists of the files templatetools.dtx and templatetools.ins |
| 24 |
% and the derived filebase templatetools.sty. |
| 25 |
% |
| 26 |
% \fi |
| 27 |
% |
| 28 |
% \iffalse |
| 29 |
%<*driver> |
| 30 |
\ProvidesFile{templatetools.dtx} |
| 31 |
%</driver> |
| 32 |
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01] |
| 33 |
%<package>\ProvidesPackage{templatetools} |
| 34 |
%<*package> |
| 35 |
[2023/03/26 v0.2 Collection of conditional commands useful inside templates] |
| 36 |
%</package> |
| 37 |
% |
| 38 |
%<*driver> |
| 39 |
\documentclass{ltxdoc} |
| 40 |
\usepackage{hypdoc} |
| 41 |
\RequirePackage[% |
| 42 |
loadHyperref=true, |
| 43 |
createIndexEntries=false, |
| 44 |
applyLayout=true] |
| 45 |
{doctools} % |
| 46 |
% |
| 47 |
\usepackage{lmodern} |
| 48 |
|
| 49 |
\usepackage{templatetools}[2023/03/26] |
| 50 |
|
| 51 |
\EnableCrossrefs % (default) Every new macro name used within a macrocode or |
| 52 |
% macrocode∗ environment will produce an index entry. |
| 53 |
% \DisableCrossrefs % turn off this feature |
| 54 |
% |
| 55 |
% If an index is created is determined by the use of the following |
| 56 |
% declarations in the driver file preamble; if neither is used, no index is |
| 57 |
% produced. |
| 58 |
\PageIndex % all index entries refer to their page number |
| 59 |
% \CodelineIndex % index entries produced by \DescribeMacro and \DescribeEnv |
| 60 |
% refer to page number but those produced by the macro |
| 61 |
% environment refer to the code lines, |
| 62 |
% which will be numbered automatically. |
| 63 |
% \CodelineNumbered % no index is created, but the code lines are numbered |
| 64 |
|
| 65 |
\RecordChanges |
| 66 |
|
| 67 |
|
| 68 |
\begin{document} |
| 69 |
\DocInput{templatetools.dtx} |
| 70 |
\PrintChanges |
| 71 |
\PrintIndex |
| 72 |
\end{document} |
| 73 |
%</driver> |
| 74 |
% \fi |
| 75 |
% |
| 76 |
% \CheckSum{0} |
| 77 |
% |
| 78 |
% \CharacterTable |
| 79 |
% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z |
| 80 |
% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z |
| 81 |
% Digits \0\1\2\3\4\5\6\7\8\9 |
| 82 |
% Exclamation \! Double quote \" Hash (number) \# |
| 83 |
% Dollar \$ Percent \% Ampersand \& |
| 84 |
% Acute accent \' Left paren \( Right paren \) |
| 85 |
% Asterisk \* Plus \+ Comma \, |
| 86 |
% Minus \- Point \. Solidus \/ |
| 87 |
% Colon \: Semicolon \; Less than \< |
| 88 |
% Equals \= Greater than \> Question mark \? |
| 89 |
% Commercial at \@ Left bracket \[ Backslash \\ |
| 90 |
% Right bracket \] Circumflex \^ Underscore \_ |
| 91 |
% Grave accent \` Left brace \{ Vertical bar \| |
| 92 |
% Right brace \} Tilde \~} |
| 93 |
% |
| 94 |
% |
| 95 |
% \changes{v0.1}{2017-10-12}{Converted to DTX file} |
| 96 |
% \changes{v0.2}{2023/03/26}{Added checking of bib environments} |
| 97 |
% |
| 98 |
% \DoNotIndex{\newcommand,\newenvironment} |
| 99 |
% |
| 100 |
% \providecommand*{\url}{\texttt} |
| 101 |
% \GetFileInfo{templatetools.dtx} |
| 102 |
% \title{The \textsf{templatetools} package} |
| 103 |
% \author{Matthias Pospiech \\ \url{[email protected]}} |
| 104 |
% \date{\fileversion~from \filedate} |
| 105 |
% |
| 106 |
% \maketitle |
| 107 |
% \begin{abstract}\noindent |
| 108 |
% Collection of tools, which are helpful for the creation of a \LaTeX{} |
| 109 |
% template if conditional paths for code execution are required. |
| 110 |
% \end{abstract} |
| 111 |
% |
| 112 |
% \section{Usage} |
| 113 |
% |
| 114 |
% \subsection{Commands} |
| 115 |
% The following commands check if a command sequence is defined or not. |
| 116 |
% |
| 117 |
% \DescribeMacro{\IfDefined} \marg{command}\marg{code defined} \AfterLastParam |
| 118 |
% Executes the code if the command is defined. |
| 119 |
% |
| 120 |
% |
| 121 |
% \DescribeMacro{\IfUndefined} \marg{command}\marg{code undefined} |
| 122 |
% \AfterLastParam |
| 123 |
% Executes the code if the command is not defined. |
| 124 |
% |
| 125 |
% \DescribeMacro{\IfElseDefined} \marg{command}\marg{defined}\marg{undefined} |
| 126 |
% \AfterLastParam |
| 127 |
% Executes either the code in the \emph{defined} bracket if the command is |
| 128 |
% defined or in the \emph{undefined} bracket if the code is undefined. |
| 129 |
% |
| 130 |
% \DescribeMacro{\IfElseUndefined} \marg{command}\marg{undefined}\marg{defined} |
| 131 |
% \AfterLastParam |
| 132 |
% As \cs{IfElseDefined}, but with switched brackets for defined and undefined. |
| 133 |
% |
| 134 |
% |
| 135 |
% \subsubsection{Example} |
| 136 |
% The \cs{usepackage} code is only executed if the required \cs{upmu} command |
| 137 |
% is defined. |
| 138 |
% \iffalse |
| 139 |
%<*example> |
| 140 |
% \fi |
| 141 |
\begin{lstlisting}[style=lstDemoStyleLaTeXCode] |
| 142 |
% Requires: Command \upmu |
| 143 |
\IfDefined{upmu}{\usepackage[upmu]{gensymb}} |
| 144 |
\end{lstlisting} |
| 145 |
% \iffalse |
| 146 |
%</example> |
| 147 |
% \fi |
| 148 |
% |
| 149 |
% |
| 150 |
% \DescribeMacro{\IfMultDefined} |
| 151 |
% \marg{list of commands}\marg{defined}\marg{undefined} \AfterLastParam |
| 152 |
% Checks a comma separated list of commands before it executes the defined |
| 153 |
% code path if all commands were defined or the undefined code path else. |
| 154 |
% |
| 155 |
% \subsubsection{Example} |
| 156 |
% \iffalse |
| 157 |
%<*example> |
| 158 |
% \fi |
| 159 |
\begin{lstlisting}[style=lstDemoStyleLaTeXCode] |
| 160 |
% Requires: Command longtable and rowcolors |
| 161 |
\IfMultDefined{longtable,rowcolors} |
| 162 |
{... longtable with rowcolors ...} |
| 163 |
{Error: Neither longtable nor rowcolors are defined} |
| 164 |
\end{lstlisting} |
| 165 |
% \iffalse |
| 166 |
%</example> |
| 167 |
% \fi |
| 168 |
% |
| 169 |
% \subsection{Draft mode} |
| 170 |
% |
| 171 |
% The following commands check if draft mode is active or not. |
| 172 |
% |
| 173 |
% \DescribeMacro{\IfDraft}\marg{draft mode active} |
| 174 |
% \AfterLastParam |
| 175 |
% |
| 176 |
% \DescribeMacro{\IfNotDraft}\marg{draft mode disabled} |
| 177 |
% \AfterLastParam |
| 178 |
% |
| 179 |
% \DescribeMacro{\IfNotDraftElse}\marg{draft mode disabled}\marg{draft mode active} |
| 180 |
% \AfterLastParam |
| 181 |
% |
| 182 |
% \subsubsection{Example} |
| 183 |
% The \package{bookmark} is not loaded in draft mode: |
| 184 |
% \iffalse |
| 185 |
%<*example> |
| 186 |
% \fi |
| 187 |
\begin{lstlisting}[style=lstDemoStyleLaTeXCode] |
| 188 |
\IfNotDraft{\usepackage[]{bookmark}} |
| 189 |
\end{lstlisting} |
| 190 |
% \iffalse |
| 191 |
%</example> |
| 192 |
% \fi |
| 193 |
% |
| 194 |
% |
| 195 |
% \subsection{Packages} |
| 196 |
% |
| 197 |
% These commands check if a package was loaded or not. |
| 198 |
% This can be achieved in different ways with commands from other packages. |
| 199 |
% The key point of these commands here is that they work not only in |
| 200 |
% the preamble and include no @-char. |
| 201 |
% |
| 202 |
% \DescribeMacro{\IfPackageLoaded}\marg{package}\marg{is loaded} |
| 203 |
% \AfterLastParam |
| 204 |
% |
| 205 |
% \DescribeMacro{\IfPackageNotLoaded}\marg{package}\marg{is not loaded} |
| 206 |
% \AfterLastParam |
| 207 |
% |
| 208 |
% \DescribeMacro{\IfPackagesLoaded}\marg{list of packages}\marg{all are loaded} |
| 209 |
% \AfterLastParam |
| 210 |
% |
| 211 |
% \DescribeMacro{\IfPackagesNotLoaded}\marg{list of packages}\marg{none is loaded} |
| 212 |
% \AfterLastParam |
| 213 |
% |
| 214 |
% \subsubsection{Example} |
| 215 |
% |
| 216 |
% \iffalse |
| 217 |
%<*example> |
| 218 |
% \fi |
| 219 |
\begin{lstlisting}[style=lstDemoStyleLaTeXCode] |
| 220 |
% Load epstopdf only if graphicx was loaded |
| 221 |
\IfPackageLoaded{graphicx}{% |
| 222 |
\usepackage{epstopdf} |
| 223 |
} |
| 224 |
% Do not load subcaption if subfig was loaded (incompatible) |
| 225 |
\IfPackageNotLoaded{subfig}{ |
| 226 |
\usepackage{subcaption}[2011/08/17] |
| 227 |
} |
| 228 |
\end{lstlisting} |
| 229 |
% \iffalse |
| 230 |
%</example> |
| 231 |
% \fi |
| 232 |
% |
| 233 |
% |
| 234 |
% \subsection{Package Loading order} |
| 235 |
% In \latex{} documents it is quite often essential |
| 236 |
% to load packages in the right order to ensure that everything works. |
| 237 |
% However this makes it impossible to group similar packages together. |
| 238 |
% |
| 239 |
% The following commands allow to execute code after or before a |
| 240 |
% specified package and thus also allows to load packages in a specified order |
| 241 |
% using \cs{usepackage} commands. |
| 242 |
% |
| 243 |
% If the reference package was not loaded in the preamble |
| 244 |
% the code will nevertheless be executed before \texttt{\cs{begin}\{document\}} |
| 245 |
% |
| 246 |
% |
| 247 |
% \DescribeMacro{\ExecuteAfterPackage} |
| 248 |
% \marg{after this package}\marg{execute this code}\AfterLastParam |
| 249 |
% |
| 250 |
% \DescribeMacro{\ExecuteBeforePackage} |
| 251 |
% \marg{before this package}\marg{execute this code}\AfterLastParam |
| 252 |
% |
| 253 |
% \subsubsection{Example} |
| 254 |
% \package{cleveref} package must be loaded after package \package{hyperref}. |
| 255 |
% |
| 256 |
% \iffalse |
| 257 |
%<*example> |
| 258 |
% \fi |
| 259 |
\begin{lstlisting}[style=lstDemoStyleLaTeXCode] |
| 260 |
% loading: must be loaded after hyperref and after varioref |
| 261 |
\ExecuteAfterPackage{hyperref}{ |
| 262 |
% caption and cleveref incompatible in Versions before 2011/12/24 |
| 263 |
\usepackage{cleveref}[2011/12/24] |
| 264 |
} |
| 265 |
\end{lstlisting} |
| 266 |
% \iffalse |
| 267 |
%</example> |
| 268 |
% \fi |
| 269 |
% |
| 270 |
% \subsection{Tikz Library} |
| 271 |
% Checks if a tikz library was loaded. |
| 272 |
% |
| 273 |
% \DescribeMacro{\IfTikzLibraryLoaded}\marg{library}\marg{if loaded} |
| 274 |
% |
| 275 |
% |
| 276 |
% \subsubsection{Example} |
| 277 |
% Executes the code only of the tikz library was loaded. |
| 278 |
% |
| 279 |
% \iffalse |
| 280 |
%<*example> |
| 281 |
% \fi |
| 282 |
\begin{lstlisting}[style=lstDemoStyleLaTeXCode] |
| 283 |
\IfTikzLibraryLoaded{lindenmayersystems}{% |
| 284 |
% code origin: pgf/tikz manual |
| 285 |
\begin{tikzpicture} |
| 286 |
\pgfdeclarelindenmayersystem{Koch curve}{ |
| 287 |
\rule{F -> F-F++F-F} |
| 288 |
} |
| 289 |
\shadedraw [top color=white, bottom color=blue!50, draw=blue!50!black] |
| 290 |
[l-system={Koch curve, step=2pt, angle=60, axiom=F++F++F, order=3}] |
| 291 |
lindenmayer system -- cycle; |
| 292 |
\end{tikzpicture} |
| 293 |
}% |
| 294 |
\end{lstlisting} |
| 295 |
% \iffalse |
| 296 |
%</example> |
| 297 |
% \fi |
| 298 |
% |
| 299 |
% \subsection{Column types} |
| 300 |
% |
| 301 |
% \LaTeX{} provides no tool to check for the existence of a column type. |
| 302 |
% This is provided by the following commands: |
| 303 |
% |
| 304 |
% \DescribeMacro{\IfColumntypeDefined}\marg{columntype character}\marg{is |
| 305 |
% defined}\marg{is undefined} \AfterLastParam |
| 306 |
% |
| 307 |
% ^^A which is also available as a command checking a comma separated list for |
| 308 |
% ^^A column type characters |
| 309 |
% |
| 310 |
% \DescribeMacro{\IfColumntypesDefined} |
| 311 |
% \marg{columntype character list}\marg{is defined}\marg{is undefined} |
| 312 |
% \AfterLastParam |
| 313 |
% |
| 314 |
% \subsubsection{Example} |
| 315 |
% Executes the code only of the X column type is defined and the tabularx package was |
| 316 |
% loaded by checking that \cs{tabularx} is defined. |
| 317 |
% |
| 318 |
% \iffalse |
| 319 |
%<*example> |
| 320 |
% \fi |
| 321 |
\begin{lstlisting}[style=lstDemoStyleLaTeXCode] |
| 322 |
\IfColumntypeDefined{X}{% |
| 323 |
\IfDefined{tabularx}{% |
| 324 |
% |
| 325 |
\begin{tabularx}{0.9\textwidth}{llXX} |
| 326 |
\hline |
| 327 |
l & l & X & X \\\hline |
| 328 |
% |
| 329 |
left column & left column & |
| 330 |
text which is considerably longer than the width of the column & |
| 331 |
text which is considerably longer than the width of the column \\ |
| 332 |
\hline |
| 333 |
\end{tabularx} |
| 334 |
% |
| 335 |
}}% |
| 336 |
\end{lstlisting} |
| 337 |
% \iffalse |
| 338 |
%</example> |
| 339 |
% \fi |
| 340 |
|
| 341 |
% \subsection{Color definitions} |
| 342 |
% |
| 343 |
% Color definitions are saved in \latex{} as names. The following commands |
| 344 |
% provide a convenient way to check the existence of these color definitions. |
| 345 |
% |
| 346 |
% \DescribeMacro{\IfColorDefined} |
| 347 |
% \marg{color name}\marg{is defined}\marg{is undefined} \AfterLastParam |
| 348 |
% |
| 349 |
% |
| 350 |
% \DescribeMacro{\IfColorsDefined} |
| 351 |
% \marg{list of color name}\marg{is defined}\marg{is undefined} \AfterLastParam |
| 352 |
% |
| 353 |
% \subsection{Math font version} |
| 354 |
% \DescribeMacro{\IfMathVersionDefined} |
| 355 |
% \marg{font version}\marg{is defined}\marg{is undefined} \AfterLastParam |
| 356 |
% |
| 357 |
% |
| 358 |
% \subsection{Glossaries styles} |
| 359 |
% \DescribeMacro{\IfGlossariesStyleDefined} |
| 360 |
% \marg{style name}\marg{is defined} \AfterLastParam |
| 361 |
% |
| 362 |
% \subsection{Bib environments} |
| 363 |
% \DescribeMacro{\IfBibEnvironmentDefined} |
| 364 |
% \marg{environment name}\marg{is defined} \AfterLastParam |
| 365 |
% |
| 366 |
% \subsection{Template Definitions} |
| 367 |
% The following commands in principle define only macros, but in contrast to |
| 368 |
% normal methods these are saved using two keys named \emph{group} |
| 369 |
% and \emph{property}. With a matching command for the execution this |
| 370 |
% allows to generate macros in an object like naming structure, which |
| 371 |
% can be used to toggle settings. |
| 372 |
% |
| 373 |
% \DescribeMacro{\SetTemplateDefinition} \marg{Group}\marg{Property}\marg{Code} |
| 374 |
% \AfterLastParam |
| 375 |
% Defines a collection of commands (a macro) with a \emph{group} and |
| 376 |
% \emph{property}. |
| 377 |
% |
| 378 |
% \DescribeMacro{\UseDefinition} \marg{Group}\marg{Property} \AfterLastParam |
| 379 |
% Execute macro save with the \emph{group} and \emph{property}. |
| 380 |
% |
| 381 |
% \subsubsection{Example} |
| 382 |
% The following code allows to switch the colors anywhere in the document: |
| 383 |
% |
| 384 |
% \iffalse |
| 385 |
%<*example> |
| 386 |
% \fi |
| 387 |
\begin{lstlisting}[style=lstDemoStyleLaTeXCode] |
| 388 |
\SetTemplateDefinition{Target}{Web}{% |
| 389 |
\definecolor{pdfurlcolor}{rgb}{0,0,0.6} |
| 390 |
}% |
| 391 |
\SetTemplateDefinition{Target}{Print}{% |
| 392 |
\definecolor{pdfurlcolor}{rgb}{0,0,0} |
| 393 |
}% |
| 394 |
% Apply colors for web |
| 395 |
\UseDefinition{Target}{Web} |
| 396 |
\end{lstlisting} |
| 397 |
% \iffalse |
| 398 |
%</example> |
| 399 |
% \fi |
| 400 |
% |
| 401 |
% \StopEventually{} |
| 402 |
% \clearpage |
| 403 |
% \section{Implementation} |
| 404 |
% |
| 405 |
% \iffalse |
| 406 |
%<*templatetools.sty> |
| 407 |
% \fi |
| 408 |
% |
| 409 |
% |
| 410 |
% \begin{macrocode} |
| 411 |
\NeedsTeXFormat{LaTeX2e}[1994/12/01] |
| 412 |
\ProvidesPackage{templatetools} |
| 413 |
[2023/03/26 v0.2 Collection of conditional commands useful inside templates] |
| 414 |
% \end{macrocode} |
| 415 |
% \begin{macrocode} |
| 416 |
%%% --- Necessary Packages |
| 417 |
%%% ------------------------------------------------------------------ |
| 418 |
\RequirePackage{iftex} |
| 419 |
\RequirePackage{etoolbox} |
| 420 |
\RequirePackage{ltxcmds} |
| 421 |
\RequirePackage{array} % for column types |
| 422 |
\RequirePackage{ifdraft} % check draft |
| 423 |
\RequirePackage{scrlfile} |
| 424 |
% \end{macrocode} |
| 425 |
% |
| 426 |
% \subsection{Command sequences} |
| 427 |
% |
| 428 |
% \iffalse |
| 429 |
%%% --- Check if command is defined |
| 430 |
%%% ------------------------------------------------------------------ |
| 431 |
% \fi |
| 432 |
% |
| 433 |
% |
| 434 |
% \begin{macro}{\IfDefined} |
| 435 |
% Wrapper to \cs{ifcsdef} with only true path. |
| 436 |
% \begin{macrocode} |
| 437 |
\newcommand{\IfDefined}[2]{\ifcsdef{#1}{#2}{}}% |
| 438 |
% \end{macrocode} |
| 439 |
% \end{macro} |
| 440 |
% |
| 441 |
% |
| 442 |
% \begin{macro}{\IfUndefined} |
| 443 |
% Wrapper to \cs{ifcsdef} with only false path. |
| 444 |
% \begin{macrocode} |
| 445 |
\newcommand{\IfUndefined}[2]{\ifcsdef{#1}{}{#2}}% |
| 446 |
% \end{macrocode} |
| 447 |
% \end{macro} |
| 448 |
% |
| 449 |
% |
| 450 |
% \begin{macro}{\IfElseDefined} |
| 451 |
% Wrapper to \cs{ifcsdef} with true and false path. |
| 452 |
% \begin{macrocode} |
| 453 |
\newcommand{\IfElseDefined}[3]{\ifcsdef{#1}{#2}{#3}}% |
| 454 |
% \end{macrocode} |
| 455 |
% \end{macro} |
| 456 |
% |
| 457 |
% |
| 458 |
% \begin{macro}{\IfElseUndefined} |
| 459 |
% Wrapper to \cs{ifcsdef} with true and false path in reverse order. |
| 460 |
% \begin{macrocode} |
| 461 |
\newcommand{\IfElseUndefined}[3]{\ifcsdef{#1}{#3}{#2}}% |
| 462 |
% \end{macrocode} |
| 463 |
% \end{macro} |
| 464 |
% |
| 465 |
% |
| 466 |
% \begin{macro}{\IfMultDefined} |
| 467 |
% Checks if more than one command is defined |
| 468 |
% \begin{macrocode} |
| 469 |
\newcommand{\IfMultDefined}[1]{% |
| 470 |
\@tempswatrue |
| 471 |
\def\do##1{% |
| 472 |
%% define \@tempa with trimmed index element. |
| 473 |
\edef\@tempa{\zap@space##1 \@empty}% |
| 474 |
%% check if package of current index is loaded |
| 475 |
\ifcsdef{\@tempa}{}{\@tempswafalse}% |
| 476 |
}% |
| 477 |
%% Process csv list with command \do (etoolbox) |
| 478 |
\docsvlist{#1}% |
| 479 |
%% makes sure that the conditional works with one or two (if, else) parameters. |
| 480 |
\if@tempswa\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi% |
| 481 |
} |
| 482 |
% \end{macrocode} |
| 483 |
% \end{macro} |
| 484 |
% |
| 485 |
% Thanks to \person{egreg,Andrey Vihrov, Martin Scharrer} on |
| 486 |
%\href{http://tex.stackexchange.com/questions/35282/how-to-implement-a-command-that-checks-for-loaded-packages}{tex.stackexchange.com} |
| 487 |
% for the help to implement a command that checks a comma separated list. |
| 488 |
% |
| 489 |
% \subsection{Draft mode} |
| 490 |
% |
| 491 |
% \iffalse |
| 492 |
% ------------------------------------------------------------------ |
| 493 |
% Check for 'draft' mode - commands. |
| 494 |
% ------------------------------------------------------------------ |
| 495 |
% \fi |
| 496 |
% |
| 497 |
% |
| 498 |
% \begin{macro}{\IfDraft} |
| 499 |
% Tests if \cs{@draft} is undefined and executed false path in case draft string |
| 500 |
% is defined. |
| 501 |
% \begin{macrocode} |
| 502 |
\newcommand{\IfDraft}[1]{\ifx\@draft\@undefined \else #1 \fi} |
| 503 |
% \end{macrocode} |
| 504 |
% \end{macro} |
| 505 |
|
| 506 |
% |
| 507 |
% \begin{macro}{\IfNotDraft} |
| 508 |
% Similar to \cs{IfDraft} but executes only path for draft mode undefined. |
| 509 |
% \begin{macrocode} |
| 510 |
\newcommand{\IfNotDraft}[1]{\ifx\@draft\@undefined #1 \fi} |
| 511 |
% \end{macrocode} |
| 512 |
% \end{macro} |
| 513 |
% |
| 514 |
% |
| 515 |
% \begin{macro}{\IfNotDraftElse} |
| 516 |
% Similar to \cs{IfDraft} but executes true and fals path. |
| 517 |
% \begin{macrocode} |
| 518 |
\newcommand{\IfNotDraftElse}[2]{\ifx\@draft\@undefined #1 \else #2 \fi} |
| 519 |
% \end{macrocode} |
| 520 |
% \end{macro} |
| 521 |
% |
| 522 |
% |
| 523 |
% |
| 524 |
% \subsection{Packages} |
| 525 |
% |
| 526 |
% \iffalse |
| 527 |
% ------------------------------------------------------------------ |
| 528 |
% Check load status of packages |
| 529 |
% ------------------------------------------------------------------ |
| 530 |
% \fi |
| 531 |
% |
| 532 |
% If a package is loaded can be checked in many ways, but here the |
| 533 |
% \cs{ltx@ifpackageloaded} is used because it can be executed anywhere |
| 534 |
% in the document. |
| 535 |
% |
| 536 |
% \begin{macro}{\IfPackageLoaded} |
| 537 |
% Wrapper to \cs{ltx@ifpackageloaded} with only true path. |
| 538 |
% \begin{macrocode} |
| 539 |
\newcommand{\IfPackageLoaded}[2]{\ltx@ifpackageloaded{#1}{#2}{}} |
| 540 |
% \end{macrocode} |
| 541 |
% \end{macro} |
| 542 |
% |
| 543 |
% |
| 544 |
% \begin{macro}{\IfPackageNotLoaded} |
| 545 |
% Wrapper to \cs{ltx@ifpackageloaded} with only false path. |
| 546 |
% \begin{macrocode} |
| 547 |
\newcommand{\IfPackageNotLoaded}[2]{\ltx@ifpackageloaded{#1}{}{#2}} |
| 548 |
% \end{macrocode} |
| 549 |
% \end{macro} |
| 550 |
% |
| 551 |
% \begin{macro}{\IfElsePackageLoaded} |
| 552 |
% Wrapper to \cs{ltx@ifpackageloaded} |
| 553 |
% \begin{macrocode} |
| 554 |
\let\IfElsePackageLoaded\ltx@ifpackageloaded |
| 555 |
% \end{macrocode} |
| 556 |
% \end{macro} |
| 557 |
% |
| 558 |
% \begin{macro}{\IfPackagesLoaded} |
| 559 |
% Checks a list of packages |
| 560 |
% \begin{macrocode} |
| 561 |
\newcommand{\IfPackagesLoaded}[1]{% |
| 562 |
\@tempswatrue |
| 563 |
\def\do##1{% |
| 564 |
\edef\@tempa{\zap@space##1 \@empty}% |
| 565 |
\ltx@ifpackageloaded{\@tempa}{}{\@tempswafalse}% |
| 566 |
}% |
| 567 |
\docsvlist{#1}% |
| 568 |
\if@tempswa\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi% |
| 569 |
} |
| 570 |
% \end{macrocode} |
| 571 |
% \end{macro} |
| 572 |
% |
| 573 |
% |
| 574 |
% \begin{macro}{\IfPackagesNotLoaded} |
| 575 |
% Invers check if all packages in a list are not loaded |
| 576 |
% \begin{macrocode} |
| 577 |
\newcommand{\IfPackagesNotLoaded}[1]{% |
| 578 |
\@tempswatrue |
| 579 |
\def\do##1{% |
| 580 |
\edef\@tempa{\zap@space##1 \@empty}% |
| 581 |
\ltx@ifpackageloaded{\@tempa}{\@tempswafalse}{}% |
| 582 |
}% |
| 583 |
\docsvlist{#1}% |
| 584 |
\if@tempswa\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi% |
| 585 |
} |
| 586 |
% \end{macrocode} |
| 587 |
% \end{macro} |
| 588 |
% |
| 589 |
% |
| 590 |
% \begin{macro}{\ExecuteAfterPackage} |
| 591 |
% Executes the code after the reference package has been loaded (using |
| 592 |
% \cs{AfterAtEndOfPackage}) or finally at the end of the preamble |
| 593 |
% if the reference package was not loaded until then. |
| 594 |
% |
| 595 |
% \begin{macrocode} |
| 596 |
\newcommand{\ExecuteAfterPackage}[2]{% |
| 597 |
%% #1: after this package |
| 598 |
%% #2: code to execute |
| 599 |
\AfterAtEndOfPackage{#1}{ |
| 600 |
#2% |
| 601 |
} |
| 602 |
\AtEndPreamble{% |
| 603 |
\IfPackageNotLoaded{#1}{% |
| 604 |
#2% |
| 605 |
} |
| 606 |
} |
| 607 |
} |
| 608 |
% \end{macrocode} |
| 609 |
% \end{macro} |
| 610 |
% |
| 611 |
% |
| 612 |
% \begin{macro}{\ExecuteBeforePackage} |
| 613 |
% Executes the code directly before the reference package is loaded (using |
| 614 |
% \cs{BeforePackage}) or finally at the end of the preamble |
| 615 |
% if the reference package was not loaded until then. |
| 616 |
% |
| 617 |
% \begin{macrocode} |
| 618 |
\newcommand{\ExecuteBeforePackage}[2]{% |
| 619 |
%% #1: before this package |
| 620 |
%% #2: code to execute |
| 621 |
\BeforePackage{#1}{ |
| 622 |
#2% |
| 623 |
} |
| 624 |
\AtEndPreamble{% |
| 625 |
\IfPackageNotLoaded{#1}{% |
| 626 |
#2% |
| 627 |
} |
| 628 |
} |
| 629 |
} |
| 630 |
% \end{macrocode} |
| 631 |
% \end{macro} |
| 632 |
% |
| 633 |
% \subsection{Tikz library} |
| 634 |
% |
| 635 |
% \iffalse |
| 636 |
% ------------------------------------------------------------------ |
| 637 |
% The command sequence that is created for each tikz library when it is loaded is |
| 638 |
% used to check if it is loaded. |
| 639 |
% \fi |
| 640 |
% |
| 641 |
% |
| 642 |
% \begin{macro}{\IfTikzLibraryLoaded} |
| 643 |
% Checks if the tikz library is loaded |
| 644 |
% \begin{macrocode} |
| 645 |
\def\IfTikzLibraryLoaded#1{% |
| 646 |
\ifcsname tikz@library@#1@loaded\endcsname |
| 647 |
\expandafter\@firstoftwo |
| 648 |
\else |
| 649 |
\expandafter\@secondoftwo |
| 650 |
\fi |
| 651 |
} |
| 652 |
% \end{macrocode} |
| 653 |
% \end{macro} |
| 654 |
% |
| 655 |
% Thanks to \person{egreg} and \person{Marco Daniel} on \href{http://tex.stackexchange.com/questions/48453/how-to-test-if-tikz-library-is-loaded}{tex.stackexchange.com} for their help with this command. |
| 656 |
% |
| 657 |
% \subsection{Column types in tables} |
| 658 |
% |
| 659 |
% \iffalse |
| 660 |
% ------------------------------------------------------------------ |
| 661 |
% table columns |
| 662 |
% ------------------------------------------------------------------ |
| 663 |
% \fi |
| 664 |
% |
| 665 |
% The code in this section was inspired by the discussion with \person{egreg} on \href{http://tex.stackexchange.com/questions/35527/how-to-check-if-a-column-type-is-defined}{tex.stackexchange.com} on the detection of column definitions. |
| 666 |
% |
| 667 |
% Creates a list of predefined columntypes |
| 668 |
% \begin{macrocode} |
| 669 |
\expandafter\let\csname columntype@l\endcsname\@empty |
| 670 |
\expandafter\let\csname columntype@c\endcsname\@empty |
| 671 |
\expandafter\let\csname columntype@r\endcsname\@empty |
| 672 |
\expandafter\let\csname columntype@p\endcsname\@empty |
| 673 |
\expandafter\let\csname columntype@m\endcsname\@empty |
| 674 |
\expandafter\let\csname columntype@b\endcsname\@empty |
| 675 |
\expandafter\let\csname columntype@@\endcsname\@empty |
| 676 |
\expandafter\let\csname columntype@!\endcsname\@empty |
| 677 |
\expandafter\let\csname columntype@|\endcsname\@empty |
| 678 |
\expandafter\let\csname columntype@<\endcsname\@empty |
| 679 |
\expandafter\let\csname columntype@>\endcsname\@empty |
| 680 |
\expandafter\let\csname columntype@=\endcsname\@empty |
| 681 |
% \end{macrocode} |
| 682 |
% |
| 683 |
% \begin{macro}{\CheckIfColumntypeDefined} |
| 684 |
% Creates a bool variable that saves the status of the column type. |
| 685 |
% \begin{macrocode} |
| 686 |
\newcommand\CheckIfColumntypeDefined[1]{% |
| 687 |
%% create the bool variable for column type |
| 688 |
\providebool{tpl@coltype@#1} |
| 689 |
%% check if new column type of this name was created |
| 690 |
\ifcsdef{NC@find@\string#1}% |
| 691 |
{\setbool{tpl@coltype@#1}{true}}% |
| 692 |
%% if not check if it is a predefined column type |
| 693 |
{\ifcsdef{columntype@\string#1} |
| 694 |
{\setbool{tpl@coltype@#1}{true}}% |
| 695 |
{\setbool{tpl@coltype@#1}{false}}% |
| 696 |
}% |
| 697 |
} |
| 698 |
% \end{macrocode} |
| 699 |
% \end{macro} |
| 700 |
% |
| 701 |
% |
| 702 |
% \begin{macro}{\isColumntypeDefined} |
| 703 |
% Returns the bool variable which can be interpreted by \cs{ifboolexpr}. |
| 704 |
% This should only be used internally and fails for nonexistent bool variables. |
| 705 |
% \begin{macrocode} |
| 706 |
\newcommand\isColumntypeDefined[1]{tpl@coltype@#1} |
| 707 |
% \end{macrocode} |
| 708 |
% \end{macro} |
| 709 |
% |
| 710 |
% |
| 711 |
% \begin{macro}{\IfColumntypeDefined} |
| 712 |
% Executes \cs{CheckIfColumntypeDefined} and uses the resulting bool |
| 713 |
% variable with \cs{isColumntypeDefined} in a conditional sequence with |
| 714 |
% \cs{ifboolexpr}. |
| 715 |
% \begin{macrocode} |
| 716 |
\newcommand\IfColumntypeDefined[3]{% |
| 717 |
%% Execute check which create bool variable |
| 718 |
\CheckIfColumntypeDefined{#1} |
| 719 |
%% use bool variable for if sequence |
| 720 |
\ifboolexpr{ bool{\isColumntypeDefined{#1}} }{#2}{#3}% |
| 721 |
} |
| 722 |
% \end{macrocode} |
| 723 |
% \end{macro} |
| 724 |
% |
| 725 |
% |
| 726 |
% \begin{macro}{\IfColumntypesDefined} |
| 727 |
% Checks a comma separated list instead of a single string. |
| 728 |
% \begin{macrocode} |
| 729 |
\newcommand{\IfColumntypesDefined}[1]{% |
| 730 |
\@tempswatrue |
| 731 |
\def\do##1{% |
| 732 |
\edef\@tempa{\zap@space##1 \@empty}% |
| 733 |
%% check if column is defined. |
| 734 |
%% Here with \expandafter because of the \string definition |
| 735 |
%% in \CheckIfColumntypeDefined. |
| 736 |
\expandafter\IfColumntypeDefined |
| 737 |
\expandafter{\@tempa}{}{\@tempswafalse} |
| 738 |
}% |
| 739 |
\docsvlist{#1}% |
| 740 |
\if@tempswa\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi% |
| 741 |
} |
| 742 |
% \end{macrocode} |
| 743 |
% \end{macro} |
| 744 |
% |
| 745 |
% |
| 746 |
% \subsection{Color definitions} |
| 747 |
% |
| 748 |
% \iffalse |
| 749 |
% ------------------------------------------------------------------ |
| 750 |
% test color definitions |
| 751 |
% ------------------------------------------------------------------ |
| 752 |
% \fi |
| 753 |
% |
| 754 |
% |
| 755 |
% \begin{macro}{\IfColorDefined} |
| 756 |
% Tests if a color is defined |
| 757 |
% \begin{macrocode} |
| 758 |
\newcommand{\IfColorDefined}[3]{% |
| 759 |
\ifcsdef{\string\color @#1} |
| 760 |
{#2} % color string is defined |
| 761 |
{#3}} % color string is not defined |
| 762 |
% \end{macrocode} |
| 763 |
% \end{macro} |
| 764 |
% |
| 765 |
% |
| 766 |
% \begin{macro}{\IfColorsDefined} |
| 767 |
% Does the same for a list (comma separated) of color names. |
| 768 |
% \begin{macrocode} |
| 769 |
\newcommand{\IfColorsDefined}[1]{% |
| 770 |
\@tempswatrue |
| 771 |
\def\do##1{% |
| 772 |
\edef\@tempa{\zap@space##1 \@empty}% |
| 773 |
\expandafter\IfColorDefined |
| 774 |
\expandafter{\@tempa}{}{\@tempswafalse} |
| 775 |
}% |
| 776 |
\docsvlist{#1}% |
| 777 |
\if@tempswa\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi% |
| 778 |
} |
| 779 |
% \end{macrocode} |
| 780 |
% \end{macro} |
| 781 |
% |
| 782 |
% \subsection{Math font version} |
| 783 |
% |
| 784 |
% \iffalse |
| 785 |
% ------------------------------------------------------------------ |
| 786 |
% test math versions |
| 787 |
% ------------------------------------------------------------------ |
| 788 |
% \fi |
| 789 |
% |
| 790 |
% \begin{macro}{\IfMathVersionDefined} |
| 791 |
% Checks if a mathversion font is defined. |
| 792 |
% \begin{macrocode} |
| 793 |
\newcommand{\IfMathVersionDefined}[3]{\ifcsdef{mv@#1}{#2}{#3}} |
| 794 |
% \end{macrocode} |
| 795 |
% \end{macro} |
| 796 |
% |
| 797 |
% Thanks to \person{Werner} and \person{Ulrike Fischer} for pointing me to this |
| 798 |
% name definition on |
| 799 |
% \href{http://tex.stackexchange.com/questions/40903/check-if-mathversion-font-is-defined}{tex.stackexchange.com}. |
| 800 |
% |
| 801 |
% |
| 802 |
% \subsection{Glossaries styles} |
| 803 |
% |
| 804 |
% \iffalse |
| 805 |
% ------------------------------------------------------------------ |
| 806 |
% tests the existens of glossaries styles |
| 807 |
% ------------------------------------------------------------------ |
| 808 |
% \fi |
| 809 |
% |
| 810 |
% \begin{macro}{\IfGlossariesStyleDefined} |
| 811 |
% Checks if a glossaries style is defined. |
| 812 |
% \begin{macrocode} |
| 813 |
\newcommand{\IfGlossariesStyleDefined}[2]{\ifcsdef{@glsstyle@#1}{#2}{}} |
| 814 |
% \end{macrocode} |
| 815 |
% \end{macro} |
| 816 |
% |
| 817 |
% Thanks to \person{cgnieder} on |
| 818 |
%\href{http://tex.stackexchange.com/questions/95639/test-if-a-listings-or-glossaries-style-is-valid}{tex.stackexchange.com} |
| 819 |
% for the help to implement the command. |
| 820 |
% |
| 821 |
% \subsection{BibLaTeX Enivronemnts} |
| 822 |
% |
| 823 |
% \iffalse |
| 824 |
% ------------------------------------------------------------------ |
| 825 |
% tests the existens of a bib environment |
| 826 |
% ------------------------------------------------------------------ |
| 827 |
% \fi |
| 828 |
% |
| 829 |
% \begin{macro}{\IfBibEnvironmentDefined} |
| 830 |
% Checks if a bib environment is defined. |
| 831 |
% \begin{macrocode} |
| 832 |
\newcommand{\IfBibEnvironmentDefined}[1]{\ifcsdef{blx@env@#1}} |
| 833 |
% \end{macrocode} |
| 834 |
% \end{macro} |
| 835 |
% |
| 836 |
% Thanks to \person{egreg} on \href{https://tex.stackexchange.com/questions/451911/check-if-a-bib-environment-is-defined}{tex.stackexchange.com} for the help to implement the command. |
| 837 |
% |
| 838 |
% \subsection{Template definitions} |
| 839 |
% |
| 840 |
% \iffalse |
| 841 |
% ------------------------------------------------------------------ |
| 842 |
% template definitions |
| 843 |
% ------------------------------------------------------------------ |
| 844 |
% \fi |
| 845 |
% |
| 846 |
% |
| 847 |
% \begin{macro}{\SetTemplateDefinition} |
| 848 |
% Defines a macro with the \emph{group} and \emph{property} parameter names. |
| 849 |
% \begin{macrocode} |
| 850 |
\newcommand\SetTemplateDefinition[3]{% 1: group, 2: property, 3: code |
| 851 |
\csdef{tpl@definition@#1@#2}{#3} |
| 852 |
} |
| 853 |
% \end{macrocode} |
| 854 |
% \end{macro} |
| 855 |
% |
| 856 |
% |
| 857 |
% \begin{macro}{\UseDefinition} |
| 858 |
% Executes the macro using \cs{csuse} if it is defined. Otherwise a warning is |
| 859 |
% thrown. |
| 860 |
% \begin{macrocode} |
| 861 |
\newcommand\UseDefinition[2]{% |
| 862 |
\ifcsdef{tpl@definition@#1@#2} |
| 863 |
{\csuse{tpl@definition@#1@#2}} |
| 864 |
{\PackageWarning{templatetools}% |
| 865 |
{Definition #1->#2 is unknown\MessageBreak}{}}% |
| 866 |
}% |
| 867 |
% \end{macrocode} |
| 868 |
% \end{macro} |
| 869 |
% |
| 870 |
% |
| 871 |
% \iffalse |
| 872 |
%</templatetools.sty> |
| 873 |
% \fi |
| 874 |
% |
| 875 |
% \Finale |
| 876 |
\endinput |
| 877 |
|