当我开始写一本较长的书时,我最初只觉得需要作者索引。因此,我通过\index
和建立了索引\makeindex
,得到了所需的结果。
与此同时,我意识到如果能有额外的词汇表来解释缩写和技术术语就更好了。不出所料,我很快就发现了这个包glossaries
,它应该能满足要求。
我现在想知道,放弃我的作者索引并将其转换为另一个词汇表是否更好,这将产生与 当前相同的作者列表\makeindex
。事实上,这样的例子已经有人提出过(附加作者信息)。
我认为使用该软件包glossaries
对所有类型的索引都有潜在的好处 - 一旦在单独的位置(最好是在单独的文件中)定义了词汇表条目 - 与变体相比,书籍的源代码将更易于编辑且更易读\index
。然而,由于缺乏使用该软件包的经验glossaries
,我想向这里的专家询问,我glossaries
对作者索引的想法是否真的很好,或者我是否忽略了这种方法的一些潜在问题?
理想情况下,我会将各个词汇表的不同词汇表输入文件与我的 tex 文件放在同一个文件夹中,然后单独编辑(就像我的文献 bib 文件一样)。这可能吗?
提前致谢。
此致,
奥利
答案1
以下是根据以下示例改编的方法:bib2gls
(在“示例”一章中描述bib2gls
用户手册)。该文件people.bib
包含所有作者信息,.bib
格式如下:
% Encoding: UTF-8
@entry{dickens,
name={\sortname{Charles}{Dickens}},
text={Dickens},
description={English writer and social critic},
born={7 February 1812},
died={9 June 1870},
identifier={person}
}
@entry{chandler,
name={\sortname{Raymond}{Chandler}},
text={Chandler},
description={American-British novelist and screenwriter},
born={23 July 1888},
died={26 March 1959},
identifier={person}
}
@entry{hammett,
name={\sortname{Samuel Dashiell}{Hammett}},
first={\sortname{Dashiell}{Hammett}},
text={Hammett},
description={American author, screenwriter and political
activist},
born={27 May 1894},
died={10 January 1961},
identifier={person}
}
@entry{christie,
name={\sortname{Dame Agatha Mary Clarissa}{Christie}},
first={\sortname{Agatha}{Christie}},
text={Christie},
othername={Lady Mallowan},
description={English crime novelist and playwright},
born={15 September 1890},
died={12 January 1976},
identifier={person}
}
@entry{landon,
name={\sortname{Christopher Guy}{Landon}},
first={\sortname{Christopher}{Landon}},
text={Landon},
description={British novelist and screenwriter},
born={29 March 1911},
died={26 April 1961},
identifier={person}
}
@entry{tolkien,
name={\sortname{John Ronald Reuel}{Tolkien}},
first={\sortname{J.R.R.}{Tolkien}},
text={Tolkien},
description={English writer, poet, philologist, and
university professor},
born={3 January 1892},
died={2 September 1973},
identifier={person}
}
@entry{baum,
name={\sortname{Lyman Frank}{Baum}},
first={\sortname{L.~Frank}{Baum}},
text={Baum},
description={American author},
born={15 May 1856},
died={6 May 1919},
identifier={person}
}
@entry{mackenzie,
name={\sortname{Compton}{Mackenzie}},
text={Mackenzie},
description={English-born Scottish writer, cultural
commentator, raconteur and Scottish nationalist},
born={17 January 1883},
died={30 November 1972},
identifier={person}
}
@entry{maclean,
name={\sortname{Alistair}{MacLean}},
text={MacLean},
description={Scottish novelist},
born={21 April 1922},
died={2 February 1987},
identifier={person}
}
@entry{dick,
name={\sortname{Philip K.}{Dick}},
text={Dick},
description={American science fiction writer},
born={16 December 1928},
died={2 March 1982},
identifier={person}
}
@entry{story,
name={\sortname{Jack Trevor}{Story}},
text={Story},
description={British novelist},
born={30 March 1917},
died={5 December 1991},
identifier={person}
}
@entry{greene,
name={\sortname{Henry Graham}{Green}},
first={\sortname{Graham}{Greene}},
text={Green},
description={English novelist},
born={2 October 1904},
died={3 April 1991},
identifier={person}
}
(由于文件仅包含 ASCII 字符,因此这里编码行不是必需的,但无论如何,将其包含在内是一种很好的做法,否则bib2gls
将在解析数据之前搜索整个文件。)
这包含一个\sortname
需要定义的自定义命令。如果文档中未明确使用此命令,则可以使用在文件中提供它.bib
。@preamble
例如:
@preamble{"\providecommand{\sortname}[2]{#2, #1}"}
(为了姓,名字) 或者
@preamble{"\providecommand{\sortname}[2]{#1 #2}"}
(为了名字 姓)。为了方便起见,我决定提供两个.bib
文件来提供上述替代方案。以下是interpret-preamble.bib
:
% Encoding: UTF-8
@preamble{"\providecommand{\sortname}[2]{#2, #1}"}
(可以向中添加其他命令定义@preamble
,但此文件中没有条目。)同样,这里是nointerpret-preamble.bib
:
% Encoding: UTF-8
@preamble{"\providecommand{\sortname}[2]{#1 #2}"}
这是一个简单的文档,使用glossaries-extra
和bib2gls
列出中定义的所有作者people.bib
:
\documentclass{article}
\usepackage[record,% using bib2gls
nostyles,% don't load default styles
stylemods={tree},% patch styles and load glossary-tree.sty
style=indexgroup
]{glossaries-extra}
\GlsXtrLoadResources[
% instruct bib2gls to parse interpret-preamble.bib and people.bib:
src={interpret-preamble,people},
selection=all% select all entries
]
\begin{document}
\printunsrtglossary[title={Authors}]
\end{document}
如果文档被称为myDoc.tex
,那么构建过程与 非常相似bibtex
,但是bib2gls
使用方式如下:
pdflatex myDoc
bib2gls myDoc
pdflatex myDoc
该文件如下所示:
虽然我使用了indexgroup
,但没有显示任何字母组。要支持此词汇表样式,bib2gls
需要--group
(或-g
)选项:
pdflatex myDoc
bib2gls -g myDoc
pdflatex myDoc
bib2gls
有一个基本的 LaTeX 解释器,用于解析@preamble
,这就是它如何按姓氏排序(因为\sortname
被定义为,所以它扩展为姓,名字.)bib2gls
可以被指示不去解析,这为文档@preamble
提供了一种有用的定义方法,但为提供了不同的定义:\sortname
bib2gls
\documentclass{article}
\usepackage[record,% using bib2gls
nostyles,% don't load default styles
stylemods={tree},% patch styles and load glossary-tree.sty
style=index
]{glossaries-extra}
\GlsXtrLoadResources[
% provide definition of `\sortname` for the document
src={nointerpret-preamble},
interpret-preamble=false
]
\GlsXtrLoadResources[
% instruct bib2gls to parse interpret-preamble.bib and people.bib:
src={interpret-preamble,people},
selection=all% select all entries
]
\begin{document}
\printunsrtglossary[title={Authors}]
\end{document}
因此作者仍然按姓氏字母顺序排列,但显示名字 姓。
文件中的一些信息people.bib
已被忽略,因为bib2gls
总是忽略未知字段(在本例中为、 和born
)died
。如果这些字段在第一次使用之前在文档中定义,或者可以将它们别名为现有字段,则这些字段将被识别:othername
identifier
\GlsXtrLoadResources
\GlsXtrLoadResources[
% instruct bib2gls to parse interpret-preamble.bib and people.bib:
src={interpret-preamble,people},
field-aliases={% provide field aliases
identifier=category,
born=user1,
died=user2,
othername=user3},
selection=all% select all entries
]
设置这些别名后,可以挂接词汇表样式来显示额外信息:
\newcommand*{\glsxtrpostnameperson}{%
\ifglshasfield{user3}{\glscurrententrylabel}%
{\space(\glscurrentfieldvalue)}%
{}%
}
\newcommand*{\glsxtrpostdescperson}{%
\ifglshasfield{user1}{\glscurrententrylabel}
{% born
\space(\glscurrentfieldvalue\,--\,%
\ifglshasfield{user2}{\glscurrententrylabel}
{% died
\glscurrentfieldvalue
}%
{}%
)%
}%
{}%
}
还可以使用以下选项来获得按出生日期排序的辅助列表:
secondary={date:user1:bybirth},
date-field-locale=en-GB
完成 MWE:
\documentclass{article}
\usepackage[a4paper]{geometry}
\usepackage[record,% using bib2gls
nostyles,% don't load default styles
stylemods={tree},% patch styles and load glossary-tree.sty
style=indexgroup
]{glossaries-extra}
\GlsXtrLoadResources[
% provide definition of `\sortname` for the document
src={nointerpret-preamble},
interpret-preamble=false
]
\GlsXtrLoadResources[
% instruct bib2gls to parse interpret-preamble.bib and people.bib:
src={interpret-preamble,people},
field-aliases={% provide field aliases
identifier=category,
born=user1,
died=user2,
othername=user3},
secondary={date:user1:bybirth},
date-field-locale=en-GB,
selection=all% select all entries
]
\newcommand*{\glsxtrpostnameperson}{%
\ifglshasfield{user3}{\glscurrententrylabel}%
{\space(\glscurrentfieldvalue)}%
{}%
}
\newcommand*{\glsxtrpostdescperson}{%
\ifglshasfield{user1}{\glscurrententrylabel}
{% born
\space(\glscurrentfieldvalue\,--\,%
\ifglshasfield{user2}{\glscurrententrylabel}
{% died
\glscurrentfieldvalue
}%
{}%
)%
}%
{}%
}
\begin{document}
\printunsrtglossary[title={Authors (by name)}]
\printunsrtglossary[title={Authors (by birth)},type=bybirth]
\end{document}
使用bib2gls --group
,第一页是:
第二页是:
按日期排序时,组标题默认为 YYYY-MM。这可以更改。例如,只使用年份(定义之前\GlsXtrLoadResources
):
\newcommand{\bibglsdategroup}[7]{#1#4#7}
\newcommand{\bibglsdategrouptitle}[7]{#1}
可以在文档中引用作者。在下面修改后的 MWE 中,我删除了selection=all
,因此选择标准现在是默认的,selection=recorded and deps
这意味着选择所有记录的条目(使用类似 的命令引用\gls
)及其依赖项。
\documentclass{article}
\usepackage[a4paper]{geometry}
\usepackage[record,% using bib2gls
nostyles,% don't load default styles
stylemods={tree},% patch styles and load glossary-tree.sty
style=indexgroup
]{glossaries-extra}
\newcommand{\bibglsdategroup}[7]{#1#4#7}
\newcommand{\bibglsdategrouptitle}[7]{#1}
\GlsXtrLoadResources[
% provide definition of `\sortname` for the document
src={nointerpret-preamble},
interpret-preamble=false
]
\GlsXtrLoadResources[
% instruct bib2gls to parse interpret-preamble.bib and people.bib:
src={interpret-preamble,people},
field-aliases={% provide field aliases
identifier=category,
born=user1,
died=user2,
othername=user3},
secondary={date:user1:bybirth},
date-field-locale=en-GB
]
\newcommand*{\glsxtrpostnameperson}{%
\ifglshasfield{user3}{\glscurrententrylabel}%
{\space(\glscurrentfieldvalue)}%
{}%
}
\newcommand*{\glsxtrpostdescperson}{%
\ifglshasfield{user1}{\glscurrententrylabel}
{% born
\space(\glscurrentfieldvalue\,--\,%
\ifglshasfield{user2}{\glscurrententrylabel}
{% died
\glscurrentfieldvalue
}%
{}%
)%
}%
{}%
}
\begin{document}
\section{First Use}
\gls{greene}, \gls{story}, \gls{dick}, \gls{maclean},
\gls{mackenzie}, \gls{baum}, \gls{tolkien}, \gls{landon},
\gls{christie}, \gls{hammett}, \gls{chandler}, \gls{dickens}.
\section{Next Use}
\gls{greene}, \gls{story}, \gls{dick}, \gls{maclean},
\gls{mackenzie}, \gls{baum}, \gls{tolkien}, \gls{landon},
\gls{christie}, \gls{hammett}, \gls{chandler}, \gls{dickens}.
\printunsrtglossary[title={Authors (by name)}]
\printunsrtglossary[title={Authors (by birth)},type=bybirth]
\end{document}
第一次使用时会出现不一致的情况。这是因为只有部分条目有字段first
。例如:
@entry{christie,
name={\sortname{Dame Agatha Mary Clarissa}{Christie}},
first={\sortname{Agatha}{Christie}},
text={Christie},
othername={Lady Mallowan},
description={English crime novelist and playwright},
born={15 September 1890},
died={12 January 1976},
identifier={person}
}
所以第一次使用的时候会显示这个值,但是其他的只有这个text
字段,没有这个值first
,例如:
@entry{dickens,
name={\sortname{Charles}{Dickens}},
text={Dickens},
description={English writer and social critic},
born={7 February 1812},
died={9 June 1870},
identifier={person}
}
因此,在这种情况下,第一个使用值是从字段中获取的text
。如果从字段中获取,看起来会更一致name
。这可以通过以下选项实现:
replicate-fields={name={first}}
通过定义后链接钩子,可以在第一次使用时附加此人的其他姓名(如果提供):
\newcommand*{\glsxtrpostlinkperson}{%
\glsxtrifwasfirstuse
{%
\ifglshasfield{user3}{\glslabel}%
{\space(\glscurrentfieldvalue)}%
{}%
}%
{}%
}
完成 MWE:
\documentclass{article}
\usepackage[a4paper]{geometry}
\usepackage[colorlinks]{hyperref}
\usepackage[record,% using bib2gls
nostyles,% don't load default styles
stylemods={tree},% patch styles and load glossary-tree.sty
style=indexgroup
]{glossaries-extra}
\newcommand{\bibglsdategroup}[7]{#1#4#7}
\newcommand{\bibglsdategrouptitle}[7]{#1}
\GlsXtrLoadResources[
% provide definition of `\sortname` for the document
src={nointerpret-preamble},
interpret-preamble=false
]
\GlsXtrLoadResources[
% instruct bib2gls to parse interpret-preamble.bib and people.bib:
src={interpret-preamble,people},
field-aliases={% provide field aliases
identifier=category,
born=user1,
died=user2,
othername=user3},
replicate-fields={name={first}},
secondary={date:user1:bybirth},
date-field-locale=en-GB
]
\newcommand*{\glsxtrpostnameperson}{%
\ifglshasfield{user3}{\glscurrententrylabel}%
{\space(\glscurrentfieldvalue)}%
{}%
}
\newcommand*{\glsxtrpostdescperson}{%
\ifglshasfield{user1}{\glscurrententrylabel}
{% born
\space(\glscurrentfieldvalue\,--\,%
\ifglshasfield{user2}{\glscurrententrylabel}
{% died
\glscurrentfieldvalue
}%
{}%
)%
}%
{}%
}
\newcommand*{\glsxtrpostlinkperson}{%
\glsxtrifwasfirstuse
{%
\ifglshasfield{user3}{\glslabel}%
{\space(\glscurrentfieldvalue)}%
{}%
}%
{}%
}
\begin{document}
\section{First Use}
\gls{greene}, \gls{story}, \gls{dick}, \gls{maclean},
\gls{mackenzie}, \gls{baum}, \gls{tolkien}, \gls{landon},
\gls{christie}, \gls{hammett}, \gls{chandler}, \gls{dickens}.
\section{Next Use}
\gls{greene}, \gls{story}, \gls{dick}, \gls{maclean},
\gls{mackenzie}, \gls{baum}, \gls{tolkien}, \gls{landon},
\gls{christie}, \gls{hammett}, \gls{chandler}, \gls{dickens}.
\printunsrtglossary[title={Authors (by name)}]
\printunsrtglossary[title={Authors (by birth)},type=bybirth,
target=false% don't create hypertargets
]
\end{document}
这些位置现在出现在两个词汇表中(对应于 创建的记录\gls
)。如果您不想要这些,只需添加选项
save-locations=false
到 的选项列表\GlsXtrLoadResources
。