词汇表、如何将每个首字母大写以及仅将首字母大写(仍支持复数形式)

词汇表、如何将每个首字母大写以及仅将首字母大写(仍支持复数形式)

由此question,我如何使用一个命令将其更改为每个单词的首字母大写,并使用另一个命令仅将第一个单词的首字母大写(仍然支持复数形式)形式如下:

\documentclass[a4paper,12pt]{article}
\usepackage{glossaries}
\usepackage{glossary-mcols}

\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

\newglossaryentry{word}{
    name = {word},
    description = {word description},
    plural = {words},
    descriptionplural = {words description}
}
\newglossaryentry{good word}{
    name = {good word},
    description = {good word description},
    plural = {good words},
    descriptionplural = {good words description},
    parent = {word}
}
\makeglossaries

\begin{document}


1. \gls{word}% correct

2. \Gls{word}% correct

3. \glspl{word}% correct

4. \Glspl{word}% correct

5. \glsfirst{word}% correct

6. \Glsfirst{word}% correct

7. \glsplfirst{word}% gives error

8. \Glsplfirst{word}% gives error, doesn't capitalize

1p. \gls{good word}% correct

2p. \Gls{good word}% correct, it capitalizes every words first letter

3p. \glspl{good word}% correct

4p. \Glspl{good word}% correct, it capitalizes every words first letter and does plural

5p. \glsfirst{good word}% correct, it capitalizes every words first letter and does plural

6p. \Glsfirst{good word}% wrong, it should capitalize only first's words first letter.

7p. \glsplfirst{good word}% gives error, doesn't make plural

8p. \Glsplfirst{good word}% gives error, doesn't capitalize first word's first letter and doesn't make plural

\printglossary[style=mcoltreespannav]

\end{document}

结果: 结果:

相关内容