My problem to be solved is: I want to set and reset a value (like a summation value) per line in my longtable (whose content is generated from the outside of the document).
\documentclass[12pt,twoside]{article}
\newcommand{\myvalue}{initialise}
\usepackage{longtable}
\begin{document}
\begin{longtable}{ll}
\myvalue&test\renewcommand{\myvalue}{1}\\
test &test\renewcommand{\myvalue}{2}\\
test &test\renewcommand{\myvalue}{3}\\
test&test\renewcommand{\myvalue}{4}\\\pagebreak
\myvalue&test\renewcommand{\myvalue}{5}\\
test&test\renewcommand{\myvalue}{6}\\\pagebreak
\myvalue&test\renewcommand{\myvalue}{7}\\
test &test\renewcommand{\myvalue}{8}
\end{longtable}
This was my longtable example for \myvalue
\end{document}
What I expect is, that at the beginning of each page, there is a new \myvalue
("initialise", "4", "6") and after the table "8".
What I get is only "initialise", \myvalue
is never changed.
&test\renewcommand{\myvalue}{1}\\
is like{test\renewcommand{\myvalue}{1}}
and the value will not be seen outside that scope.\renewcommand
inside any LaTeX environment. Tables add the compilcation that each table cell is a scope group, but the issue would be there in more friendly environments too. (as you want to use data outside the environment). LaTeX provides no interface to work around that problem. You must resort to\global\def
or\gdef
as in @marmot answer, or, if possible, use auxiliary files which is quite more complicated.