我希望在使用描述环境浏览文档时继续定义术语,然后将所有这些术语(及其描述)收集到文档末尾的词汇表中。
词汇表包似乎是实现此目的的明显选择,但我看不出有办法在文档正文中列出条目描述。MWE 看起来像
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{blindtext}
\begin{document}
\tableofcontents{}
\section{Introduction}
\begin{description}
\item[Ontology] refers to a theory of what is real
\item[Epistemology] refers to a theory of knowledge
\end{description}
\section{Theory} \begin{description}
\item[Potato] is a class of root vegetables
\item[Reductionism] refers to the practice of reducing one set of ideas to another \end{description}
\section{Glossary of Terms}
\begin{description}
\item[Epistemology] refers to a theory of knowledge
\item[Ontology] refers to a theory of what is real
\item[Potato] is a class of root vegetables
\item[Reductionism] refers to the practice of reducing one set of ideas to another \end{description}
\end{document}
例如,来自 {description} 环境中的所有术语都会被收集、按字母顺序排列,并在术语表中重现它们的描述。
答案1
最简单的方法是创建一个包含定义的新文件。这可以让你更容易在编写文档时添加新术语,因为大多数文本编辑器允许一次打开多个文件,因此你可以直接切换到定义文件而不会丢失文档中的位置。
这里是definitions.tex
:
\newglossaryentry{ontology}{name={ontology},
description={refers to a theory of what is real}}
\newglossaryentry{epistemology}{name={epistemology},
description={refers to a theory of knowledge}}
\newglossaryentry{potato}{name={potato},
category={theory},
description={is a class of root vegetables}}
\newglossaryentry{reductionism}{name={reductionism},
category={theory},
description={refers to the practice of reducing one set
of ideas to another}}
如果您的定义跨越多个段落,则使用\longnewglossaryentry
:
\longnewglossaryentry{reductionism}{name={reductionism},category={theory}}
{refers to the practice of reducing one set
of ideas to another}
这是使用所有提供的定义的文档:
\documentclass{article}
\usepackage{glossaries-extra}
\loadglsentries{definitions}
\glssetcategoryattribute{general}{glossname}{firstuc}
\glssetcategoryattribute{theory}{glossname}{firstuc}
\newcommand{\printcategory}[1]{%
\printunsrtglossary*{%
\renewcommand{\glossarysection}[2][]{}%
\renewcommand{\printunsrtglossaryhandler}[1]{%
\glsifcategory{##1}{#1}{\glsxtrunsrtdo{##1}}{}%
}%
}%
}
\begin{document}
\tableofcontents
\section{Introduction}
\printcategory{general}
\section{Theory}
\printcategory{theory}
\printunsrtglossary[title={Glossary of Terms}]
\end{document}
如果调用该文档,myDoc.tex
那么文档构建就很简单:
pdflatex myDoc
这会按定义顺序列出词汇表中所有已定义的术语。如果您希望列表按顺序排列,则操作会更复杂。
这是另一种方法。将定义保存在文件中.bib
,例如definitions.bib
:
% Encoding: UTF-8
@entry{ontology,
name = {ontology},
description = {refers to a theory of what is real}
}
@entry{epistemology,
name = {epistemology},
description = {refers to a theory of knowledge}
}
@entry{potato,
name = {potato},
plural = {potatoes},
description = {is a class of root vegetables}
}
@entry{reductionism,
name = {reductionism},
description = {refers to the practice of reducing one set
of ideas to another}
}
同样,在两个窗口之间切换应该很简单,而不会丢失文档中的位置。文档现在是:
\documentclass{article}
\usepackage[record,% using bib2gls
postpunc=dot% put a full-stop after the descriptions in the glossary
]{glossaries-extra}
\GlsXtrLoadResources[
src={definitions},% entries in definitions.bib
name-case-change={firstuc}% convert the first character of `name` to uppercase and set `text` to the original value of `name`
]
\newcommand{\glossitem}[1]{\item[\glsentryname{#1}]
\glsadd{#1}\glsentrydesc{#1}.}
\begin{document}
\tableofcontents
\section{Introduction}
\begin{description}
\glossitem{epistemology}
\glossitem{ontology}
\end{description}
\section{Theory}
\begin{description}
\glossitem{potato}
\glossitem{reductionism}
\end{description}
\printunsrtglossary[title={Glossary of Terms}]
\end{document}
这样,您就可以更好地手动控制文档中不同部分的排序。主词汇表现在已排序,并包含词汇表中指示术语使用位置的位置(对于此简单文档,在所有情况下均为第 1 页)。
构建过程现在是:
pdflatex myDoc
bib2gls myDoc
pdflatex myDoc
如果您不想要位置,请使用资源选项save-locations=false
:
\GlsXtrLoadResources[
src={definitions},% entries in definitions.bib
name-case-change={firstuc},
save-locations=false
]
或使用nonumberlist
:
\printunsrtglossary[title={Glossary of Terms},nonumberlist]
默认情况下bib2gls
将根据文档语言排序(如果检测到),否则将根据默认语言环境排序。您可以指定特定语言。例如:
\GlsXtrLoadResources[
src={definitions},% entries in definitions.bib
name-case-change={firstuc},
sort={en-GB}
]
如果你想在文档的其他任何地方引用术语,你可以使用\gls{
标签}
,例如\gls{ontology}
,或者在句子开头\Gls
,例如。可以使用和\Gls{potato}
获得复数。如果您在 之前加载,则这些将变成指向主词汇表中相关行的超链接。\glspl
\Glspl
hyperref
glossaries-extra