# Color switches are problematic with footnotes, longtable and hyperref

When using the color package in its switch form (\color cf. \textcolor), things can get confused using certain packages, with footnotes, and with section headings. The section headings issue was discussed in another of my questions but, even with the \zcolor robust command definition suggested by David Carlisle (the color author) there, this still causes problems with footnotes, and the longtable and hyperref packages.

See the LaTeX source below:

(a) Footnotes from coloured text lose their colour.

(b) hyperref URLs within footnotes get the colour back! (This doesn't happen if using the url package instead.)

(c) Floating longtables can/will get the color of text on the page they float to, even when defined in a non-coloured area. (Using table and tabular doesn't have this problem. I used the afterpage package to force the table to be on the next page, and assume the problem still exists if it 'naturally' did.)

\documentclass[11pt,a4paper,twoside,notitlepage]{article}

%\usepackage{url}      % URLs in footnotes consistent (no color) if use this instead
\usepackage{hyperref}
\usepackage{breakurl}
\usepackage[usenames,dvips]{color}
\usepackage{lipsum}
\usepackage{afterpage}
\usepackage{longtable}

\newcommand{\startToDo}{\color{Purple}}
\newcommand{\stopToDo}{\color{Black}}

\author{Stuart Rossiter}
\title{Color weirdness test}
\date{4th November 2013}

\begin{document}

\maketitle

\startToDo          % Works with titles
\section{Wibble Wobble}
\lipsum[1-4]
What about footnote weirdness?\footnote{A profound footnote that should be
colored with a URL:
\url{http://wibblewobble.org}.}
\stopToDo

\lipsum[1-3]

\afterpage{         % Just to force it to be on page with colored text
\begin{longtable}{ccc}      % Table is OK if use normal table and tabular
%\begin{table}
%\begin{tabular}{ccc}
a & b & c \\
d & e & f \\
\caption{An astonishing table that shouldn't be coloured.}
%\end{tabular}
%\end{table}
\end{longtable}
}

\section{Wobble Wibble}

\startToDo
\lipsum
\stopToDo

\end{document}


I guess my question is:

Can my use of color be 'fixed' to work robustly in all such scenarios?

(David's answer to my other question suggests color is fundamentally problematic in such contorted constructs, and can't be 'fixed' itself.)

As the \startToDo and \stopToDo (custom) macros suggest, I use color to mark-up to-do text. I'll ask a separate question about better alternatives (that avoid these colour issues).

• no time now, may look this evening, but the important thing to remember is whatever has gone wrong it's not my fault:-) floats explicitly normalise the color so to copy that behaviour use \afterpage{{\normalcolor \begin{longtable}....}} – David Carlisle Nov 4 '13 at 15:56
• Thanks David. I've slightly changed the title to make it seem less 'accusing' of the color package! I can imagine that the multi-pass way stuff like longtable and hyperref work makes things very tricky. – Stuart Rossiter Nov 5 '13 at 11:45

I changed the color options not to use dvips explicitly so it works with latex/dvips and with pdflatex (you should rarely need to give the driver option)

I added a \normalcolor reset to \afterpage to mimic the \normalcolor that floats do.

Conversely I added a \startToDo to the footnote to overcome the color reset that footnotes do so the footnote comes out Purple.

I think this now makes the same result with pdflatex or latex/dvips/ps2pdf and I think it's the result you intended...

\documentclass[11pt,a4paper,twoside,notitlepage]{article}

%\usepackage{url}      % URLs in footnotes consistent (no color) if use this instead
\usepackage{hyperref}
\usepackage{breakurl}
\usepackage[usenames,dvipsnames]{color}
\usepackage{lipsum}
\usepackage{afterpage}
\usepackage{longtable}

\newcommand{\startToDo}{\color{Purple}}
\newcommand{\stopToDo}{\color{Black}}

\author{Stuart Rossiter}
\title{Color weirdness test}
\date{4th November 2013}

\begin{document}

\maketitle

\startToDo          % Works with titles
\section{Wibble Wobble}
\lipsum[1-4]
What about footnote weirdness?\footnote{\startToDo A profound footnote that should be
colored with a URL:
\url{http://wibblewobble.org}.}
\stopToDo

\lipsum[1-3]

\afterpage{{\normalcolor        % Just to force it to be on page with colored text
\begin{longtable}{ccc}      % Table is OK if use normal table and tabular
%\begin{table}
%\begin{tabular}{ccc}
a & b & c \\
d & e & f \\
\caption{An astonishing table that shouldn't be coloured.}
%\end{tabular}
%\end{table}
\end{longtable}
}}

\section{Wobble Wibble}

\startToDo
\lipsum
\stopToDo

\end{document}

• This looks great; will try it out soon. To be clear about the floating longtables issue ((c) in my question), are you saying that this was the result of explicitly using afterpage, and that it wouldn't happen if the longtable 'naturally' floated to a page with coloured text (i.e., my assumption in the question is wrong?). – Stuart Rossiter Oct 28 '14 at 11:43
• @monsieurRigsby well longtables don't float so the issue doesn't arise but things that do float have to normalize colour (and fonts and other things) in case they float into areas with different settings. – David Carlisle Oct 28 '14 at 11:52