| 1 |
In {\tt pdfToolbox-utils.tex}, \pdftoolbox{} provides various useful utilities for a variety of (relatively) simple tasks. |
| 2 |
|
| 3 |
\subsection{Simple Macros} |
| 4 |
|
| 5 |
\macroexp{\_checkloaded {<name>}} |
| 6 |
Place this at the beginning of a package or a file in a package to ensure you don't include the same file multiple times. |
| 7 |
It will check if {\it name} has already been loaded: if it has been, it stops input; otherwise it remembers that {\it name} has been loaded and continues inputting it. |
| 8 |
\emacroexp |
| 9 |
|
| 10 |
A few useful short macros: |
| 11 |
\blist |
| 12 |
\item \macro\_xp: shorthand for \macro\expandafter; |
| 13 |
\item \macro\_nul: defined to be \macro\_nul; useful as a marker (used, for example, to mark the end of something); |
| 14 |
\item \macro\_id: defined as \inlinecode|\def\_id#1{#1}|; |
| 15 |
\item \macro\_gobble: gobbles the next parameter; |
| 16 |
\item \macro\_gobbletilnul: gobbles until it sees \macro\_nul{} (definition is \inlinecode|\def\_gobbletilnul#1\_nul{}|); |
| 17 |
\item \macro\_mstrip: given a control sequence, returns its name without the escape character; |
| 18 |
\item \macro\True: defined to be \macro\True; used when returning a value; |
| 19 |
\item \macro\False: defined to be \macro\False; used when returning a value; |
| 20 |
\item \macro\glet: \inlinecode|\global\let|; |
| 21 |
\item \macro\_xplet: takes two inputs {\tt A} and {\tt B}, suppose they expand to {\tt X} and {\tt Y} respectively. |
| 22 |
Then \inlinecode|\_xplet{A}{B}| is equivalent to \inlinecode|\let XY|; |
| 23 |
\item \macro\_afterfi: within an \inlinecode|\if...\fi| construct, placing code inside \macro\_afterfi{} will execute it (if the condition matches) after the \macro\fi; |
| 24 |
\item \macro\say{}: prints the input on the terminal (on its own line). |
| 25 |
\elist |
| 26 |
|
| 27 |
\macroexp{\_ifnextchar <char>{<first>}{<second>} |
| 28 |
\@ifnextchar <char>{<first>}{<second>}} |
| 29 |
Inspired by \LaTeX. |
| 30 |
Looks at the following character, if it is equal to {\it char}, executes {\it first} and otherwise executes {\it second}. |
| 31 |
The following character is left in the input stream. |
| 32 |
\emacroexp |
| 33 |
|
| 34 |
\macroexp{\_ifstar {<first>}{<second>} |
| 35 |
\@ifstar {<first>}{<second>}} |
| 36 |
Inspired by \LaTeX. |
| 37 |
Looks at the following character, if it is an asterisk, executes {\it first} and otherwise executes {\it second}. |
| 38 |
The asterisk is removed from the stream. |
| 39 |
\emacroexp |
| 40 |
|
| 41 |
\macroexp{\_nopt {<dim expression>}} |
| 42 |
Expands to the computation of {\it dim expression} (a dimension expression) without the trailing {\tt pt}. |
| 43 |
\emacroexp |
| 44 |
|
| 45 |
\macroexp{\_noptfloor {<dim expression>}} |
| 46 |
Expands to the whole part of the computation of {\it dim expression} (a dimension expression) without the trailing {\tt pt}. |
| 47 |
\emacroexp |
| 48 |
|
| 49 |
\macroexp{\literal <macro definition>} |
| 50 |
Equivalent to \inlinecode|\def\X<macro definition>\X|. |
| 51 |
\emacroexp |
| 52 |
|
| 53 |
\macroexp{\_getline <macro>} |
| 54 |
Reads until a linebreak and then passes that to {\it macro} as its parameter. |
| 55 |
\emacroexp |
| 56 |
|
| 57 |
\macroexp{\reverse <macro>{<list>}} |
| 58 |
Reverses {\it list} and puts the result in {\it macro}. |
| 59 |
\emacroexp |
| 60 |
|
| 61 |
\subsection{Setters} |
| 62 |
|
| 63 |
\pdftoolbox{} has a concept of {\it setters}: these are the macros used for defining things. |
| 64 |
There are four three: \inlinecode|\currlet, \currdef, \curredef, \currset|\anchormacro\currdef. |
| 65 |
These generally alternate between \inlinecode|\let, \def, \edef, \empty| and \inlinecode|\glet, \gdef, \xdef, \global|. |
| 66 |
You can change the definitions via the two macros \macro\localsetters\anchormacro\localsetters{} and \macro\globalsetters\anchormacro\globalsetters. |
| 67 |
|
| 68 |
So for example, if you'd like to use an array and make the changes global, you'd first execute \macro\globalsetters. |
| 69 |
|
| 70 |
\subsection{Repeating Macros} |
| 71 |
|
| 72 |
\macroexp{\commap <macro>{<list>}} |
| 73 |
If {\it list} is a comma-separated list of the form {\tt x1,\dots,xN} and {\it macro} is \macro\X, this will execute \inlinecode|\X{x1}...\X{xN}|. |
| 74 |
\emacroexp |
| 75 |
|
| 76 |
\macroexp{\map <macro>{<list>}} |
| 77 |
If {\it list} is a list of the form \inlinecode|x1\dots xN| where each {\tt xI} is a group or a single token, and {\it macro} is \macro\X, this will execute \inlinecode|\X{x1}...\X{xN}|. |
| 78 |
\emacroexp |
| 79 |
|
| 80 |
\macroexp{\_repeat {<times>}{<code>}} |
| 81 |
Executes {\it code} {\it times} times. |
| 82 |
\emacroexp |
| 83 |
|
| 84 |
\macroexp{\_prepeat {<times>}<macro>} |
| 85 |
If {\it times} is {\tt N} and {\it macro} \macro\X, executes \inlinecode|\X{1}...\X{N}|. |
| 86 |
\emacroexp |
| 87 |
|
| 88 |
\macroexp{\_varrepeat {<start>}{<stop>}{<step>}<comparison><macro>} |
| 89 |
If {\it macro} is \macro\X, {\it start} is {\tt i}, step is {\tt d}, and stop is {\tt f}: executes \inlinecode|\X{i}\X{i+d}\X{i+2d}...\X{i+Nd}| until the condition (\inlinecode|i+Nd /it comparison /tt f|) is satisfied. |
| 90 |
\emacroexp |
| 91 |
|