![如何结合缩略词和词汇表](https://linux22.com/image/234092/%E5%A6%82%E4%BD%95%E7%BB%93%E5%90%88%E7%BC%A9%E7%95%A5%E8%AF%8D%E5%92%8C%E8%AF%8D%E6%B1%87%E8%A1%A8.png)
我正在使用这个glossaries
包。
我有一个缩写词(例如 API),应该在词汇表中进行解释。每次出现时都应将其链接到词汇表,但第一次出现时应这样写:
这是应用程序编程接口(API)的测试。
这是 API 的第二次出现。
缩略词
API应用程序接口
词汇表
API应用程序编程接口 (API) 是一组特定的规则和规范,软件程序可以遵循这些规则和规范来访问和使用实现该 API 的另一个特定软件程序提供的服务和资源
我怎样才能做到这一点?
答案1
一个简单的例子
\documentclass{article}
\usepackage[acronym]{glossaries}
\makeglossaries
%from documentation
%\newacronym[⟨key-val list⟩]{⟨label ⟩}{⟨abbrv ⟩}{⟨long⟩}
%above is short version of this
% \newglossaryentry{⟨label ⟩}{type=\acronymtype,
% name={⟨abbrv ⟩},
% description={⟨long⟩},
% text={⟨abbrv ⟩},
% first={⟨long⟩ (⟨abbrv ⟩)},
% plural={⟨abbrv ⟩\glspluralsuffix},
% firstplural={⟨long⟩\glspluralsuffix\space (⟨abbrv ⟩\glspluralsuffix)},
% ⟨key-val list⟩}
\newacronym{cd}{CD}{compact disk}
\begin{document}
\noindent
First use \gls{cd}\\
subsequent \gls{cd}
\printglossaries
\end{document}
词汇表支持多种命名法,因此你仍然可以使用类似这样的术语
\newglossaryentry{tree}{name={tree},
description={trees are the better humans}}
并且因为在上面的例子中类型被自动设置为“main”,它会给你一个名为“Glossary”的第二个列表
\documentclass{article}
\usepackage[acronym]{glossaries}
\makeglossaries
%from documentation
%\newacronym[⟨key-val list⟩]{⟨label ⟩}{⟨abbrv ⟩}{⟨long⟩}
%above is short version of this
% \newglossaryentry{⟨label ⟩}{type=\acronymtype,
% name={⟨abbrv ⟩},
% description={⟨long⟩},
% text={⟨abbrv ⟩},
% first={⟨long⟩ (⟨abbrv ⟩)},
% plural={⟨abbrv ⟩\glspluralsuffix},
% firstplural={⟨long⟩\glspluralsuffix\space (⟨abbrv ⟩\glspluralsuffix)},
% ⟨key-val list⟩}
\newacronym{cd}{CD}{compact disk}
\newglossaryentry{tree}{name={tree},
description={trees are the better humans}}
\begin{document}
\noindent
First use \gls{cd}\\
subsequent \gls{cd}
Nomenclature \gls{tree}
\printglossaries
\end{document}
为了最终得到你想要的东西,你可以使用
\documentclass{article}
\usepackage{hyperref}
\usepackage[acronym]{glossaries}
\makeglossaries
%from documentation
%\newacronym[⟨key-val list⟩]{⟨label ⟩}{⟨abbrv ⟩}{⟨long⟩}
%above is short version of this
% \newglossaryentry{⟨label ⟩}{type=\acronymtype,
% name={⟨abbrv ⟩},
% description={⟨long⟩},
% text={⟨abbrv ⟩},
% first={⟨long⟩ (⟨abbrv ⟩)},
% plural={⟨abbrv ⟩\glspluralsuffix},
% firstplural={⟨long⟩\glspluralsuffix\space (⟨abbrv ⟩\glspluralsuffix)},
% ⟨key-val list⟩}
%\newacronym{api}{API}{Application Programming Interface }
%%% The glossary entry the acronym links to
\newglossaryentry{apig}{name={API},
description={An Application Programming Interface (API) is a particular set
of rules and specifications that a software program can follow to access and
make use of the services and resources provided by another particular software
program that implements that API}}
%%% define the acronym and use the see= option
\newglossaryentry{api}{type=\acronymtype, name={API}, description={Application
Programming Interface}, first={Application
Programming Interface (API)\glsadd{apig}}, see=[Glossary:]{apig}}
\begin{document}
\noindent
First use \gls{api}\\
subsequent \gls{api}
\newpage
\printglossary[type=\acronymtype]
%%% \newpage just to demonstrate that links are correct
\newpage
\printglossary[type=main]
\end{document}
你可以把它变成自定义命令,更方便,像这样:
% Command to create a glossary entry with correspondent acronym.
% Args : 1: acronym/name, 2: long name, 3: description
\newcommand{\newglossaryentrywithacronym}[3]{
%%% The glossary entry the acronym links to
\newglossaryentry{#1_gls}{
name={#1},
long={#2},
description={#3}
}
% Acronym pointing to glossary
\newglossaryentry{#1}{
type=\acronymtype,
name={#1},
description={#2},
first={#2 (#1)\glsadd{#1_gls}},
see=[Glossary:]{#1_gls}
}
}
像这样调用它:
\newglossaryentrywithacronym{API}{Application Programming Interface}{
An Application Programming Interface (API) is a particular set of rules and
specifications that a software program can follow to access and make use of
the services and resources provided by another particular software program
that implements that API.
}
答案2
我的解决方案如下:
\newglossaryentry{api}
{
name={API},
description={An Application Programming Interface (API) is a particular set
of rules and specifications that a software program can follow to access and make use of the services and resources provided by another particular software program that implements that API},
first={Application Programming Interface (API)},
long={Application Programming Interface}
}
所以我不必将其分成两部分,一部分用于词汇表,一部分用于首字母缩略词部分。我认为这是一个干净的解决方案。
干杯 :-)
编辑:但如果您真的想分成两个部分,那么 OSHis 解决方案是完美的。
答案3
我已经扩展了这个非常非常好的例子(在此表示感谢 ;) ),这样就不再需要手动添加词汇表条目了:
\newglossaryentry{APIG}{
name=\glslink{API}{Application Programming Interface (\gls{API})},
description={
Application Programming Interface Desc}
}
\newglossaryentry{API}{
type=\acronymtype,
name=API,
first=Application Programming Interface (API),
firstplural={Application Programming Interfaces (API's)},
see=[Glossary:]{\gls{APIG}},
description=\glslink{APIG}{Application Programming Interfaces}
}
主要关键是\glslink{APIG}{Application Programming Interfaces}
。每次添加 (API) 缩写时,它都会“添加”词汇表条目。
答案4
我来这里是为了尝试做类似的事情,但只使用一个条目,而不单独使用词汇表条目和首字母缩略词。对于所有寻找相同内容的人,这是我的解决方案。
它的作用是:
- 单次入境在词汇表中
- 条目包含全名和缩写
- 第一的使用将显示名称 + 缩写。
- 后续用途将显示仅缩写。
代码片段:
\newglossaryentry{API}
{
name={Application Programming Interface (API)},
description={An Application Programming Interface (API) is a particular set of rules and specifications that a software program can follow to access and make use of the services and resources provided by another particular software program that implements that API},
first={Application Programming Interface (API)},
text={API}
}
“name”指定用于在词汇表中列出的名称。“text”指定引用条目时使用的文本,第一次使用时会被“first”覆盖。
外观:
完整示例:
\documentclass{article}
\usepackage{hyperref}
\usepackage[nonumberlist]{glossaries}
\makeglossaries
\newglossaryentry{API}
{
name={Application Programming Interface (API)},
description={An Application Programming Interface (API) is a particular set of rules and specifications that a software program can follow to access and make use of the services and resources provided by another particular software program that implements that API},
first={Application Programming Interface (API)},
text={API}
}
\begin{document}
\noindent
First use: \gls{API}\\
Subsequent: \gls{API}
\pagebreak
\printglossaries
\end{document}