# \everymath and \underline color

I use \everymath to change the color of all maths (blue). However, beyond my expectation, this color happens to automatically apply for any underlined texts. Please kindly instruct me how to solve this problem, i.e have all underlined texts back to normal color (black). Any help will be highly appreciated.

Below is a small example to illustrate my problem.

\documentclass[11pt]{paper}
\usepackage[usenames]{color}
\everymath{\color{blue}}
\makeatletter \def\m@th{\normalcolor\mathsurround\z@} \makeatother

\begin{document}
\underline{Problem 1.} This is \underline{some} math: $a^2$.
\end{document}

• \underline uses math mode. You can consider with the package ulem or soul, or not underlining altogether. – egreg Dec 1 '18 at 15:31
• Add a \footnote and a \url (from the url or hyperref package) to your document to see more blue where one might not expect it. – moewe Dec 1 '18 at 15:42

The definition of \underline is

% latex.ltx, line 5128:
\def\underline#1{%
\relax
\ifmmode\@@underline{#1}%
\else $\@@underline{\hbox{#1}}\m@th$\relax\fi}


and the placement of \m@th is the explanation for your output.

It is necessary to have \m@th there, because otherwise it could affect math in the text to be underlined.

You might want to redefine it:

\def\underline#1{%
\relax
\ifmmode\@@underline{#1}%
\else $\normalcolor\@@underline{\hbox{#1}}\m@th$\relax\fi}


but you should consider to use the facilities of the packages ulem or soul.

Better yet, don't underline at all.

• Many thanks for your clear guidance. I would spend time to study further on ulem or soul packages. But for now, your solution works perfectly for my current desire. – Romalpa Akzo Dec 1 '18 at 15:44