14

The LaTeX team are looking to improve the implemenation of case-changing in LaTeX (\MakeUppercase and \MakeLowercase, plus potentially integrating the textcase package). To help with that, I'd like to ask for examples of 'tricky' case changing.

Each answer should have

  • A short 'title' to explain what it shows
  • The input you wanted to use
  • What you expected to get as a result
  • What you actually got

and for 'bonus points' how you got around the problem.

Good examples will probably include: using commands in text, accented characters, multiple languages, etc.

2
  • 2
    No specific examples, but encouragement to include textcase, so that math, \ref, and \cite aren't corrupted in the process. Feb 12, 2020 at 17:43
  • @barbarabeeton That's already on the list: the only trciky aspect is the optional argument to \cite
    – Joseph Wright
    Feb 12, 2020 at 18:21

5 Answers 5

5

Storing case-changed text

Long ago, I posted a question asking how to store the upper case counterpart of a string. In short, the result of

\def\word{abc}
\def\WORD{\MakeUppercase{\word}}
\show\WORD

is \MakeUppercase{abc}, whereas I would like ABC. The seemingly obvious solution

\edef\WORD{\MakeUppercase{\word}}

generates an error. @Bruno Le Floch solved this using

\def\word{abc}
\MakeUppercase{\gdef\noexpand\WORD{\word}}

which, in all honesty, I still don't understand!

1
  • \MakeUppercase expands its arguments and then uppercases it using \uppercase (plus a few protections for special input). \MakeUppercase{\gdef\noexpand\WORD{\word}} will expand \word and uppercase it, leaving \WORD unexpanded (\noexpand), so is equivalent to \uppercase{\gdef\WORD{<contents of \word>} (modulo the protection for special characters). Does this explain it?
    – Skillmon
    Feb 13, 2020 at 23:03
4

Citation keys

Case changing gets applied to citation keys by the standard \MakeUppercase functions

\documentclass{article}
\begin{filecontents*}{\jobname.bib}
@Article{a-key,
  author    = {Person One},
  title     = {A demo in lowercase},
  journal   = {Journal of Irreproducible Results},
  year      = {2020}
}
\end{filecontents*}
\begin{document}
A demo \cite{a-key}
\MakeUppercase{Some text \cite{a-key}}
\bibliographystyle{unsrt}
\bibliography{\jobname}
\end{document}

which yields one missing citation:

enter image description here

This can be handled using the textcase package

\documentclass{article}
\usepackage[overload]{textcase}
\begin{filecontents*}{\jobname.bib}
@Article{a-key,
  author    = {Person One},
  title     = {A demo in lowercase},
  journal   = {Journal of Irreproducible Results},
  year      = {2020}
}
\end{filecontents*}
\begin{document}
A demo \cite{a-key}
\MakeUppercase{Some text \cite{a-key}}
\bibliographystyle{unsrt}
\bibliography{\jobname}
\end{document}

which then gives

enter image description here

3

Math mode

Math mode material should not be case changed, but

\documentclass{article}
\begin{document}
\MakeUppercase{Some text $y = mx + c$}
\end{document}

gives

enter image description here

which can be fixed using textcase

\documentclass{article}
\usepackage[overload]{textcase}
\begin{document}
\MakeUppercase{Some text $y = mx + c$}
\end{document}

enter image description here

3

Headers

Headers of chapters are set using \MakeUppercase by default (in book and report). Undefined references in chapter titles end up with warnings in the .log also showing in all-caps:

\documentclass{book}

\usepackage{lipsum}

\begin{document}

\sloppy
\chapter{A chapter before Chapter~\ref{ch:two}}
\lipsum[1-50]
\chapter{Second chapter}
\lipsum[1-50]

\end{document}

Here's the .log showing an uppercase warning with the setting of every \chapter-related mark (even pages):

Chapter 1.

LaTeX Warning: Reference `ch:two' on page 1 undefined on input line 8.

[1


{c:/texlive/2019/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]

LATEX WARNING: REFERENCE `CH:TWO' ON PAGE 1 UNDEFINED on input line 10.

[2] [3]

LATEX WARNING: REFERENCE `CH:TWO' ON PAGE 1 UNDEFINED on input line 10.

[4] [5]

LATEX WARNING: REFERENCE `CH:TWO' ON PAGE 1 UNDEFINED on input line 10.

[6] [7]

LATEX WARNING: REFERENCE `CH:TWO' ON PAGE 1 UNDEFINED on input line 10.

[8] [9]

LATEX WARNING: REFERENCE `CH:TWO' ON PAGE 1 UNDEFINED on input line 10.

[10]
Chapter 2.
[11

] [12] [13] [14] [15] [16] [17] [18] [19] [20] (./latex_stuff.aux)

LaTeX Warning: There were undefined references.

 )
2

Expanding the nonchangecase list of textcase for uppercase captions/headings

Maybe the new version of \MakeUppercase can expand the \@nonchangecase list of textcase to a wider range of commands?

For instance, suppose that a template requires uppercase section heads and uppercase captions. You'd like end-users to be able to use \eqref in captions and \footnote in headings without having to call \NoCaseChange.

Here's an example:

\documentclass{article}

\usepackage{amsmath}
\usepackage{textcase}  

\usepackage{caption}
    \DeclareCaptionLabelFormat{uppercase}{\MakeTextUppercase{#1} #2}
    \DeclareCaptionFormat{uppercase}{#1 #2 {\MakeTextUppercase #3}}
    \captionsetup[figure]{labelformat=uppercase, labelfont=bf, format=uppercase}

\usepackage{titlesec}
    \titleformat{\section}{\bfseries\raggedright}{\thesection .}{0.5em}{\MakeTextUppercase}

%% Patch textcase to include \footnote and \eqref. 
\makeatletter
\usepackage{etoolbox}  
    \patchcmd{\@uclcnotmath}{\@nonchangecase\ref}{\@nonchangecase\ref\@nonchangecase\footnote}{}{}
    \patchcmd{\@uclcnotmath}{\@nonchangecase\ref}{\@nonchangecase\ref\@nonchangecase\eqref}{}{} 

%% And stop \footnote from causing problems with \sectionmark
    \robustify{\footnote}      
    \patchcmd{\section}{\sectionmark}{\let\footnote\@gobble\sectionmark}{}{} 
\makeatother

\begin{document}

\section{Section heading with a footnote\footnote{Footnote that does not need \texttt{\textbackslash NoCaseChange}.}}
Some text (see Fig.~\ref{fig:1}) and an equation
\begin{equation}\label{eqn:tag}
A = B
\end{equation}

\begin{figure}
\caption{Caption with math, eqn.~\eqref{eqn:tag}: $z = (r,\phi)$ \cite{latexdps}\label{fig:1}}
\end{figure}

\begin{thebibliography}{9}
\bibitem{latexdps} 
  Leslie Lamport. \textit{\LaTeX{}: a document preparation system}. Addison-Wesley, Reading, Massachusetts, 1993.
\end{thebibliography}

\end{document}  

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .