6

I am still using ieeecolor.cls - get it from https://www.embs.org/tmi/authors-instructions/, namely, https://www.embs.org/wp-content/uploads/2020/04/TMI-Template-LaTeX-2020.zip

With this very short MWE,

\documentclass[print]{ieeecolor}
\usepackage{tmi}
\begin{document}
\begin{figure}
    \caption{X}
\end{figure}
\end{document}

I get a

pdfTeX warning: pdflatex: pop empty color page stack 0

presumably due to the colored caption. Can this be fixed?

bers
  • 5,404

1 Answers1

11

It's a bug in ieeecolor.cls. It misuses \color with \hbox and the scope of the colour \special “leaks”. The problem narrows down to this (see how world is red too):

\documentclass{article}
\usepackage{color}
\begin{document}
\setbox0\hbox{\color{red}hello}
\box0 world
\end{document}

The \color is inserted in the \hbox, and that box is later used, but since no grouping was performed when \color was used (it acts at the time the box is used, rather than when it's set), there was a missing “end color” instruction. If you use just \hbox{\color{red}hello} (that is, no \setbox...\box), then the implicit end group from the \hbox ends the colour, because the box is being used.

Here's a patch for that. It inserts \color@begingroup and \color@endgroup around the contents of the box, so that the \color properly ends:

\documentclass[print]{ieeecolor}
\usepackage{tmi}

% Fix ieeecolor's \caption \usepackage{etoolbox} \makeatletter @ifundefined{color@begingroup}% {\let\color@begingroup\relax \let\color@endgroup\relax}{}% \def\fix@ieeecolor@hbox#1{% \hbox{\color@begingroup#1\color@endgroup}} \patchcmd@makecaption{\hbox}{\fix@ieeecolor@hbox}{}{\FAILED} \patchcmd@makecaption{\hbox}{\fix@ieeecolor@hbox}{}{\FAILED} %

\begin{document} \begin{figure} \caption{X} \end{figure} \end{document}

  • Thank you for this! It fixed my recurring issues of different parts of body text getting colored seemingly randomly – JohanPI Oct 26 '22 at 09:22