如何根据条目级别将树形样式词汇表打印中的符号大写?

如何根据条目级别将树形样式词汇表打印中的符号大写?

如何根据条目的项目级别强制在词汇表中仅以大写或大写形式打印符号(在“符号”字段中声明非大写形式)?

这里是 MWE:

\documentclass{article}
\usepackage[style=tree]{glossaries-extra}
\makenoidxglossaries

\newglossaryentry{subsytem}{name={Subssytems},description={\glspar},sort={4}}
\newglossaryentry{compressor}
{
  name={Compressor},
  text={compressor},
  sort={compressor},
  description={Air Compressor},
  symbol={cp},
  parent=subsytem
}
\newglossaryentry{compressor_motor}
{
  name={Compressor Motor},
  sort={compressor motor},
  text={compressor motor},
  description={Motor of the \Gls{compressor}},
  symbol={cm},
  parent=compressor
}


\begin{document}
\gls{compressor_motor}
\printnoidxglossary
\end{document}

而不是这个结果: 在此处输入图片描述

我想要这样的东西(子项“压缩机(Cp)”而不是“压缩机(cp)”和子项“压缩机电机(CM)”而不是“压缩机电机(cm)”):

在此处输入图片描述

但我希望在符号字段(cp 或 cm)中以小写形式声明符号,如 MWE 中所示。

答案1

尝试一下这个代码。

更新如需更全面的回复,请查看如何在词汇表打印中将符号大写

A

\documentclass{article}
\usepackage[style=tree]{glossaries-extra}

% *******************************************added <<<<<<<<<<<
\newcommand*{\GLOSSentrysymbol}[1]{%
    \glsdoifexistsorwarn{#1}%
    {%
        \GLSentrysymbol{#1}%
    }%
}
\makeatletter
\newcommand*{\GLSentrysymbol}[1]{% see https://tex.stackexchange.com/a/199801/161015
    \begingroup\edef\tmpx{\endgroup\uppercase{\@gls@entry@field{#1}{symbol}}}\tmpx  
}
\makeatother

\renewcommand{\subglossentry}[3]{%  
    \ifcase#1\relax
        \item
    \or
        \subitem
        \glstreenamefmt{\glstarget{#2}{\glossentryname{#2}}}%
        \ifglshassymbol{#2}{\space(\Glossentrysymbol{#2})}{}%
        \glstreechildpredesc\glossentrydesc{#2}\glspostdescription\space #3%
    \else
        \subsubitem 
        \glstreenamefmt{\glstarget{#2}{\glossentryname{#2}}}%
        \ifglshassymbol{#2}{\space(\GLOSSentrysymbol{#2})}{}%
        \glstreechildpredesc\glossentrydesc{#2}\glspostdescription\space #3%
    \fi\par
}%

% *******************************************


\makenoidxglossaries

\newglossaryentry{subsytem}{name={Subssytems},description={\glspar},sort={4}}
\newglossaryentry{compressor}
{
    name={Compressor},
    text={compressor},
    sort={compressor},
    description={Air Compressor},
    symbol={cp},
    parent=subsytem
}
\newglossaryentry{compressor_motor}
{
    name={Compressor Motor},
    sort={compressor motor},
    text={compressor motor},
    description={Motor of the \Gls{compressor}},
    symbol={cm},
    parent=compressor
}


\begin{document}    
    \gls{compressor_motor}
    \printnoidxglossary
\end{document}

相关内容