6

I'm writing a family history, and I want to do something like this: for every person I have a chapter, and every person is identified by a unique code.

For example something like this:

\personChapter{John Doe}{1}

John Doe is born in 1900, lorem ipsum dolor sit amet, consectetur adipisci
elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua.

that produce this:

John Doe

John Doe is born in 1900, lorem ipsum dolor sit amet, consectetur adipisci elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua.

In another page I can write this:

\personChapter{Jennifer Doe}{23}

Jennifer Doe, born in 1920, is the daughter of \person{1}.

that produce this:

Jennifer Doe

Jennifer Doe, born in 1920, is the daughter of John Doe¹.


¹ See John Doe on page 46.

in which John Doe is a link to the John Doe page (in this example page 46).

If I want I can add only the link or only the footnote:

Jennifer Doe, born in 1920, is the daughter of \personLink{1}.

Jennifer Doe, born in 1920, is the daughter of \personFoot{1}.

I can also specify another name, for example this:

John Doe's \person{23}[daughter] is dead in 1990.

produce this:

John Doe's daughter¹ is dead in 1990.


¹ See Jennifer Doe on page 125.

in which daughter is a link to the Jennifer Doe page.

Furthermore, people can have multiple code, for example:

\personChapter{Jennifer Doe}{23}[JenniferDoe1920][JD20]

Then I can produce an index with all the people. For every person in the index, is linked the main page of that person:

\printPeopleIndex

Or, with another command, are linked all the pages in which they are cited:

\printPeopleAllRef

Is something like this possible?


I wrote these commands which partly do what I wrote above.

\newcommand{\personChapter}[2]
{
\chapter{#1}
\label{ch:#2}
}

\newcommand{\person}[1]
{
\nameref{ch:#1}
\footnote{See \nameref{ch:#1} on page \pageref{ch:#1} .}
}
ᴜsᴇʀ
  • 579

1 Answers1

4

EDITED to use hot links. It uses the aux file for saving the labeling information, so it can forward and backward reference, as shown in this MWE.

I have implemented \person using a footnote link, and \personLink implementing a direct link. EDITED to implement \personFoot which provides a plain footnote without a link to the another page.

The \textheight is shrunk in this MWE to better show the result.

\documentclass{article}
\usepackage{lipsum}
\makeatletter
\long\def \protected@iwrite#1#2#3{%
     \begingroup
     \let\thepage\relax
     #2%
     \let\protect\@unexpandable@protect
     \edef\reserved@a{\immediate\write#1{#3}}%
     \reserved@a
     \endgroup
     \if@nobreak\ifvmode\nobreak\fi\fi
    }
\newcommand\personChapter[2]{\bigskip%
  \protected@iwrite\@auxout{\def\nex{\noexpand\noexpand\noexpand}}{%
    \nex\expandafter\xdef%
    \nex\csname GenLabel#2%
    \nex\endcsname{#1}%
  }%
  \label{Label#2}%
  \noindent\textbf{#1}\smallskip}
\makeatother
\newcommand\person[1]{\csname GenLabel#1\endcsname\footnote{%
  See \csname GenLabel#1\endcsname{} on page \pageref{Label#1}}}
\newcommand\personLink[1]{\csname GenLabel#1\endcsname{} (page \pageref{Label#1})}
\newcommand\personFoot[1]{\csname GenLabel#1\endcsname\footnote{%
  See \csname GenLabel#1\endcsname{} on page \pageref*{Label#1}}}
\parindent 0pt
\textheight 2in
\usepackage{hyperref}

\begin{document}
\personChapter{John Doe}{1}

John Doe is born in 1900, father of \person{23} or, using unlinked footnote,
father of \personFoot{23}, \lipsum[3]

\personChapter{Jennifer Doe}{23}

Jennifer Doe, born in 1920, is the daughter of \person{1} or,
  using no footnote, the daughter of \personLink{1}.
\end{document}

enter image description here

enter image description here


Note: the \protected@iwrite macro came from egreg's answer at Writing \\ to a File.