[texhax] How to properly accumulate TeX input for later use?

Pablo Mayckon pmsf at alu.dc.ufc.br
Fri Oct 7 01:09:55 CEST 2011


Hello, folks! Thanks in advance for the patience with my questions in what
follows.

* My original intention, abstractly: I would like to accumulate TeX input in a
control sequence, and later to use this control sequence, so that it would
execute in a row everything that I had put inside it. I've tried the
following:

\def\texcode{}
\def\addtotexcode#1{\edef\texcode{\texcode #1}}

\addtotexcode{Hi!} \addtotexcode{ Hello!} \texcode
\def\acommand{\message{ *ACOMMAND is being executed!* }}
\addtotexcode{ \acommand} \texcode % Only writes one message, as I expected.

* My problem, concretely: what I actually needed to accumulate was TikZ
instructions for drawing pictures in LaTeX (I wanted to build a set of
high-level macros that would repeatedly receive some "conceptual information"
as input and would accumulate instructions for drawing a TikZ picture later),
but then the above solution didn't work anymore:

% \usepackage{tikz}
\begin{tikzpicture}
% \path[draw] (0,0) -- (1,1) ; % This works if uncommented.
\addtotexcode{\path[draw] (0,0) -- (1,1) ;} % Infinite loop, apparently.
\end{tikzpicture}

The TeX execution doesn't finish anymore, and, if I interrupt it, it says

! Interruption.
\path ->\let \tikz at signal@path
                               =\tikz at signal@path \pgfutil at ifnextchar [{\tik...
l.28 ...addtotexcode{\path[draw] (0,0) -- (1,1) ;}
                                                  ]
?

* My questions:

  1) I surmise that the \path macro does "complicated things" and that this
leads to a problem when it is expanded into the "\edef". This alone would be
a demonstration that my strategy for accumulating TeX input is not ideal. Am
I right here or is it possible, with due TeX expertise, to adapt this
strategy so that it will properly work (not only in practise but also
conceptually)?

  2) Would it be a better idea to accumulate the input into a file, and then
read back from it when it's time to use what I've saved? (I've never used
TeX's in/output routines, but I know they exist and conceived the
possibility of using them for the purpose in question.)

  3) Any other good advice?

* My background: LaTeX user since 2005 and for the last three months I've been
studying "The TeXbook". (I've begun reading this book other times, but I would
soon quit it.) I've read chapters 1--13, 20, the "\count"-related part of 15
and the beginning of 14.

Sorry for the long message and thanks again! --Pablo, from Brazil.



More information about the texhax mailing list