I'm making a document with LaTeX and I wish to add a lateral index to each page with the first letters of the first and last words.

To do that, I need to reset a command at the end of every page

I put a snippet of code in footer (of the fancyhdr package) with:

\def\TwoFirstLettersBegin{Indef} % Resetting the command
\TwoFirstLettersBegin            % Showing the new state of the command

but when I build my document, something strange happens:

My command seams to have been correctly resetted and the right content (Indef) when it is shown in the footer. But in the next page, when I print the command, nothings seems to have been modified.

In my pages content, I regularly modify other commands and every thing is nice. I don't understand what I made wrong.

Do you have any idea why my new command definition work in the footer and is cancelled in the next page?

  • Most likely the footer is grouped somehow, hence the definition also remains local according to that group. Maybe try using \gdef... – Ruben Jan 16 '17 at 22:28
  • In general I would recommend to use the everyshi package for such things, resp. its \EveryShipout command. – Ruben Jan 16 '17 at 22:31
  • Technically your centre footer should show Indef from the point onward where you call it that way. – Werner Jan 16 '17 at 23:01

I think using fancyhdr for this is kind of a misuse. The everyshi package was actually designed for the exact purpose of performing actions right before the page gets shipped out.




\verb|\TwoFirstLettersBegin|: \TwoFirstLettersBegin

\verb|\TwoFirstLettersBegin|: \TwoFirstLettersBegin

\verb|\TwoFirstLettersBegin|: \TwoFirstLettersBegin


On the new page it's resetted -- \verb|\TwoFirstLettersBegin|: \TwoFirstLettersBegin
| improve this answer | |

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.