使用词汇表-额外包将每个单词的首字母大写

使用词汇表-额外包将每个单词的首字母大写

如何使用该glossaries-extra包将词汇表中每个单词的首字母大写?

我碰到此主题但它使用了该glossaries包。

我也试过了\glsentrytitlecase{<label>}{long},但没有

  1. 使词汇表超链接
  2. 在末尾的括号中包含词汇表,例如,下面 MWE 中的 (ES)

基本上,我想要的类似于,\Gls但是将每个单词的首字母大写,而不是仅仅将第一个单词的首字母大写。

梅威瑟:

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

更新:

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

答案1

这是解决方案。请注意代码中的注释。如果您希望第二个用途显示简短形式,请取消注释那些注释。否则它将始终显示完整形式。添加\myGlspl以处理复数形式。

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

在此处输入图片描述

相关内容