# Genealogy System

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

• A minimal example would be of more use than fragments. What's the purpose of the codes? Why not use just \chapter with \labels and something like nameref? – cfr Feb 23 '16 at 13:16
• Interesting task. How good are your TeX macro programming skills? – jknappen Feb 23 '16 at 16:57
• BTW, in LaTeX convention [] denotes an optional argument. However, the person number looks pretty much obligatory to me, suggesting a syntax like \personChapter{Jennifer Doe}{23} – jknappen Feb 23 '16 at 16:59
• @cfr Thanks for the advice, I wrote two commands that use this: I added them at the end of my question. – ᴜsᴇʀ Feb 23 '16 at 17:37
• @jknappen I'm not an expert, but I wrote some simple commands that partly do it, but I'm still working on. I also edited the question with LaTeX conventions, as you said, thanks. – ᴜsᴇʀ Feb 23 '16 at 17:41

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


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

• What is the advantage over the code at the end of my question? – ᴜsᴇʀ Feb 23 '16 at 19:19
• @ᴜsᴇʀ I don't use up \chapters in the process. – Steven B. Segletes Feb 23 '16 at 19:21
• And what is the advantage to not use \chapter? – ᴜsᴇʀ Feb 23 '16 at 19:23
• @ᴜsᴇʀ That is for you to decide, if there is any advantage. Me? If I used a chapter for each person in the family genealogy, I would have to chop down more trees. – Steven B. Segletes Feb 23 '16 at 19:25
• @ᴜsᴇʀ I have edited the result to use hot links – Steven B. Segletes Feb 23 '16 at 19:50