11

How can I get the \Gls{...} command to capitalize the first letter of EACH word, not just the first word?

\documentclass[a4paper,12pt]{article}

\usepackage{glossaries}

\newacronym{tla}{TLA}{three lettered acronym}
\makeglossaries

\begin{document}
\glsfirst{tla}

\Glsfirst{tla}

\end{document}
1

1 Answer 1

11

\Gls-like commands use \makefirstuc to capitalize only the first letter of a sentence.

I've redefined the meaning of \makefirstuc to be the same of \capitalisewords which instead capitalizes all words in a sentence.

So, add this in the preamble

\makeatletter
\let\oldmakefirstuc\makefirstuc
\renewcommand*{\makefirstuc}[1]{%
  \def\gls@add@space{}%
  \mfu@capitalisewords#1 \@nil\mfu@endcap
}
\def\mfu@capitalisewords#1 #2\mfu@endcap{%
  \def\mfu@cap@first{#1}%
  \def\mfu@cap@second{#2}%
  \gls@add@space
  \oldmakefirstuc{#1}%
  \def\gls@add@space{ }%
  \ifx\mfu@cap@second\@nnil
    \let\next@mfu@cap\mfu@noop
  \else
    \let\next@mfu@cap\mfu@capitalisewords
  \fi
  \next@mfu@cap#2\mfu@endcap
}
\makeatother

and everything should be as you want.

Complete MWE:

\documentclass[a4paper,12pt]{article}

\usepackage{glossaries}

\makeatletter
\let\oldmakefirstuc\makefirstuc
\renewcommand*{\makefirstuc}[1]{%
  \def\gls@add@space{}%
  \mfu@capitalisewords#1 \@nil\mfu@endcap
}
\def\mfu@capitalisewords#1 #2\mfu@endcap{%
  \def\mfu@cap@first{#1}%
  \def\mfu@cap@second{#2}%
  \gls@add@space
  \oldmakefirstuc{#1}%
  \def\gls@add@space{ }%
  \ifx\mfu@cap@second\@nnil
    \let\next@mfu@cap\mfu@noop
  \else
    \let\next@mfu@cap\mfu@capitalisewords
  \fi
  \next@mfu@cap#2\mfu@endcap
}
\makeatother

\newacronym{tla}{TLA}{three lettered acronym}
\makeglossaries

\begin{document}

\glsfirst{tla}

\Glsfirst{tla}

\end{document} 

Output:

enter image description here

4
  • This is excellent, how would it be possible to ignore words such as: to, or, for, the, and, etc... Oct 26, 2013 at 2:15
  • @ADP this is not simple at all, I think. And I haven't any idea at the moment... Oct 26, 2013 at 3:58
  • 3
    This is a bit of a hack, I am sure, however it works... \newacronym{tla}{TLA}{three~lettered acronym} prevents the 'lettered' word from being capitalized. Therefore, in each definition, joining 'and', 'to', 'for' etc... to the previous words via ~ does the job. Oct 26, 2013 at 4:12
  • 1
    Why does Latex "programming" have to look to chaotic?!
    – winklerrr
    Apr 19, 2020 at 11:02

You must log in to answer this question.

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