我正在阅读研究论文,并在 LaTeX 文档中编写摘要。对于每篇论文,我都会写一个部分,其中包含标题、作者姓名、其所在机构、出版年份、摘要、评论等。
是否可以在源文件中以任意顺序写入各个部分,然后使用序言中的命令(或类似命令)根据某些标准(作者姓名、年份等的字母顺序)对它们进行排序?
答案1
以下是使用的一种可能方法glossaries-extra
和bib2gls
:
\RequirePackage{filecontents}
\begin{filecontents*}{preamble-nointerpret.bib}
@preamble{"\providecommand{\sortart}[2]{#1 #2}"}
\end{filecontents*}
\begin{filecontents*}{\jobname.bib}
@preamble{"\providecommand{\sortart}[2]{#2, #1}"}
@article{quackalot2017,
title={\sortart{The}{Adventures of Duck and Goose}},
author={Sir Quackalot},
institution={Duck University},
year=2017,
summary={A well-researched chronicle of some waterfowl activities},
comments={A really exciting story}
}
@article{parrot2016,
title={My Friend is a Duck},
author={Polly Parrot},
institution={Amazon College},
year=2016,
summary={An authorized biography},
comments={Another really exciting story}
}
@article{parrot2015,
title={Annotated Duck and Goose Lecture Notes for Students},
author={Polly Parrot and Dickie Duck},
institution={Amazon College},
year=2015,
summary={Lecture notes for students studying the Duck and Goose
chronicles},
comments={Accessible and easy to understand reference notes}
}
\end{filecontents*}
\documentclass{report}
\usepackage[record]{glossaries-extra}
% Ensure document use of \sortart is provided:
\GlsXtrLoadResources[src=preamble-nointerpret,interpret-preamble=false]
\GlsXtrLoadResources[
src=\jobname,% data in \jobname.bib
% convert unknown entry identifiers to something that bib2gls will
% recognise:
entry-type-aliases={article=entry},% make @article act like @entry
% convert unknown fields to keys recognised by glossaries.sty:
field-aliases={
title=name,
summary=description,
author=user1,
year=user2,
comments=user3,
institution=user4
},
% Identify fields formatted using BibTeX name style:
bibtex-contributor-fields={user1},
% Name ordered to be used in the document:
contributor-order=forenames,% forenames first
selection=all,% select all defined entries
sort-field=name,% order by name field
sort=en,% sort according to English alphabet
type=main,% add primary entries to the 'main' glossary
% also provide a secondary list sorted numerically by year:
secondary=integer:user2:byyear
]
\newcommand{\glssummary}{\glsentrydesc}
\newcommand{\glsauthor}{\glsentryuseri}
\newcommand{\glsyear}{\glsentryuserii}
\newcommand{\glscomments}{\glsentryuseriii}
\newcommand{\glsinstitution}{\glsentryuseriv}
% Provide custom glossary style
\newglossarystyle{titlelist}%
{%
\renewenvironment{theglossary}{}{}%
\renewcommand{\glossaryheader}{}%
\renewcommand*{\glsgroupheading}[1]{}%
\renewcommand*{\glsgroupskip}{}%
\renewcommand{\glossentry}[2]{%
\glsentryitem{##1}%
\section[\glsentryname{##1}]{\glossentryname{##1}}%
% Change to fit desired format
Author: \glsauthor{##1}\par
Institution: \glsinstitution{##1}\par
Year of Publication: \glsyear{##1}\par
Summary: \glssummary{##1}\par
Comments: \glscomments{##1}\par
}%
% Don't have sub-entries, but providing style anyway:
\renewcommand{\subglossentry}[3]{%
\glssubentryitem{##2}%
\subsection[\glsentryname{##2}]{\glossentryname{##2}}%
% Change to fit desired format
Author: \glsauthor{##2}\par
Institution: \glsinstitution{##2}\par
Year of Publication: \glsyear{##2}\par
Summary: \glssummary{##2}\par
Comments: \glscomments{##2}\par
}%
}
\setglossarystyle{titlelist}
\renewcommand{\glossarysection}[2][]{}
\begin{document}
\chapter{Ordered by Title}
\printunsrtglossary
\chapter{Ordered by Year}
\printunsrtglossary[type=byyear,target=false]
\end{document}
如果文档位于名为的文件中myDoc.tex
,则构建过程如下:
pdflatex myDoc
bib2gls myDoc
pdflatex myDoc
自定义命令\sortart
有两个定义。第一个是:
\providecommand{\sortart}[2]{#1 #2}
该文件中使用了该函数。第二个函数是:
\providecommand{\sortart}[2]{#2, #1}
在排序时使用它bib2gls
,这意味着冠词(“The”)被移动到标题的末尾,以便第一个标题按“Adventures of Duck and Goose, The”而不是“The Adventures of Duck and Goose”排序。
首页 (按标题排序):
第二页(按年份排序):
要添加有关出版物类型的信息,您可以使用该category
字段。此字段需要标签作为其值,因此research
或tutorial
或之类的值survey
都可以。
对于其他机构,这取决于您的需要。例如,您可以直接使用 BibTeX 的命名样式并列出institution
列表:
\RequirePackage{filecontents}
\begin{filecontents*}{preamble-nointerpret.bib}
@preamble{"\providecommand{\sortart}[2]{#1 #2}"}
\end{filecontents*}
\begin{filecontents*}{\jobname.bib}
@preamble{"\providecommand{\sortart}[2]{#2, #1}"}
@article{quackalot2017,
title={\sortart{The}{Adventures of Duck and Goose}},
author={Sir Quackalot},
institution={Duck University},
year=2017,
summary={A well-researched chronicle of some waterfowl
activities},
comments={A really exciting story},
category={survey}
}
@article{parrot2016,
title={My Friend is a Duck},
author={Polly Parrot},
institution={Amazon College},
year=2016,
summary={An authorized biography},
comments={Another really exciting story},
category={research}
}
@article{parrot2015,
title={Annotated Duck and Goose Lecture Notes for Students},
author={Polly Parrot and Dickie Duck},
institution={Amazon College and Duck University},
year=2015,
summary={Lecture notes for students studying the Duck and Goose
chronicles},
comments={Accessible and easy to understand reference notes},
category={tutorial}
}
\end{filecontents*}
\documentclass{report}
\usepackage[record]{glossaries-extra}
% Ensure document use of \sortart is provided:
\GlsXtrLoadResources[src=preamble-nointerpret,interpret-preamble=false]
\GlsXtrLoadResources[
src=\jobname,% data in \jobname.bib
% convert unknown entry identifiers to something that bib2gls will
% recognise:
entry-type-aliases={article=entry},% make @article act like @entry
% convert unknown fields to keys recognised by glossaries.sty:
field-aliases={
title=name,
summary=description,
author=user1,
year=user2,
comments=user3,
institution=user4
},
% Identify fields formatted using BibTeX name style:
bibtex-contributor-fields={user1,user4},
% Name ordered to be used in the document:
contributor-order=forenames,% forenames first
selection=all,% select all defined entries
sort-field=name,% order by name field
sort=en,% sort according to English alphabet
type=main,% add primary entries to the 'main' glossary
% also provide a secondary list sorted numerically by year:
secondary=integer:user2:byyear
]
\newcommand{\glssummary}{\glsentrydesc}
\newcommand{\glsauthor}{\glsentryuseri}
\newcommand{\glsyear}{\glsentryuserii}
\newcommand{\glscomments}{\glsentryuseriii}
\newcommand{\glsinstitution}{\glsentryuseriv}
% Provide custom glossary style
\newglossarystyle{titlelist}%
{%
\renewenvironment{theglossary}{}{}%
\renewcommand{\glossaryheader}{}%
\renewcommand*{\glsgroupheading}[1]{}%
\renewcommand*{\glsgroupskip}{}%
\renewcommand{\glossentry}[2]{%
\glsentryitem{##1}%
\section[\glsentryname{##1}]{\glossentryname{##1}}%
% Change to fit desired format
Author: \glsauthor{##1}\par
Institution: \glsinstitution{##1}\par
Year of Publication: \glsyear{##1}\par
Summary: \glssummary{##1}\par
Type: \glscategory{##1}\par
Comments: \glscomments{##1}\par
}%
% Don't have sub-entries, but providing style anyway:
\renewcommand{\subglossentry}[3]{%
\glssubentryitem{##2}%
\subsection[\glsentryname{##2}]{\glossentryname{##2}}%
% Change to fit desired format
Author: \glsauthor{##2}\par
Institution: \glsinstitution{##2}\par
Year of Publication: \glsyear{##2}\par
Type: \glscategory{##2}\par
Summary: \glssummary{##2}\par
Comments: \glscomments{##2}\par
}%
}
\setglossarystyle{titlelist}
\renewcommand{\glossarysection}[2][]{}
\begin{document}
\chapter{Ordered by Title}
\printunsrtglossary
\chapter{Ordered by Year}
\printunsrtglossary[type=byyear,target=false]
\end{document}
如果您需要将作者与相应的机构关联起来,情况会更加复杂。我不确定最好的语法是什么,尽管交叉引用方法可能是最好的。因此,每个作者都有定义,并且文章有一个字段可以通过标签引用他们。例如:
@index{polly.parrot,
name={Polly Parrot},
institution={amazon.college},
category={author}
}
@index{dickie.duck,
name={Dickie Duck},
institution={duck.university},
category={author}
}
@index{amazon.college,
name={Amazon College},
category={institution}
}
@index{duck.university,
name={Duck University},
category={institution}
}
@article{parrot2015,
title = {Annotated Duck and Goose Lecture Notes for Students},
author = {polly.parrot,duckie.duck},
Annotated Duck and Goose Lecture Notes for Students
}
在这种情况下,按作者排序比较棘手。你可以调整sample-authors.pdf
示例中描述bib2gls
手动的,它通过分层方法链接作者及其出版物。其中的条目形式为 (people.bib
):
@entry{dickens,
name={\sortname{Charles}{Dickens}},
text={Dickens},
description={English writer and social critic},
born={7~February 1812 AD},
died={9~June 1870 AD},
identifier={person}
}
和 (books.bib
):
@entry{ataleoftwocities,
name={\sortart{A}{Tale of Two Cities}},
description={novel by Charles Dickens},
identifier={book},
author={\sortmediacreator{Charles}{Dickens}},
year={1859}
}
@entry{bleakhouse,
name={Bleak House},
description={novel by Charles Dickens},
identifier={book},
author={\sortmediacreator{Charles}{Dickens}},
year={1852}
}
自定义命令定义在no-interpret-preamble.bib
:
@preamble{"\providecommand{\sortname}[2]{#1 #2}
\providecommand{\sortvonname}[3]{#1 #2 #3}
\providecommand{\sortart}[2]{#1 #2}
\providecommand{\sortmediacreator}[2]{#1 #2}"}
@preamble{"\providecommand{\sortname}[2]{#2, #1}
\providecommand{\sortvonname}[3]{#2 #3, #1}
\providecommand{\sortart}[2]{#2}
\renewcommand{\sortmediacreator}[2]{\MakeLowercase{#2}}"}
这允许一些技巧,可以将名称转换为
author={\sortmediacreator{Charles}{Dickens}}
标签
author={dickens}
允许将字段转换为交叉引用。完整代码如下sample-authors.tex
是
\documentclass[12pt,a4paper]{article}
\usepackage[colorlinks]{hyperref}
\usepackage[record,% using bib2gls
nostyles,% don't load default styles
stylemods={bookindex},% load glossary-bookindex and patch styles
style=bookindex]{glossaries-extra}
\GlsXtrLoadResources[
src=no-interpret-preamble,
interpret-preamble=false
]
\GlsXtrLoadResources[
src={interpret-preamble2,people,books},
write-preamble=false,
interpret-label-fields,
field-aliases={identifier=category,author=parent},
check-end-punctuation={name},
replicate-fields={name={first}}
]
\newcommand*{\bookfont}[1]{\emph{#1}}
\glssetcategoryattribute{book}{textformat}{bookfont}
\glssetcategoryattribute{book}{glossnamefont}{bookfont}
% requires glossaries-extra v1.23
\renewcommand*{\glsxtrifcustomdiscardperiod}[2]{%
\GlsXtrIfFieldUndef{nameendpunc}{\glslabel}{#2}{#1}%
}
\begin{document}
\section{Sample}
\gls{ataleoftwocities}. \gls{bleakhouse}. \gls{thebigsleep}.
\gls{thelonggoodbye}. \gls{redharvest}.
\gls{murderontheorientexpress}. \gls{whydidnttheyaskevans}.
\gls{icecoldinalex}. \gls{thehobbit}. \gls{thelordoftherings}.
\gls{thewonderfulwizardofoz}. \gls{whiskygalore}.
\gls{whereeaglesdare}. \gls{icestationzebra}. \gls{ubik}.
\gls{doandroidsdreamofelectricsheep}. \gls{thetroublewithharry}.
\gls{brightonrock}.
\printunsrtglossary[title={Author and Book List}]
\end{document}
此列表按作者列出,其出版物为子条目。此示例的不同之处在于没有合著者或机构,但它演示了如何将作者姓名转换为识别标签。