词汇表-额外:如何在使用 bib2gls 时应用自定义缩写样式

词汇表-额外:如何在使用 bib2gls 时应用自定义缩写样式

我正在一个大文档上使用glossaries-extrabib2gls选项(我尝试使用标准方法,\makeglossaries但出现了写入缓冲区不足的错误)。

我的问题是:使用 时makeglossaries,缩写样式withdescwithoutdesc正确应用,因此首次使用时,会打印短格式和长格式。但使用 时情况并非如此bib2gls:仅打印短格式。

MWE(由于我正在创建的文档非常大,所以我选择了这个):

\documentclass{article}

\usepackage{polyglossia}
\setdefaultlanguage{spanish}

\usepackage[svgnames]{xcolor}
\usepackage{filecontents}

\usepackage[spanish]{varioref}
\usepackage{hyperref}
\usepackage{cleveref}

\hypersetup{
  colorlinks=true,
  citecolor=Crimson,
  linkcolor=Crimson,
  urlcolor=Crimson
}

\usepackage[record,acronym,postdot]{glossaries-extra}

\begin{filecontents}{terms.bib}
% Encoding: UTF-8
@entry{duck,
    name = {duck},
    category = {withdesc},
    description = {a waterbird with webbed feet}
}

@entry{parrot,
    name = {parrot},
    category = {withdesc},
    description = {mainly tropical bird with bright plumage}
}
\end{filecontents}
\GlsXtrLoadResources[src={terms}]

\begin{filecontents}{acros.bib}
% Encoding: UTF-8
@acronym{GNU,
    user1 = {{\textit{GNU No es Unix}\, en español}},
    plural = {{GNUs}},
    short = {{GNU}},
    category = {{withoutdesc}},
    long = {{GNU is Not Unix}}
}

@acronym{TTL,
    plural = {TTLs},
    short = {TTL},
    category = {withdesc},
    long = {{Time To Live}},
    description = {{Some value}}
}
\end{filecontents}
\GlsXtrLoadResources[src={acros}]

\setabbreviationstyle[withdesc]{long-short-user-desc}
\setabbreviationstyle[withoutdesc]{long-short-user}

\newglossarystyle{customAbbrevList}{%
    \setglossarystyle{listhypergroup}%
    \renewcommand*{\glossentry}[2]{%
        \item[\glsentryitem{##1}%
            \glstarget{##1}{\glossentryname{##1}}]%
        \glsifcategory{##1}{withoutdesc}{%
             --- \glsentrylong{##1}\ifglshasfield{\glsxtruserfield}{\glscurrententrylabel}{ (\!\glscurrentfieldvalue)}{}%
        }{%
            \mbox{}\par\nobreak\csuse{@afterheading}%
            \glossentrydesc{##1}%
        }%
        \glspostdescription\space ##2%
    }%
}

\newglossarystyle{customGloList}{%
    \setglossarystyle{listhypergroup}%
    \renewcommand*{\glossentry}[2]{%
        \item[\glsentryitem{##1}%
            \glstarget{##1}{\glossentryname{##1}}]%
        \glsifcategory{##1}{withoutdesc}%
        { ---}%
        {%
            {\mbox{}\par\nobreak\csuse{@afterheading}%
            \glossentrydesc{##1}}\glspostdescription%
        }%
        \space ##2%
    }%
}

\addto\captionsspanish{%
    \renewcommand*{\acronymname}{Abreviaturas}
    \renewcommand*{\glossaryname}{Glosario}
}

\begin{document}

A \gls{duck} and a \gls{parrot}. Lots of \glspl{duck}. Also, this is \gls{GNU}.

Again: a \gls{duck}, and a \gls{parrot} are part of \gls{GNU}.

We have some \gls{TTL}; again, \gls{TTL}.

\printunsrtglossary[type=main,style=customGloList]
\printunsrtglossary[type=acronym,style=customAbbrevList]

\end{document}

使用以下方法编译上述文档的输出:

xelatex doc.tex
bib2gls doc
xelatex doc.tex

这是:

编译文档的输出

我应该怎么做才能在第一次使用时正确打印术语的长格式和短格式[例如:生存时间(TTL)]?

答案1

必须在定义缩写之前设置缩写样式。由于它们是在.glstex输入的文件中定义的,因此\GlsXtrLoadResources需要在该命令之前设置它们:

\documentclass{article}

\usepackage{polyglossia}
\setdefaultlanguage{spanish}

\usepackage[svgnames]{xcolor}
\usepackage{filecontents}

\usepackage[spanish]{varioref}
\usepackage{hyperref}
\usepackage{cleveref}

\hypersetup{
  colorlinks=true,
  citecolor=Crimson,
  linkcolor=Crimson,
  urlcolor=Crimson
}

\usepackage[record,acronym,postdot]{glossaries-extra}

\begin{filecontents}{terms.bib}
% Encoding: UTF-8
@entry{duck,
    name = {duck},
    category = {withdesc},
    description = {a waterbird with webbed feet}
}

@entry{parrot,
    name = {parrot},
    category = {withdesc},
    description = {mainly tropical bird with bright plumage}
}
\end{filecontents}
\GlsXtrLoadResources[src={terms}]

\begin{filecontents}{acros.bib}
% Encoding: UTF-8
@acronym{GNU,
    user1 = {{\textit{GNU No es Unix}\, en español}},
    plural = {{GNUs}},
    short = {{GNU}},
    category = {{withoutdesc}},
    long = {{GNU is Not Unix}}
}

@acronym{TTL,
    plural = {TTLs},
    short = {TTL},
    category = {withdesc},
    long = {{Time To Live}},
    description = {{Some value}}
}
\end{filecontents}

\setabbreviationstyle[withdesc]{long-short-user-desc}
\setabbreviationstyle[withoutdesc]{long-short-user}

\GlsXtrLoadResources[src={acros}]

\newglossarystyle{customAbbrevList}{%
    \setglossarystyle{listhypergroup}%
    \renewcommand*{\glossentry}[2]{%
        \item[\glsentryitem{##1}%
            \glstarget{##1}{\glossentryname{##1}}]%
        \glsifcategory{##1}{withoutdesc}{%
             --- \glsentrylong{##1}\ifglshasfield{\glsxtruserfield}{\glscurrententrylabel}{ (\!\glscurrentfieldvalue)}{}%
        }{%
            \mbox{}\par\nobreak\csuse{@afterheading}%
            \glossentrydesc{##1}%
        }%
        \glspostdescription\space ##2%
    }%
}

\newglossarystyle{customGloList}{%
    \setglossarystyle{listhypergroup}%
    \renewcommand*{\glossentry}[2]{%
        \item[\glsentryitem{##1}%
            \glstarget{##1}{\glossentryname{##1}}]%
        \glsifcategory{##1}{withoutdesc}%
        { ---}%
        {%
            {\mbox{}\par\nobreak\csuse{@afterheading}%
            \glossentrydesc{##1}}\glspostdescription%
        }%
        \space ##2%
    }%
}

\addto\captionsspanish{%
    \renewcommand*{\acronymname}{Abreviaturas}
    \renewcommand*{\glossaryname}{Glosario}
}

\begin{document}

A \gls{duck} and a \gls{parrot}. Lots of \glspl{duck}. Also, this is \gls{GNU}.

Again: a \gls{duck}, and a \gls{parrot} are part of \gls{GNU}.

We have some \gls{TTL}; again, \gls{TTL}.

\printunsrtglossary[type=main,style=customGloList]
\printunsrtglossary[type=acronym,style=customAbbrevList]

\end{document}

文件图像

相关内容