Can I use a command to set a variable, then use that variable earlier in the document?

Specifically, I want grab the last revision from the revision history table and put that in my footers.

In my *.tex, I have an environment and commands for a version-history table which I use like this:

  \version{1.0}{1 April 2020}{Initial Release}
  \version{1.1}{10 Oct 2021}{Updated chapter 2}

In my *.cls I currently have:

\pagestyle{fancy} % Imports header style
\fancyhf{} % Clear header/footer
\newcommand{\version}[3]{#1 & #2 & #3\\\hline}
\newenvironment{history}{ ... }{ ... }

And I am thinking of doing this:


\pagestyle{fancy} % Imports header style
\fancyhf{} % Clear header/footer
\fancyfoot[L]{\@title Rev\@revision}

  #1 & #2 & #3\\\hline%
\newenvironment{history}{ ... }{ ... }

But there are two problems:

  1. My footers always show ?.
  2. Even if \@revision was updated, my version history table is not on the first page. So I imagine it would only set the value for later pages.

Is there a way I can store my revision in *.out or *.aux? Then my footer can use that value at the start of the document, and I'll get a rerunfilecheck if it changed since last run?

I found a promising answer here but it saves counters (which I assume are integer-only). I'm interested in something that can handle [a-zA-Z0-9\.]+

  • It would be very helpful if you wrote a small, complete code we can copy/paste instead of censored snippets.
    – campa
    Jul 29 at 11:47

2 Answers 2


You can conditionally set the label if the entry coincides with the last revision number gathered at the previous run.


  Rev & Date & Reason \\ \hline

  \fi & #2 & #3 \\ \hline



  \version{1.0}{1 April 2020}{Initial Release}
  \version{1.1}{10 Oct 2021}{Updated chapter 2}


The last revision is \lastrevision.


You can use \lastrevision anywhere you want.


I managed to adapt an answer from this solution: https://tex.stackexchange.com/a/160035/205379

First I define a command for setting the revision:

  \protected@write \@auxout {}{\string \newlabel{revision}{{#1}{\thepage}{#1}{revision}{}} }%

Then I can access the revision with \ref{revision}:

\pagestyle{fancy} % Imports header style
\fancyhf{} % Clear header/footer
\fancyfoot[L]{\@title Rev:\ref{revision}}

Then I can set the revision in my document:

  \setrev{#1}#1 & #2 & #3\\\hline%

I do get the warning:

LaTeX Warning: There were multiply-defined labels.

But maybe I'll have to live with that.

  • A safer approach is to use \edef\@currentlabel{#1} and \label. You can also put \string\gdef\string\foo{#1} into \protected@write \@auxout. Jul 29 at 12:19
  • That sounds great. I'm trying to find reference manuals for \profected@write \@auxout, \newlabel, \edef, \string, \gdefand \@currentlabel. If you don't mind writing it up as an answer or explaining what it does, I'd be happy to try it out and accept that answer.
    – Stewart
    Jul 29 at 12:33
  • \edef, \string and \gdef are TeX commands and can be found in the TeXbook by Knuth. I believe the rest are covered in source2e.pdf (which should already be loaded in the docs folder). Jul 29 at 16:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.