我正在使用词汇表包来制作我的首字母缩略词列表。我用西班牙语写作,但有些首字母缩略词是英文的。我希望它们显示如下:西班牙语描述 - 英文长(短) -
我考虑在词汇表中使用描述标签来包含西班牙语描述。但是我不知道如何修改 \acX 宏才能正确显示首字母缩略词(第一次显示全部,下一次只显示缩写,等等)。
任何帮助或提示都非常受欢迎。
CU
编辑:之后使用词汇表包查找德语文档中的英文缩写我需要将其修改为如下格式:
OtherLanguage_long (短, 长) 长 (短)
IE。 --> 服务质量 (QoS,服务质量) 互联网协议 (IP)
编辑2:问题解决了……至少我是这么认为的。我创建了两个标记,一个表示复数,另一个表示单数。
\documentclass{article}
\usepackage[acronym, toc, shortcuts]{glossaries}
\usepackage{etoolbox}
\newtoks\customtoksingular
\newtoks\customtokplural
\renewcommand*{\newacronymhook}{%
\edef\dosetkeys{\noexpand\setkeys{glossentry}{user1={},\the\glskeylisttok}}%
\dosetkeys
\ifcsempty{@glo@useri}%
{%
%\expandafter\customtoksingular\expandafter{\the\glsshorttok\space(\the\glslongtok)}%
\expandafter\customtoksingular\expandafter{\noexpand\acrfullformat{\the\glslongtok}{\the\glsshorttok}}%
}%
{%
\edef\custom{\csexpandonce{@glo@useri}\space(\the\glsshorttok, \the\glslongtok)}%
\expandafter\customtoksingular\expandafter{\custom}%
}%
\ifcsempty{@glo@userii}%
{%
%\expandafter\customtoksingular\expandafter{\the\glsshorttok\space(\the\glslongtok)}%
\expandafter\customtokplural\expandafter{\noexpand\acrfullformat
{\noexpand\glsentrylongpl{\the\glslabeltok}}%
{\noexpand\glsentryshortpl{\the\glslabeltok}}}
}%
{%
\edef\custom{\csexpandonce{@glo@userii}\space(\the\glsshorttok, \the\glslongtok\noexpand\acrpluralsuffix)}%
\expandafter\customtokplural\expandafter{\custom}%
}%
}
\newcommand*{\custompostdesc}[1]{%
\ifcsempty{glo@#1@useri}{}{ (\glsentryuseri{#1})}%
}
\renewcommand*{\CustomAcronymFields}{%
user1={},%
name={\the\glsshorttok},%
description={\the\glslongtok\noexpand\custompostdesc{\the\glslabeltok}},%
first={\the\customtoksingular},%
firstplural={\the\customtokplural},%
% first={\the\glslongtok\space(\the\customtoksingular)},%
%firstplural={\the\glslongtok\noexpand\acrpluralsuffix\space (the\customtoksingular},%
text={\the\glsshorttok},%
plural={\the\glsshorttok\noexpand\acrpluralsuffix}%
}
\SetCustomStyle
\makeglossaries
\newacronym[user1=interfaz de programaci\'{o}n de la aplicaci\'{o}n, user2=interfaces de programaci\'{o}n de la aplicaci\'{o}n]{api}{API}{Application Programming Interface}
\newacronym{aa}{AA}{Another Acronym}
\begin{document}
First use: Las \acp{api} .... Subsequent use: \acp{api}
\glsresetall{}
First use: Las \ac{api} .... Subsequent use: \ac{api}
First use: \gls{aa}. Subsequent use: \gls{aa}.
\printglossary[type=\acronymtype]
\end{document}
答案1
我建议你升级到最新版本glossaries
(撰写本文时为 v4.01)因为它更加灵活。以下是使用 v4.01 的示例:
\documentclass[spanish,english]{article}
\usepackage{babel}
\usepackage{etoolbox}
\usepackage[acronym,toc,shortcuts]{glossaries}
\makeglossaries
% Add new key for long Spanish form:
\glsaddkey
{longsp}% key
{}% default value
{\glsentrylongsp}% new command analogous to \glsentrylong
{\Glsentrylongsp}% new command analogous to \Glsentrylong
{\acrlongsp}% new command analogous to \acrlong
{\Acrlongsp}% new command analogous to \Acrlong
{\ACRlongsp}% new command analogous to \ACRlong
% Add new key for plural long Spanish form:
\glsaddkey
{longplsp}% key
{}% default value
{\glsentrylongplsp}% new command analogous to \glsentrylongpl
{\Glsentrylongplsp}% new command analogous to \Glsentrylongpl
{\acrlongplsp}% new command analogous to \acrlongpl
{\Acrlongplsp}% new command analogous to \Acrlongpl
{\ACRlongplsp}% new command analogous to \ACRlongpl
% Provide conditional to test if longsp/longplsp has been set
\newcommand*{\glsifhaslongsp}[3]{%
\ifcsempty{glo@#1@longsp}{#3}{#2}%
}
\newcommand*{\glsifhaslongplsp}[3]{%
\ifcsempty{glo@#1@longplsp}{#3}{#2}%
}
% Set up custom acronym style:
\renewcommand*{\CustomAcronymFields}{%
name={\the\glsshorttok},
description={\the\glslongtok},%
}
% Set the display style for acronyms (used by commands like \gls, \glspl, \ac, \acp or \glsdisp)
\renewcommand*\SetCustomDisplayStyle[1]{%
\defglsentryfmt[#1]{%
\ifdefempty\glscustomtext
{% \glsdisp not used
\ifglsused\glslabel
{% subsequent use
\glsifplural
{% plural
\glscapscase
{% subsequent, plural, no case change
\glsentryshortpl{\glslabel}\glsinsert%
}%
{% subsequent, plural, first letter upper case
\Glsentryshortpl{\glslabel}\glsinsert%
}%
{% subsequent, plural, all caps
\MakeTextUppercase{\glsentryshortpl{\glslabel}\glsinsert}%
}%
}%
{% singular
\glscapscase
{% subsequent, singular, no case change
\glsentryshort{\glslabel}\glsinsert%
}%
{% subsequent, singular, first letter upper case
\Glsentryshort{\glslabel}\glsinsert%
}%
{% subsequent, singular, all caps
\MakeTextUppercase{\glsentryshort{\glslabel}\glsinsert}%
}%
}%
}%
{% first use
\glsifplural
{% plural
\glsifhaslongplsp\glslabel
{% first use, plural, has Spanish long form
\glscapscase
{% first use, plural, Spanish, no case change
\glsentrylongplsp{\glslabel}\glsinsert\space
(\glsentryshortpl{\glslabel},\space
\glsentrylongpl{\glslabel})%
}%
{% first use, plural, Spanish, first letter upper case
\Glsentrylongplsp{\glslabel}\glsinsert\space
(\glsentryshortpl{\glslabel},\space
\glsentrylongpl{\glslabel})%
}%
{% first use, plural, Spanish, all caps
\MakeTextUppercase{\glsentrylongplsp{\glslabel}\glsinsert\space
(\glsentryshortpl{\glslabel},\space
\glsentrylongpl{\glslabel})}%
}%
}%
{% first use, plural, doesn't have Spanish long form
\glscapscase
{% first use, plural, no Spanish, no case change
\glsentrylongpl{\glslabel}\glsinsert\space
(\glsentryshortpl{\glslabel})%
}%
{% first use, plural, no Spanish, first letter upper case
\Glsentrylongpl{\glslabel}\glsinsert\space
(\glsentryshortpl{\glslabel})%
}%
{% first use, plural, no Spanish, all caps
\MakeTextUppercase{\glsentrylongpl{\glslabel}\glsinsert\space
(\glsentryshortpl{\glslabel})}%
}%
}%
}%
{% singular
\glsifhaslongsp\glslabel
{% first use, singular, has Spanish long form
\glscapscase
{% first use, singular, Spanish, no case change
\glsentrylongsp{\glslabel}\glsinsert\space
(\glsentryshort{\glslabel},\space
\glsentrylong{\glslabel})%
}%
{% first use, singular, Spanish, first letter upper case
\Glsentrylongsp{\glslabel}\glsinsert\space
(\glsentryshort{\glslabel},\space
\glsentrylong{\glslabel})%
}%
{% first use, singular, Spanish, all caps
\MakeTextUppercase{\glsentrylongsp{\glslabel}\glsinsert\space
(\glsentryshort{\glslabel},\space
\glsentrylong{\glslabel})}%
}%
}%
{% first use, singular, doesn't have Spanish long form
\glscapscase
{% first use, singular, no Spanish, no case change
\glsentrylong{\glslabel}\glsinsert\space
(\glsentryshort{\glslabel})%
}%
{% first use, singular, no Spanish, first letter upper case
\Glsentrylong{\glslabel}\glsinsert\space
(\glsentryshort{\glslabel})%
}%
{% first use, singular, no Spanish, all caps
\MakeTextUppercase{\glsentrylong{\glslabel}\glsinsert\space
(\glsentryshort{\glslabel})}%
}%
}%
}%
}%
}%
{% \glsdisp used
\glscustomtext
}%
}%
}
\SetCustomStyle
% Define a new glossary style that checks for the existence of
% the longsp field.
\newglossarystyle{listsp}{%
\setglossarystyle{list}% base style on the list style
\renewcommand*{\glossentry}[2]{%
\item[\glsentryitem{##1}%
\glstarget{##1}{\glossentryname{##1}}]
\glossentrydesc{##1}%
\glsifhaslongsp{##1}{\space(\glsentrylongsp{##1})}{}%
\glspostdescription\space ##2}%
}
\newacronym
[longsp=interfaz de programaci\'{o}n de la aplicaci\'{o}n,
longplsp=interfaces de programaci\'{o}n de la aplicaci\'{o}n
]{api}{API}{Application Programming Interface}
\newacronym{aa}{AA}{Another Acronym}
\begin{document}
First use: Las \acp{api} .... Subsequent use: \acp{api}
\glsresetall
First use: Las \ac{api} .... Subsequent use: \ac{api}
First use: \gls{aa}. Subsequent use: \gls{aa}.
\printglossary[type=\acronymtype,style=listsp]
\end{document}
得出的结果为:
编辑:
如果您升级到最新版本 (v4.02,2013/12/05),则可以更轻松地定义新的首字母缩略词样式并匹配该样式。(尽管也可以定义不匹配的首字母缩略词样式,就像不使用脚注的预定义样式\acf
一样。)以下是使用 v4.02 代码重写的上述示例:footnote
\acr
\documentclass[spanish,english]{article}
\usepackage{babel}
\usepackage{etoolbox}
\usepackage[acronym,toc,shortcuts]{glossaries}
\makeglossaries
% Add new key for long Spanish form:
\glsaddkey
{longsp}% key
{}% default value
{\glsentrylongsp}% new command analogous to \glsentrylong
{\Glsentrylongsp}% new command analogous to \Glsentrylong
{\acrlongsp}% new command analogous to \acrlong
{\Acrlongsp}% new command analogous to \Acrlong
{\ACRlongsp}% new command analogous to \ACRlong
% Add new key for plural long Spanish form:
\glsaddkey
{longplsp}% key
{}% default value
{\glsentrylongplsp}% new command analogous to \glsentrylongpl
{\Glsentrylongplsp}% new command analogous to \Glsentrylongpl
{\acrlongplsp}% new command analogous to \acrlongpl
{\Acrlongplsp}% new command analogous to \Acrlongpl
{\ACRlongplsp}% new command analogous to \ACRlongpl
% Provide conditional to test if longsp/longplsp has been set
\newcommand*{\glsifhaslongsp}[3]{%
\ifcsempty{glo@#1@longsp}{#3}{#2}%
}
\newcommand*{\glsifhaslongplsp}[3]{%
\ifcsempty{glo@#1@longplsp}{#3}{#2}%
}
% Define new acronym style:
\newacronymstyle{spanish}
{% base the display style on 'long-short'
\GlsUseAcrEntryDispStyle{long-short}%
}%
{% base the definitions on 'long-short'
\GlsUseAcrStyleDefs{long-short}%
% Make some custom modifications for the first use display.
% Singular, no case change:
\renewcommand*{\genacrfullformat}[2]{%
\glsifhaslongsp{##1}%
{% has Spanish version:
\glsentrylongsp{##1}##2\space
(\firstacronymfont{\glsentryshort{##1}}, \glsentrylong{##1})%
}%
{%
\glsentrylong{##1}##2\space
(\firstacronymfont{\glsentryshort{##1}})%
}%
}%
% Singular, first letter upper case:
\renewcommand*{\Genacrfullformat}[2]{%
\glsifhaslongsp{##1}%
{% has Spanish version:
\Glsentrylongsp{##1}##2\space
(\firstacronymfont{\glsentryshort{##1}}, \glsentrylong{##1})%
}%
{%
\Glsentrylong{##1}##2\space
(\firstacronymfont{\glsentryshort{##1}})%
}%
}%
% Plural, no case change:
\renewcommand*{\genplacrfullformat}[2]{%
\glsifhaslongplsp{##1}%
{% has Spanish version:
\glsentrylongplsp{##1}##2\space
(\firstacronymfont{\glsentryshortpl{##1}}, \glsentrylongpl{##1})%
}%
{%
\glsentrylongpl{##1}##2\space
(\firstacronymfont{\glsentryshortpl{##1}})%
}%
}%
% Plural, first letter upper case:
\renewcommand*{\Genplacrfullformat}[2]{%
\glsifhaslongplsp{##1}%
{% has Spanish version:
\Glsentrylongplsp{##1}##2\space
(\firstacronymfont{\glsentryshortpl{##1}}, \glsentrylongpl{##1})%
}%
{%
\Glsentrylongpl{##1}##2\space
(\firstacronymfont{\glsentryshortpl{##1}})%
}%
}%
}
% switch to the new style:
\setacronymstyle{spanish}
% Define a new glossary style that checks for the existence of
% the longsp field.
\newglossarystyle{listsp}{%
\setglossarystyle{list}% base style on the list style
\renewcommand*{\glossentry}[2]{%
\item[\glsentryitem{##1}%
\glstarget{##1}{\glossentryname{##1}}]
\glossentrydesc{##1}%
\glsifhaslongsp{##1}{\space(\glsentrylongsp{##1})}{}%
\glspostdescription\space ##2}%
}
\newacronym
[longsp=interfaz de programaci\'{o}n de la aplicaci\'{o}n,
longplsp=interfaces de programaci\'{o}n de la aplicaci\'{o}n
]{api}{API}{Application Programming Interface}
\newacronym{aa}{AA}{Another Acronym}
\begin{document}
First use: Las \acp{api} .... Subsequent use: \acp{api}
\glsresetall
First use: Las \ac{api} .... Subsequent use: \ac{api}
First use: \gls{aa}. Subsequent use: \gls{aa}.
Full form: \acf{api}, \acf{aa}.
\printglossary[type=\acronymtype,style=listsp]
\end{document}
得出的结果为:
编辑2:
在回答@cacamailg 关于仅使用非英语版本的评论时,最简单的方法就是定义一组检查第一次使用标志的命令,如下所示:
\newcommand*{\acfor}[2][]{%
\ifglsused{#2}%
{\acrshort[#1]{#2}}%
{\acrlongsp[#1]{#2} (\acrshort[#1]{#2})\glsunset{#2}}%
}
\newcommand*{\Acfor}[2][]{%
\ifglsused{#2}%
{\Acrshort[#1]{#2}}%
{\Acrlongsp[#1]{#2} (\acrshort[#1]{#2})\glsunset{#2}}%
}
\newcommand*{\acplfor}[2][]{%
\ifglsused{#2}%
{\acrplshort[#1]{#2}}%
{\acrlongplsp[#1]{#2} (\acrshortpl[#1]{#2})\glsunset{#2}}%
}
\newcommand*{\Acplfor}[2][]{%
\ifglsused{#2}%
{\Acrshortpl[#1]{#2}}%
{\Acrlongplsp[#1]{#2} (\acrshortpl[#1]{#2})\glsunset{#2}}%
}
然后你可以做类似的事情:
\acfor{api}. Next use: \acfor{api}.
这有一些限制,例如,您不能使用诸如之类的命令所使用的最终插入可选参数\gls
。
答案2
的新版本\acfor{}
。在文本中,您可以使用它在第一次运行和其他运行中\acfor[Televisão]{TV}
获得结果。这将生成指向条目的链接,定义如下:Televisão (TV)
TV
Television
\newacronym{TV}{TV}{Television}
如果没有提供第一个参数,\acfor{TV}
则给出电视(电视)在第一轮和TV
其他轮次中。
\usepackage{xparse}
% A version of '\ac{}' to be used in foreign texts
\DeclareDocumentCommand{\acfor}{ o m }{%
\ifglsused{#2}{% verifies if entry has been marked as used
\glslink{#2}{\glsentryshort{#2}}% if yes, use short version
}{% else
\IfValueTF{#1}{% verifies if there is a label
\glslink{#2}{#1\space(\glsentryshort{#2})}% if yes, use and link it
\glsunset{#2}% mark as used
}{% else
\glslink{#2}{\emph{\glsentrylong{#2}}\space(\glsentryshort{#2})}% emphasize the foreign text
\glsunset{#2}% mark as used
}%
}%
}