自定义首字母缩略词以将描述设置为斜体

自定义首字母缩略词以将描述设置为斜体

我正在使用词汇表包和\newacronym文档命令,我希望描述在第一次出现时以斜体文本打印,但我不想在首字母缩略词的每个定义中都这样做,有没有办法修改内部钩子或设置某种样式,使长描述自动设置为斜体

答案1

只需使用基础glossaries包,您就可以使用类似此示例来自词汇表库

% arara: pdflatex
% arara: makeglossaries
% arara: pdflatex
\documentclass{article}

\usepackage[colorlinks]{hyperref}
\usepackage[toc,acronymlists={main}]{glossaries}
\usepackage{glossary-mcols}

\makeglossaries

\newacronymstyle{long-short-emph}%
{%
  \ifglshaslong{\glslabel}%
  {% acronym
   % This is an adaptation of \glsgenacfmt
    \ifdefempty\glscustomtext
    {%
      \ifglsused\glslabel
      {%
        \glsifplural
        {%
          \glscapscase
          {%
            \acronymfont{\glsentryshortpl{\glslabel}}\glsinsert
          }%
          {%
            \acronymfont{\Glsentryshortpl{\glslabel}}\glsinsert
          }%
          {%
            \mfirstucMakeUppercase
              {\acronymfont{\glsentryshortpl{\glslabel}}\glsinsert}%
          }%
        }%
        {%
          \glscapscase
          {%
            \acronymfont{\glsentryshort{\glslabel}}\glsinsert
          }%
          {%
            \acronymfont{\Glsentryshort{\glslabel}}\glsinsert
          }%
          {%
            \mfirstucMakeUppercase
              {\acronymfont{\glsentryshort{\glslabel}}\glsinsert}%
          }%
        }%
      }%
      {%
        \glsifplural
        {%
          \glscapscase
          {%
            \emph{\glsentrylongpl{\glslabel}\glsinsert}\space
            (\firstacronymfont{\glsentryshortpl{\glslabel}})%
          }%
          {%
            \emph{\Glsentrylongpl{\glslabel}{\glsinsert}}\space
            (\firstacronymfont{\glsentryshortpl{\glslabel}})%
          }%
          {%
            \mfirstucMakeUppercase
              {\emph{\glsentrylongpl{\glslabel}{\glsinsert}}\space
               (\firstacronymfont{\glsentryshortpl{\glslabel}})}%
          }%
        }%
        {%
          \glscapscase
          {%
            \emph{\glsentrylong{\glslabel}\glsinsert}\space
            (\firstacronymfont{\glsentryshort{\glslabel}})%
          }%
          {%
            \emph{\Glsentrylong{\glslabel}\glsinsert}\space
            (\firstacronymfont{\glsentryshort{\glslabel}})%
          }%
          {%
            \mfirstucMakeUppercase
             {\emph{\glsentrylong{\glslabel}\glsinsert}\space
             (\firstacronymfont{\glsentryshort{\glslabel}})}%
          }%
        }%
      }%
    }%
    {%
      \glscustomtext
    }%
  }%
  {% regular term
    \ifglsused{\glslabel}{\glsgenentryfmt}{\emph{\glsgenentryfmt}}%
  }%
}%
{%
  \GlsUseAcrStyleDefs{long-short}%
}

\setacronymstyle{long-short-emph}

\loadglsentries{example-glossaries-brief}

\loadglsentries{example-glossaries-acronym}

\begin{document}

\section{First Use}

Regular entries: \gls{ac}, \gls{accumsan}, \gls{amet},
\gls{bibendum}, \gls{consectetuer}, \gls{diam}.

Acronyms: \gls{aeu}, \gls{afm}, \gls{anp}, \gls{cas},
\gls{cdg}, \gls{cea}, \gls{dia}.

\section{Next Use}

Regular entries: \gls{ac}, \gls{accumsan}, \gls{amet},
\gls{bibendum}, \gls{consectetuer}, \gls{diam}.

Acronyms: \gls{aeu}, \gls{afm}, \gls{anp}, \gls{cas},
\gls{cdg}, \gls{cea}, \gls{dia}.

Full form: \acrfull{aeu}.

\printglossary[style=mcolindex]

\end{document}

得出的结果为:

文件图像

或者,您可以使用扩展包glossaries-extra。这使用不同的缩写机制,缩写使用\newabbreviation(与 相同的语法\newacronym)定义。缩写样式使用\setabbreviationstyle[类别]{样式名称}。为了便于转换,被重新定义为\newacronym,这意味着需要用 来设置样式\newabbreviationcategory=acronym\setabbreviationstyle[acronym]{样式名称}。首次使用时long-short,将使用缩写样式\glsfirstlongdefaultfont作为长格式字体。这使得文档更加简单:

\documentclass{article}

\usepackage[colorlinks]{hyperref}
\usepackage{glossaries-extra}
\usepackage{glossary-mcols}

\makeglossaries

\renewcommand{\glsfirstlongdefaultfont}[1]{\emph{#1}}

\setabbreviationstyle[acronym]{long-short}

\loadglsentries{example-glossaries-brief}

\loadglsentries{example-glossaries-acronym}

\begin{document}

\section{First Use}

Regular entries: \gls{ac}, \gls{accumsan}, \gls{amet},
\gls{bibendum}, \gls{consectetuer}, \gls{diam}.

Acronyms: \gls{aeu}, \gls{afm}, \gls{anp}, \gls{cas},
\gls{cdg}, \gls{cea}, \gls{dia}.

\section{Next Use}

Regular entries: \gls{ac}, \gls{accumsan}, \gls{amet},
\gls{bibendum}, \gls{consectetuer}, \gls{diam}.

Acronyms: \gls{aeu}, \gls{afm}, \gls{anp}, \gls{cas},
\gls{cdg}, \gls{cea}, \gls{dia}.

Full form: \glsxtrfull{aeu}.

\printglossary[style=mcolindex]

\end{document}

这会产生类似的结果,除了最后的明确完整形式,在这种情况下也有斜体长形式。

文件图像

请注意,\setabbreviationstyle您需要使用\glsxtrfullnot \acrfull。同样,\glsxtrshortinstead of\acrshort\glsxtrlongInstead of \acrlong。这些\acr...命令旨在与基本glossaries缩写机制一起使用,不允许进行glossaries-extra样式设置。

答案2

用户指南(第 110 页)

\glstextformat{< 文本 >}

例如,要使所有链接文本以无衬线字体显示,请执行以下操作:

\renewcommand*{\glstextformat}[1]{\textsf{#1}}

在你的情况下,你可以使用\glstextformat将所有链接文本定义为斜体。这是一个 MWE

\documentclass{article}

\usepackage{glossaries} 

\newacronym{svm}{SVM}{support vector machine}
\makeglossaries
\renewcommand{\glstextformat}[1]{\textit{#1}}

\begin{document}
    blah balh blah \gls{svm} some more text and then \gls{svm}

    \printglossaries
\end{document}

相关内容