18

Is there a way to prevent \MakeUppercase from affecting in-text equations? In this example, abc should change to ABC, but n should be left as it is.

\documentclass{article}
\begin{document}
\MakeUppercase{abc $n$}
\end{document}

The following works for individual characters, but I would like something more general.

\documentclass{article}
\begin{document}
\newcount\mycount
\mycount\mathcode`n
\MakeUppercase{abc $\mathchar\mycount$}
\end{document}
lockstep
  • 250,273
Ian Thompson
  • 43,767
  • 1
    try the textcase package, AFAIK it has a \MakeUppercaseText macro – daleif Mar 02 '12 at 16:35
  • Unfortunately that's not an option. This problem arises from a journal document class applying \MakeUppercase to section headings. I need to prevent the existing command from affecting mathematics. – Ian Thompson Mar 02 '12 at 16:44
  • So you want to modify \MakeUppercase then? – Werner Mar 02 '12 at 16:47
  • @Werner --- I thought there might be some way to prevent \MakeUppercase from changing mathematics, similar to the use of braces to prevent BIBTeX from changing the case of letters. Failing that, your suggestion of \let\MakeUppercas\MakeTextUppercase looks like a good alternative. – Ian Thompson Mar 02 '12 at 17:04

2 Answers2

15

textcase provides \MakeTextUppercase:

enter image description here

\documentclass{article}
\usepackage{textcase}% http://ctan.org/pkg/textcase
\begin{document}
\MakeUppercase{abc $n$} \par
\MakeTextUppercase{abc $n$}
\end{document}

For easy modification across the entire document, I suggest issuing

\usepackage[overload]{textcase}% http://ctan.org/pkg/textcase

which "overloads" both \MakeUppercase and \MakeLowercase with \MakeTextUppercase and \MakeTextLowercase, respectively. Similar to

\let\MakeUppercase\MakeTextUppercase
\let\MakeLowercase\MakeTextLowercase

Apparently the AMS document classes also provide this functionality - a math-aware \MakeUppercase using \uppercasenonmath. See @barbarabeeton's answer to Stop memoir from making mathmode section names uppercase in header.

Werner
  • 603,163
15

The textcase package was already mentioned. But if you are forced to stay with an unchanged \MakeUppercasefor some reason then you still have the poor man's choice of "hiding" the math:

\newcommand\hidemath{$n$}
\MakeUppercase{abc \protect\hidemath}

The \protect is needed as \MakeUppercase in LaTeX is essentially an \edef that only stops expanding at \protect.

Or the alternative with eTeX which has protection at the macro definition level:

\protected\def\hiddenmath{$n$}
\MakeUppercase{abc \hiddenmath}
Werner
  • 603,163
  • I think the 'poor man's' choice is the best option here. I need this for a journal article, and the publishers may view redefining \MakeUppercase as hacking their class file. – Ian Thompson Mar 03 '12 at 10:48