0

How to capitalize the first letter for EACH word in a glossary using the glossaries-extra package?

I came across this thread but it uses the glossaries package.

I also tried \glsentrytitlecase{<label>}{long} but it didn't

  1. make the glossary hyperlinked
  2. include the glossary in the parentheses at the end, e.g., (ESs) in the MWE below

Basically, what I want is similar to \Gls but make capitalize the first letter for EACH word instead of the first word only.

MWE:

\documentclass[a4paper,12pt]{article}

\usepackage[acronym]{glossaries-extra} \setabbreviationstyle[acronym]{long} \newacronym [ description={Evolutionary Strategies}, longplural={evolutionary strategies} ] {es}{ES}{evolutionary strategy} \makeglossaries

\begin{document} \printglossary[type=acronym,title={List of Acronyms}]

\glsentrytitlecase{es}{long}.

\glspl{es}.

\Glspl{es}.

\glsentrytitlecase{es}{longpl}.

\end{document}


Update:

\documentclass[a4paper,12pt]{article}

\usepackage[acronym,automake]{glossaries-extra}

\makeatletter \newrobustcmd{\myGls}{@gls@hyp@opt@myGls} \newcommand{@myGls}[2][]{% \new@ifnextchar[{@myGls@{#1}{#2}}{@myGls@{#1}{#2}[]}% } \def@myGls@#1#2[#3]{% \glsdoifexists{#2}% {% \let\do@gls@link@checkfirsthyper@gls@link@checkfirsthyper \let\glsifplural@secondoftwo \let\glscapscase@secondofthree \def\glscustomtext{% {% \ecapitalisewords{\glsentrylong{#2}}#3\space% \firstacronymfont(\glsentryshort{#2})}% } \def\glsinsert{#3}% \def@glo@text{\csname gls@\glstype @entryfmt\endcsname}% @gls@link[#1]{#2}{@glo@text}% \ifKV@glslink@local \glslocalunset{#2}% \else \glsunset{#2}% \fi }% \glspostlinkhook }

\newrobustcmd{\myGlspl}{@gls@hyp@opt@myGlspl} \newcommand{@myGlspl}[2][]{% \new@ifnextchar[{@myGlspl@{#1}{#2}}{@myGlspl@{#1}{#2}[]}% } \def@myGlspl@#1#2[#3]{% \glsdoifexists{#2}% {% \let\do@gls@link@checkfirsthyper@gls@link@checkfirsthyper \let\glsifplural@firstoftwo \let\glscapscase@secondofthree \def\glscustomtext{% {% \ecapitalisewords{\glsentrylongpl{#2}}#3\space% \firstacronymfont(\glsentryshortpl{#2})}% } \def\glsinsert{#3}% \def@glo@text{\csname gls@\glstype @entryfmt\endcsname}% @gls@link[#1]{#2}{@glo@text}% \ifKV@glslink@local \glslocalunset{#2}% \else \glsunset{#2}% \fi }% \glspostlinkhook } \makeatother

\setabbreviationstyle[acronym]{long}

\newacronym [ description=Evolutionary Strategy, longplural=evolutionary strategies ] {es}{ES}{evolutionary strategy} \makeglossaries

\begin{document} \printglossary[type=acronym,title={List of Acronyms}]

textbf{Singular:}

blablbla \gls{es}.

blablbla \glsxtrfull{es}.

blablbla \Gls{es}.

blablbla \Glsxtrfull{es}.

blablbla \myGls{es}.

blablbla \glsentrytitlecase{es}{long}.

\vspace*{1cm}

\textbf{Plural:}

blablbla \glspl{es}.

blablbla \glsxtrfullpl{es}.

blablbla \Glspl{es}.

blablbla \Glsxtrfullpl{es}.

blablbla \myGlspl{es}.

blablbla \glsentrytitlecase{es}{longpl}.

\end{document}

  • The glossaries-extra package is just an extension to the glossaries package. The basic commands will be same for both packages. The thread you mentioned is working in your case. – Tom May 07 '22 at 23:38
  • @Tom Are you sure? If I change the line \usepackage{glossaries} to \usepackage{glossaries-extra}, it doesn't produce the same result... – livemyaerodream May 08 '22 at 07:23

1 Answers1

1

This is the solution. Notice the comments in the code. If you wanna the second use to display the short form, uncomment those comments. Otherwise it will always display the full form. Add \myGlspl to deal with plural form.

\documentclass[a4paper,12pt]{article}
\usepackage[hidelinks]{hyperref}
\usepackage[acronym,automake]{glossaries-extra}

\makeatletter \newrobustcmd{\myGls}{@gls@hyp@opt@myGls} \newcommand{@myGls}[2][]{% \new@ifnextchar[{@myGls@{#1}{#2}}{@myGls@{#1}{#2}[]}% } \def@myGls@#1#2[#3]{% \glsdoifexists{#2}% {% \let\do@gls@link@checkfirsthyper@gls@link@checkfirsthyper \let\glsifplural@secondoftwo \let\glscapscase@secondofthree \def\glscustomtext{% \ifglsused{#2} {\acronymfont\glsentryshort{#2}#3} {% \ecapitalisewords{\glsentrylong{#2}}#3\space% \firstacronymfont(\glsentryshort{#2})}% }% \def\glsinsert{#3}% \def@glo@text{\csname gls@\glstype @entryfmt\endcsname}% @gls@link[#1]{#2}{@glo@text}% \ifKV@glslink@local \glslocalunset{#2}% \else \glsunset{#2}% \fi }% \glspostlinkhook }

\newrobustcmd{\myGlspl}{@gls@hyp@opt@myGlspl} \newcommand{@myGlspl}[2][]{% \new@ifnextchar[{@myGlspl@{#1}{#2}}{@myGlspl@{#1}{#2}[]}% } \def@myGlspl@#1#2[#3]{% \glsdoifexists{#2}% {% \let\do@gls@link@checkfirsthyper@gls@link@checkfirsthyper \let\glsifplural@firstoftwo \let\glscapscase@secondofthree \def\glscustomtext{% \ifglsused{#2}% {\acronymfont\glsentryshortpl{#2}#3} {% \ecapitalisewords{\glsentrylongpl{#2}}#3\space% \firstacronymfont(\glsentryshortpl{#2})}% }% \def\glsinsert{#3}% \def@glo@text{\csname gls@\glstype @entryfmt\endcsname}% @gls@link[#1]{#2}{@glo@text}% \ifKV@glslink@local \glslocalunset{#2}% \else \glsunset{#2}% \fi }% \glspostlinkhook } \makeatother

\setabbreviationstyle[acronym]{long-short}

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

\begin{document}

\printglossary[type=acronym,title={List of Acronyms}]

\myGls{tla}

\myGlspl{tla}

\Gls{tla} \end{document}

enter image description here

Tom
  • 7,318
  • 4
  • 21
  • Is there any way to keep the result of \Gls as it is (only the first letter of the first word is capitalized)? – livemyaerodream May 08 '22 at 21:58
  • 1
    Do you wanna a new command did similar thing as \Gls but capitalized each words? – Tom May 09 '22 at 00:24
  • Yes. and I would like to keep the functionality of \Gls intact. With the code you provided, the result of \Gls also capitalizes the first letter of EACH word instead of only the FIRST word as it is. – livemyaerodream May 09 '22 at 06:28
  • 1
    @hmhuang I found a way to do that. I have a question for you. Do you wanna the second use of the command to display the short form or it doesn't matter. See the new edits in my answer. – Tom May 09 '22 at 21:16
  • I need the short form as from the second use. – livemyaerodream May 10 '22 at 13:41
  • How to deal with the plural cases? – livemyaerodream May 10 '22 at 15:52
  • @hmhuang Add to the answer. – Tom May 10 '22 at 17:48
  • Thanks. Could you directly provide the code that can show the short form in the second use? I am not sure which line to uncomment... – livemyaerodream May 10 '22 at 18:00
  • @hmhuang I have already uncomment those. The code in answer should did what you want. – Tom May 10 '22 at 19:34
  • I just spotted a tiny issue with the code: The space in front of the \myGls and \myGlspl\ is larger than the normal one. Could you please fix it? Thanks! (Please see the updated post) – livemyaerodream May 11 '22 at 07:53
  • 1
    If you complete copy my code it won’t have any space in front. Notice every %in the code is necessary to prevent extra space happen – Tom May 11 '22 at 08:36
  • @hmhuang Sorry, that's my fault,. It was missing two % signs in the code. Thank you for point this out. I have fixed it. See if it works in your case. – Tom May 11 '22 at 16:10