I am writing a package that lets the user type a block of text which may be printed later in the output document than it appears in the source, i.e. re-ordering the text.
Currently, I am passing the block of text to a command, which renews another command to hold the page on which the text should occur, based on a sum (using FP). But I've hit a problem; if my command is inside an environment -- any environment -- then the \renewcommand's effect is local to the environment. After the end of the environment, the calculated value is lost.
I guess that I need to change my renewcommand to \gdef, but with that I get some results that I can't understand. (Is there a latex equivalent to TeX's \gdef? "\global\renewcommand" doesn't seem to do anything different to "\renewcommand")
Here is a minimal example that runs, and illustrates my confusion:
Code: Select all
\documentclass{article}
\usepackage{fp}
\newcommand{\foo}{A}
\newcommand{\setfoo}[1]{%
\FPadd{\temp}{#1}{2}
\gdef\foo{\temp}
Set to: \foo
}
\begin{document}
\foo % \foo yields ``A''
% Output foo
\begin{center}
\setfoo{1}% \foo changes to 3.000...
\foo % \foo is still 3.000...
\end{center}
\foo % foo is now ``[(]'' ???
\end{document}
Any help much appreciated; things seem very surreal to me just now…