Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How can I create a register of persons who are mentioned in my PDFLaTeX document? I want to write

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)

It would be nice, if the persons could be sorted by

  1. affiliation
  2. last name
  3. first name
share|improve this question
    
It is not clear why you need a solution using BibLaTeX. Except for the title, your question doesn't refer to it at all. Requiring solutions like this may severely restrict the possible solutions. –  Marc van Dongen Nov 19 '12 at 18:59
    
What would you suggest instead? –  Jonas Stein Nov 25 '12 at 2:21
    
I suggested the nameauth package in a previous incarnation of your question. There may be different solutions. –  Marc van Dongen Nov 25 '12 at 8:28

1 Answer 1

up vote 15 down vote accepted

Here is a proof of concept in BibLaTeX (Edited to include links and pageref in the list of names)

\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}

enter image description here

The first step is to create a data model for the "registry of names".

\DeclareDatamodelEntrytypes{person}
\DeclareDatamodelFields[type=list,datatype=name,skipout=false]{name}
\DeclareDatamodelFields[type=field,datatype=literal,skipout=false]{affiliation,mysortkey}  
\DeclareDatamodelEntryfields[person]{name,affiliation,mysortkey}

For the data model we create a new entry type person whose fields are name, affiliation and the mysortkey. The data model must resides in a datamodel file or a configuration file.

The second step is to create a bibliography driver for person and formatting instructions for the new fields:

\DeclareFieldFormat{affiliation}{#1}
\DeclareBibliographyDriver{person}{
\printnames{name}
\setunit{\addcomma\addspace}
\printfield{affiliation}
\usebibmacro{pageref}
}

The third step is to create sorting instructions, for affiliation and last name, this is can be done by simple sorting schemes

\DeclareSortingScheme{affiliation}{
  \sort{
    \field{affiliation}
  }
}

\DeclareSortingScheme{last}{
  \sort{
    \field{name}
  }
}

For sorting based on the first name we have manipulate the names (maybe Biber and BibLaTeX have better way to do it, but I was not able to find it in the documentation):

\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}]
    }
  }
}

We can use the Biber feature to dynamically manipulated bib entries to create new fields and new values for them. Here we duplicate the value of name and transform its content (when in standard BibTeX format <last>, <first> to create the string <first><last> in the mysortkey field. After this step we can use a simple sorting schema

\DeclareSortingScheme{first}{
  \sort{
    \field{mysortkey}
  }
}

The final step is to create a citation command \person

\DeclareCiteCommand{\person}
   {\printfield{postnote}}
   {\setunit{\addspace}\bibhyperref{\printnames{name}}}
   {, }
   {}

You need BibLaTex > 2.0 and biber > 1.2. This example will work in TeXLive2012

EDIT

To print only the initials in the text, the first step is to create a new formatting directive for names, namely:

\DeclareNameFormat{firstinit}{\usebibmacro{name:first-last}{#1}{#4}{#5}{#7}}

then, the new formatting directive has to be used (as a format option in the definition of the command for the citation, i.e., \person:

\DeclareCiteCommand{\person}
  {\printfield{postnote}}
  {\setunit{\addspace}\bibhyperref{\printnames[firstinit]{name}}}
  {, }
  {}
share|improve this answer
    
I get here ERROR: Package biblatex Error: Option 'sorting=affiliation' invalid. perhaps my TeX-Live 2009 on debian stable is too old for this. –  Jonas Stein Nov 13 '12 at 23:53
1  
Very likely. You need BibLaTex > 2.0 and biber > 1.2. –  Guido Nov 14 '12 at 0:02
    
@JonasStein It is easy to add reference and back references. See the edited version. –  Guido Nov 14 '12 at 1:07
    
I upgraded to TeXLive 2012 and changed your code a bit it compiles now. Is it difficult to print only the first letter in the text like K. Gödel prooved... –  Jonas Stein Nov 19 '12 at 1:52
    
@JonasStein It's better to edit your question (or posting and answer) rather than modifying the answers. It might be good for your case but break down in other people's uses or it might be something that Guido did not wish to include. . –  percusse Nov 19 '12 at 1:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.