在额外的词汇表中强制使用自定义长/短版本

在额外的词汇表中强制使用自定义长/短版本

我已经设置了自定义的 glossaries-extra 配置。我定义了名为customLongVersion和的自定义命令,customShortVersion这些命令在命令中使用\glsentryfmt。但是,我在强制使用这些自定义版本(customlongcustomshortforcefirst)时遇到了挑战。默认命令似乎使用标准的长/短格式,我不确定如何覆盖此行为。

以下屏幕截图以表格形式显示了当前行为和预期行为: 在此处输入图片描述

我还提供了平均能量损失通过 Overleaf 可以更方便地参考。对于那些不想使用 overleaf 的人来说,这里是完整的代码:

\documentclass{article}

\usepackage{hyperref, tabularx}
\usepackage[acronym]{glossaries-extra}

% Glossary Initialization
\makenoidxglossaries

% Custom Command to enforce "first-use" style
\newcommand{\customshort}[2][]{\glslink[noindex]{#2}{\glsentryshort{#2}}#1}

% Custom Command to enforce "first-use" style
\newcommand{\customlong}[2][]{\glslink[noindex]{#2}{\glsentrylong{#2}}#1}

% Force First Form
\newcommand{\forcefirst}[3][]{%
    % Force the initial representation, however I think it isn't a good idea to do it like this (I had some trouble with this + list of glossaries in the past)
    \glslocalreset{#2}% 
    \gls[noindex, #1]{#2}[#3]%
}

% Custom Command for Long Version
\newcommand{\customLongVersion}{%
    Long\expandafter\glsaccesslong\expandafter\glslabel
}

% Custom Command for Short Version
\newcommand{\customShortVersion}{%
    Short\expandafter\glsaccessshort\expandafter\glslabel
}

% Re-define the Glossary Entry Format
\renewcommand*{\glsentryfmt}{%
  \ifglsused\glslabel%
  {Used:\customShortVersion}
  {New:\customLongVersion\space(\customShortVersion)}
}


% Define a new sample acronym
\newacronym{SVG}{SVG}{Scalable Vector Graphics}
  
\begin{document}

Normal: \gls{SVG} is a normal usage with \gls{SVG} as short version.

% Inside the table the result is not as expected!
\begin{table}[h]
    \centering
    \begin{tabularx}{\linewidth}{lXX}
        \textbf{Command} & \textbf{Result} & \textbf{Expected}\\
         \texttt{customshort\{SVG\}} &  \customshort{SVG} & ShortSVG\\
         \texttt{customlong\{SVG\}} & \customlong{SVG} & LongScalable Vector Graphics\\
         \texttt{forcefirst\{SVG\}} & \forcefirst{SVG} & New:LongScalable Vector Graphics(ShortSVG)\\
    \end{tabularx}
    \caption{Caption}
    \label{tab:my_label}
\end{table}

\end{document}

相关内容