词汇表可选择删除长格式和缩写之间的空格

词汇表可选择删除长格式和缩写之间的空格

如果将外文缩写(此处为英文)与德文单词配对,则-在两者之间使用 a。现在我遇到的问题是,第一次出现的缩写词与配对的德文单词一起出现。在这种情况下,需要删除缩写词的长形式和括号中的缩写词之间的空格(请参阅 MWE)。所以我正在寻找一个可选参数\cgls或另一个命令来\cglsnw删除这个空格。

梅威瑟:

\documentclass[a4paper]{article}

\usepackage[english,ngerman]{babel}

\usepackage{glossaries}

\newacronymstyle{emfirst-long-sp-short}
{%
  \GlsUseAcrEntryDispStyle{long-sp-short}%
}%
{%
  \GlsUseAcrStyleDefs{long-sp-short}%  
    \renewcommand*{\genacrfullformat}[2]{%
        \emph{\glsentrylong{##1}}##2\glsacspace{##1}%
        (\protect\firstacronymfont{\glsentryshort{##1}})%
    }%
    \renewcommand*{\Genacrfullformat}[2]{%
        \emph{\Glsentrylong{##1}}##2\glsacspace{##1}%
        (\protect\firstacronymfont{\glsentryshort{##1}})%
    }%
    \renewcommand*{\genplacrfullformat}[2]{%
        \emph{\glsentrylongpl{##1}}##2\glsacspace{##1}%
        (\protect\firstacronymfont{\glsentryshortpl{##1}})%
    }%
    \renewcommand*{\Genplacrfullformat}[2]{%
        \emph{\Glsentrylongpl{##1}}##2\glsacspace{##1}%
        (\protect\firstacronymfont{\glsentryshortpl{##1}})%
    }%
}

\renewcommand*{\glsacspace}[1]{~}

\setacronymstyle{emfirst-long-sp-short}

\newcommand\newforeignacronym[5][]{\newacronym[#1]{#2}{#3}{\foreignlanguage{#5}{#4}}}

\makeglossaries

\glsenableentrycount

\newforeignacronym{am}{AM}{Application Management}{english}
\newforeignacronym{svm}{SVM}{Support Vector Machine}{english}


\begin{document}

The output from glossaries: \cgls{am}-Problem. \cgls{am}

Required output (without whitespace): \emph{Application Management}(AM)-Problem.

Required output for acronyms which are not coupled (so here with whitespace): \cgls{svm}. \cgls{svm}




\printglossaries
\end{document}

答案1

一个命题:使用 的重新定义,\cgls其具有可选的第 3 个参数,并重新定义\glsacspace来判断 是否等于\glsentrycurrcount0大于0

然而,这还不够,因为如果不向前看,\cgls{am}-foo就不会对部分做出反应,因此请这样使用它-foo

\cgls{am}[Problem]

\documentclass[a4paper]{article}

\usepackage[english,ngerman]{babel}
\usepackage{letltxmacro}
\usepackage{xparse}
\usepackage{glossaries}

\renewcommand*{\glsacspace}[1]{~}


\makeatletter
\LetLtxMacro\glossaries@@cgls\cgls
\let\glossaries@@glsacspace\glsacspace




\newif\ifthirdargused%

\RenewDocumentCommand{\cgls}{O{}mo}{%
  \IfValueT{#3}{%
    \thirdargusedtrue%
  }%
  \ifthirdargused
  \begingroup
  \renewcommand*{\glsacspace}[1]{%
    \ifnum\glsentrycurrcount{##1} > 0% Is it > 0 then use the predefined spacing. 
    \glossaries@@glsacspace{##1}%
    \fi
  }%
  \glossaries@@cgls[#1]{#2}-#3%
  \endgroup
  \else
  \glossaries@@cgls[#1]{#2}%
  \fi
  \thirdargusedfalse%
  \let\glsacspace\glossaries@@glsacspace%
}

\makeatother


\newacronymstyle{emfirst-long-sp-short}
{%
  \GlsUseAcrEntryDispStyle{long-sp-short}%
}%
{%
  \GlsUseAcrStyleDefs{long-sp-short}%  
    \renewcommand*{\genacrfullformat}[2]{%
        \emph{\glsentrylong{##1}}##2\glsacspace{##1}%
        (\protect\firstacronymfont{\glsentryshort{##1}})%
    }%
    \renewcommand*{\Genacrfullformat}[2]{%
        \emph{\Glsentrylong{##1}}##2\glsacspace{##1}%
        (\protect\firstacronymfont{\glsentryshort{##1}})%
    }%
    \renewcommand*{\genplacrfullformat}[2]{%
        \emph{\glsentrylongpl{##1}}##2\glsacspace{##1}%
        (\protect\firstacronymfont{\glsentryshortpl{##1}})%
    }%
    \renewcommand*{\Genplacrfullformat}[2]{%
        \emph{\Glsentrylongpl{##1}}##2\glsacspace{##1}%
        (\protect\firstacronymfont{\glsentryshortpl{##1}})%
    }%
}


\glsenableentrycount



\setacronymstyle{emfirst-long-sp-short}

\newcommand\newforeignacronym[5][]{\newacronym[#1]{#2}{#3}{\foreignlanguage{#5}{#4}}}

\makeglossaries


\newforeignacronym{am}{AM}{Application Management}{english}
\newforeignacronym{svm}{SVM}{Support Vector Machine}{english}


\begin{document}

The output from glossaries: \cgls{am}[Problem]. 

Second usage: \cgls{am}

Required output (without whitespace): \emph{Application Management}(AM)-Problem.

Required output for acronyms which are not coupled (so here with whitespace): \cgls{svm}. 

Second usage: \cgls{svm}

%\cgls{am}-Problem

%\cgls{am}


\printglossaries
\end{document}

在此处输入图片描述

答案2

这是另一种不修改内部结构的可能性。

\documentclass[a4paper]{article}

\usepackage[english,ngerman]{babel}

\usepackage{glossaries}

\newcommand*{\ishyphen}[2]{\ifdefstring{\glsinsert}{-}{#1}{#2}}

\newacronymstyle{emfirst-long-sp-short}
{%
  \GlsUseAcrEntryDispStyle{long-sp-short}%
}%
{%
  \GlsUseAcrStyleDefs{long-sp-short}%  
    \renewcommand*{\genacrfullformat}[2]{%
        \emph{\glsentrylong{##1}}\ishyphen{}{##2\glsacspace{##1}}%
        (\protect\firstacronymfont{\glsentryshort{##1}})\ishyphen{-}{}%
    }%
    \renewcommand*{\Genacrfullformat}[2]{%
        \emph{\Glsentrylong{##1}}\ishyphen{}{##2\glsacspace{##1}}%
        (\protect\firstacronymfont{\glsentryshort{##1}})\ishyphen{-}{}%
    }%
    \renewcommand*{\genplacrfullformat}[2]{%
        \emph{\glsentrylongpl{##1}}\ishyphen{}{##2\glsacspace{##1}}%
        (\protect\firstacronymfont{\glsentryshortpl{##1}})\ishyphen{-}{}%
    }%
    \renewcommand*{\Genplacrfullformat}[2]{%
        \emph{\Glsentrylongpl{##1}}\ishyphen{}{##2\glsacspace{##1}}%
        (\protect\firstacronymfont{\glsentryshortpl{##1}})\ishyphen{-}{}%
    }%
}

\renewcommand*{\glsacspace}[1]{~}

\setacronymstyle{emfirst-long-sp-short}

\newcommand\newforeignacronym[5][]{\newacronym[#1]{#2}{#3}{\foreignlanguage{#5}{#4}}}

\makeglossaries

\glsenableentrycount

\newforeignacronym{am}{AM}{Application Management}{english}
\newforeignacronym{svm}{SVM}{Support Vector Machine}{english}


\begin{document}

The output from glossaries: \cgls{am}[-]Problem. \cgls{am}

Required output (without whitespace): \emph{Application Management}(AM)-Problem.

Required output for acronyms which are not coupled (so here with whitespace): \cgls{svm}. \cgls{svm}

\printglossaries
\end{document}

这将重新定义要检查的完整格式中使用的命令\glsinsert(设置为\gls/等命令的最后一个可选参数\cgls)。这实际上是 etc 的第二个参数\genacrfullformat,因此如果它在 之外使用,则可以针对它进行测试\cgls

结果图像

相关内容