如何创建 PDFLaTeX 文档中提及的人员登记册?我想写
The screwdriver was turned by \person[Mr.]{Miller}.
The screwdriver was turned by M. Miller. Register of Persons =================== Prof. Dr. M. Miller, University of M (p. 4, 12) Dr. A. Foobar, University of M (p. 5) B. Foo, University of Z (p. 1)
如果可以按以下方式对人员进行排序,那就太好了
- 联系
- 姓
- 名
答案1
以下是概念证明BibLaTeX
(已编辑,在名称列表中包含链接和 pageref)
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{filecontents}
\usepackage{hyperref} % to activate hyperlinks
\usepackage[sorting=affiliation,backref=]{biblatex} % persons are sorted on their affiliation
%\usepackage[sorting=first,backref]{biblatex}% persons are sorted on their first name
%\usepackage[sorting=last,backref]{biblatex} % persons are sorted on their last name
\begin{filecontents}{biblatex-dm.cfg}
\DeclareDatamodelEntrytypes{person}
\DeclareDatamodelFields[type=list,datatype=name,skipout=false]{name}
\DeclareDatamodelFields[type=field,datatype=literal,skipout=false]{affiliation,mysortkey}
\DeclareDatamodelEntryfields[person]{name,affiliation,mysortkey}
\end{filecontents}
\begin{filecontents}{\jobname.bib}
% Encoding: UTF8
@person{goedel,
name = {Gödel, Kurt},
affiliation = {Princeton}
}
@person{lamport,
name = {Lamport, Leslie},
affiliation = {Microsoft}
}
@person{knuth,
name = {Knuth, Donald},
affiliation = {Stanford}
}
\end{filecontents}
\DeclareFieldFormat{affiliation}{#1}
\DeclareBibliographyDriver{person}{
\printnames{name}
\setunit{\addcomma\addspace}
\printfield{affiliation}
\usebibmacro{pageref}
}
\DeclareSourcemap{
\maps[datatype=bibtex]{
\map[overwrite]{
\step[fieldsource=name, final]
\step[fieldset=mysortkey, origfieldval]
\step[fieldsource=mysortkey,
match=\regexp{\s*(.+)\s*,\s*(.+)\s*},
replace={$2$1}]
}
}
}
\DeclareSortingScheme{affiliation}{
\sort{
\field{affiliation}
}
}
\DeclareSortingScheme{last}{
\sort{
\field{name}
}
}
\DefineBibliographyStrings{english}{
backrefpage = {p\adddot},
backrefpages = {pp\adddot},
}
\DeclareSortingScheme{first}{
\sort{
\field{mysortkey}
}
}
\DeclareCiteCommand{\person}
{\printfield{postnote}}
{\setunit{\addspace}\bibhyerref{\printnames{name}}}
{, }
{}
\addbibresource{\jobname.bib}
\begin{document}
\person{knuth}
\newpage
This is page \thepage
\person{goedel} proved the incompleteness theorem.
The inventor of \TeX{} is \person[Prof.]{knuth}
The \LaTeX{} format was written by \person{lamport}
\printbibliography[title={List of Names}]
\end{document}
第一步是创建“名称注册”的数据模型。
\DeclareDatamodelEntrytypes{person}
\DeclareDatamodelFields[type=list,datatype=name,skipout=false]{name}
\DeclareDatamodelFields[type=field,datatype=literal,skipout=false]{affiliation,mysortkey}
\DeclareDatamodelEntryfields[person]{name,affiliation,mysortkey}
对于数据模型,我们创建一个新的条目类型,person
其字段为name, affiliation
和mysortkey
。数据模型必须驻留在数据模型文件或配置文件中。
第二步是为person
新字段创建参考书目驱动程序和格式化说明:
\DeclareFieldFormat{affiliation}{#1}
\DeclareBibliographyDriver{person}{
\printnames{name}
\setunit{\addcomma\addspace}
\printfield{affiliation}
\usebibmacro{pageref}
}
第三步是创建排序指令,对于affiliation
和姓氏,这可以通过简单的排序方案来完成
\DeclareSortingScheme{affiliation}{
\sort{
\field{affiliation}
}
}
\DeclareSortingScheme{last}{
\sort{
\field{name}
}
}
对于根据名字进行排序,我们必须操纵名字(也许Biber
有BibLaTeX
更好的方法来做到这一点,但我无法在文档中找到它):
\DeclareSourcemap{
\maps[datatype=bibtex]{
\map[overwrite]{
\step[fieldsource=name, final]
\step[fieldset=mysortkey, origfieldval]
\step[fieldsource=mysortkey,
match=\regexp{\s*(.+)\s*,\s*(.+)\s*},
replace={$2$1}]
}
}
}
我们可以使用该Biber
功能动态操作bib
条目,为其创建新字段和新值。在这里,我们复制值name
并转换其内容(当采用标准BibTeX
格式时)以在字段中<last>, <first>
创建字符串。完成此步骤后,我们可以使用简单的排序模式<first><last>
mysortkey
\DeclareSortingScheme{first}{
\sort{
\field{mysortkey}
}
}
最后一步是创建引用命令\person
\DeclareCiteCommand{\person}
{\printfield{postnote}}
{\setunit{\addspace}\bibhyperref{\printnames{name}}}
{, }
{}
您需要 BibLaTex > 2.0 和 biber > 1.2。此示例可在 TeXLive2012 中使用
编辑
为了仅打印文本中的首字母,第一步是创建一个新的姓名格式指令,即:
\DeclareNameFormat{firstinit}{\usebibmacro{name:first-last}{#1}{#4}{#5}{#7}}
然后,必须使用新的格式指令(作为引用命令定义中的格式选项,即\person
:
\DeclareCiteCommand{\person}
{\printfield{postnote}}
{\setunit{\addspace}\bibhyperref{\printnames[firstinit]{name}}}
{, }
{}