词汇表与作者索引的索引?

词汇表与作者索引的索引?

当我开始写一本较长的书时,我最初只觉得需要作者索引。因此,我通过\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-extrabib2gls列出中定义的所有作者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提供了一种有用的定义方法,但为提供了不同的定义:\sortnamebib2gls

\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总是忽略未知字段(在本例中为、 和borndied。如果这些字段在第一次使用之前在文档中定义,或者可以将它们别名为现有字段,则这些字段将被识别:othernameidentifier\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,第一页是:

第 1 页图片:按姓名列出的作者

第二页是:

第 2 页图片:按出生日期列出的作者

按日期排序时,组标题默认为 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}

1 首先使用 Graham Greene、Story、Dick、MacLean、Mackenzie、L. Frank Baum、JRR Tolkien、Christopher Landon、Agatha Christie、Dashiell Hammett、Chandler、Dickens。2 接下来使用 Green、Story、Dick、MacLean、Mackenzie、Baum、Tolkien、Landon、Christie、Hammett、Chandler、Dickens。

第一次使用时会出现不一致的情况。这是因为只有部分条目有字段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}

1 首先使用 Graham Greene、Jack Trevor Story、Philip K. Dick、Alistair MacLean、Compton Mackenzie、L. Frank Baum、JRR Tolkien、Christopher Landon、Agatha Christie (Lady Mallowan)、Dashiell Hammett、Raymond Chandler、Charles Dickens。2 接下来使用 Green、Story、Dick、MacLean、Mackenzie、Baum、Tolkien、Landon、Christie、Hammett、Chandler、Dickens。

这些位置现在出现在两个词汇表中(对应于 创建的记录\gls)。如果您不想要这些,只需添加选项

save-locations=false

到 的选项列表\GlsXtrLoadResources

相关内容