7

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}
6

\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

  • This is excellent, how would it be possible to ignore words such as: to, or, for, the, and, etc... – Nicholas Hamilton Oct 26 '13 at 2:15
  • @ADP this is not simple at all, I think. And I haven't any idea at the moment... – karlkoeller Oct 26 '13 at 3:58
  • 1
    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. – Nicholas Hamilton Oct 26 '13 at 4:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.