I hope this question makes sense. If I wanted to modify the following code to allow the user to pass a macro as the first parameter, how would I do it?
How it is:
(using pgf
)
\def\appendtolist#1{% <item>
\csname pgfutil@ifundefined\endcsname{mylistmacro}{\def\mylistmacro{#1}}{% Instantiate list if not already
\expandafter\def\expandafter\mylistmacro\expandafter{\mylistmacro^^J#1}}% Append to list
}%
What I effectively want to do:
(using pgf
)
\def\appendtolist#1#2{% <macro representing list> <item>
\csname pgfutil@ifundefined\endcsname{#1}{\def\ithapplist{#1}}{% Instantiate list if not already
\expandafter\def\expandafter#1\expandafter{\ithapplist^^J#1}}% Append to list
}%
Problem
After \endcsname
I need to supply a macro name without the backslash.
Even if I use this other syntax for determining whether or not the macro has been defined, I still run into this problem.
Other csname checks
TeX Kernel
https://tex.stackexchange.com/a/30484/13552
\ifcsname#1\endcsname%
... command '#1' exists ...%
\else%
... command '#1' does not exist ...%
\fi%
LateX kernel
https://tex.stackexchange.com/a/30486/13552emphasized text
\@ifundefined{foo}
{%
% \foo not defined
}
{%
% \foo defined
}%
Ultimate Goal
Normally I spit out things to the log during runtime using \typeout
. Instead, I'd like to append them to a macro (delimited variable) that I can call later with something like \typeout\expandafter{\aggregatedlogentries}
. This would keep certain things grouped in the log.
Example
Does not compile
\documentclass{article}
\usepackage{pgf}
\def\appendtolist#1{% <item>
\csname pgfutil@ifundefined\endcsname{mylistmacro}{\def\mylistmacro{#1}}{% Instantiate list if not already
\expandafter\def\expandafter\mylistmacro\expandafter{\mylistmacro^^J#1}}% Append to list
}%
\begin{document}
\newcount\step
\step = 0%
\loop
\appendtolist{\step}% <== I want to be able to provide a macro name as arg1 and item as arg2!
\advance\step by 1%
\unless\ifnum \step>10 %space important
\repeat %
\typeout{\mylistmacro}
\end{document}
\mylistmacro
to be empty and then define new\appendtolist
using internal command\g@addto@macro
\csname pgfutil@ifundefined\endcsname
rather than\pgfutil@ifundefined
?\unless
and e-TeX from egreg at tex.stackexchange.com/a/62381/13552\unless
is a primitive, theetex
package does not define it (and should not be loaded into current latex as it will undo all the new allocation code)