0

If a LaTeX2e environment verbatim spreads two pages, then in the footer of first page, catcode of symbols like $ and _ are changed to 12 (other), as if the whole footer is inside the verbatim env.

\documentclass{article}

\makeatletter
\def\@oddfoot{footer: \showcatcode{\$}}
\makeatother

\newcommand\showcatcode[1]{%
  catcode of symbol #1\space is \the\catcode`#1\hfill
}

\begin{document}
\vspace*{.9\textheight}
main body: \showcatcode{\$}
\begin{verbatim}
0
1
2
3
\end{verbatim}
\end{document}

output of mwe

In most cases, this won't cause any problems since the contents of footer is rather simple. But if footer contains something like tikzpicture, the error raises (see questions like tikz Error some package has redefined the meaning of the math-mode dollar sign and semiverbatim with tikz in beamer).

The same problem exists when using verbatim-like environments in packages verbatim and fancyhdr, but not listings. Guess listings uses another mechanism.

My question is:

  1. Since the problem is reproducible in LaTeX2e, can we treat it as a bug?
  2. If it is a bug, how can we fix it, and fix it in the most general case? Since in the linked questions there have been solutions like 1) restore catcode by luatex only command \catcodetable@latex, and 2) save contents of footer in box.

A supplement question:

If I set \def\@oddfoot{footer: \showcatcode{\$} $a$ \showcatcode{\$}} in the above example, the output shows that the catcode of $ is always 12, but $a$ still acts like the catcode of $ is 3. How can this happen? (it seems the footer is treated differently than main body in output routine)

muzimuzhi Z
  • 26,474
  • Also you should only ask one question at a time. But the effect you observe is that the catcodes are frozen when you set the footer. The TikZ problem ony appears because TikZ "unfreezes" the catcodes again. – Marcel Krüger Jul 06 '19 at 11:38
  • @MarcelKrüger The supplement question shows that even if "catcode of $ is 12", the dollar symbol can still serve as math shift. Since the supplement question part, I am currently not sure if this is a tikz issue, a verbatim pkg issue, or a latex-base issue. I will make a new question relating the supplement question only. – muzimuzhi Z Jul 06 '19 at 11:45

0 Answers0