# Tag Info

## Hot answers tagged expansion

5

If I understand correctly, you want to use the relative positions of the saved nodes in your new picture. That is, each node should refer to a position in the new picture relative to the new origin. Here's some code that saves all the data for a list of specified nodes which can then be restored at a later time in the document. It uses LaTeX3 stuff ...

4

Define \UnitLabel with an argument: \documentclass{article} \usepackage{lipsum} \usepackage{xparse} \newcounter{Unit} \NewDocumentCommand{\UnitLabel}{m}{% \makebox[4.5em][l]{Unit #1}% } \NewDocumentCommand{\Unit}{ m }{% \refstepcounter{Unit}% \section*{\UnitLabel{\Roman{Unit}}#1} \addcontentsline{toc}{section}{\UnitLabel{\Roman{Unit}}#1}% } ...

3

Use \DeclareExpandableDocumentCommand -- this does not allow an optional argument at the end of the argument list, but this is no issue here! The \NewDocumentCommand version isn't expandable, see e.g. \show\UnitLabel: \UnitLabel=\protected macro: ->\makebox [4.5em][l]{Unit \Roman {Unit}}. l.25 \show\UnitLabel i.e. \UnitLabel is protected. The xparse ...

3

You can use expl3; the \strcompare macro is just a user level version of the expandable internal function \str_if_eq:nnTF. \documentclass{article} \usepackage{expl3} \ExplSyntaxOn \cs_new_eq:NN \strcompare \str_if_eq:nnTF \ExplSyntaxOff \begin{document} start\par \strcompare{abc}{def}{OOPS}{OK}\par \strcompare{abc}{abcd}{OOPS}{OK}\par ...

2

I am unclear on the detailed behavior desired, but... Is this what is desired? \documentclass{article} \usepackage{xpatch} \newcommand\app[1]{\textbf{#1}} % <- #1 is appended's macro's parameter \def\addtoapp#1{% \apptocmd{\app}{#1}{}{} % <- passing appended macro's parameter to appended macro again } \begin{document} \app{Food App} \addtoapp{This ...

1

\apptocmd doesn't like to be in the argument to another command when # is involved. You can do it with a conditional: \documentclass{article} \usepackage{etoolbox} \newcommand\app[1]{\textbf{#1}} \newif\ifdebugmode \debugmodetrue % comment for not applying the patches \ifdebugmode \newwrite\appfile ...

1

Another approach is to create a stack that contains the nodes for a macros. Each call to a macro create en new level in the stack, and the level is deleted at the end of the macro. One can preserve the nodes one chooses by picking them, and only ones that are useful for the future. Nodes are named with the pattern a-i-j where j is the level (automatically ...

1

I've read that with \usepackage{pdftexcmds}, you can use \pdf@strcmp but haven't checked if it works in this case. Alternatively, the code below defines \expandable@if@equal{str1}{str2}{if-case}{else-case}, which can be used as follows: \makeatletter start% \expandable@if@equal{abc}{def}{OOPS}{OK}% \expandable@if@equal{abc}{abcd}{OOPS}{OK}% ...

Only top voted, non community-wiki answers of a minimum length are eligible