我正在寫一部家族史,我想做這樣的事情:對於每個人,我都有一個章節,每個人都由一個獨特的代碼來識別。
例如這樣的事情:
\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.
產生這個:
約翰·多伊
John Doe 出生於 1900 年,lorem ipsum dolor sat amet,consectetur adipisci elit,sed eiusmod tempor incidunt ut labore et dolore magna aliqua。
在另一頁我可以這樣寫:
\personChapter{Jennifer Doe}{23}
Jennifer Doe, born in 1920, is the daughter of \person{1}.
產生這個:
珍妮佛·多伊
詹妮弗·多伊 (Jennifer Doe) 出生於 1920 年,是約翰·多伊1.
1 請參閱第 46 頁的 John Doe。
其中約翰·多伊是指向 John Doe 頁面的連結(在此範例中為第 46 頁)。
如果我願意,我可以僅添加連結或僅添加腳註:
Jennifer Doe, born in 1920, is the daughter of \personLink{1}.
Jennifer Doe, born in 1920, is the daughter of \personFoot{1}.
我也可以指定另一個名稱,例如:
John Doe's \person{23}[daughter] is dead in 1990.
產生這個:
約翰·多伊的女兒1990 年去世。
1 請參閱第 125 頁的 Jennifer Doe。
其中女兒是 Jennifer Doe 頁面的連結。
此外,人們可以擁有多個程式碼,例如:
\personChapter{Jennifer Doe}{23}[JenniferDoe1920][JD20]
然後我就可以和所有人一起製作一個索引。對於索引中的每個人,都連結到該人的主頁:
\printPeopleIndex
或者,使用另一個命令連結引用它們的所有頁面:
\printPeopleAllRef
這樣的事情可能嗎?
我寫的這些命令部分執行了我上面寫的操作。
\newcommand{\personChapter}[2]
{
\chapter{#1}
\label{ch:#2}
}
\newcommand{\person}[1]
{
\nameref{ch:#1}
\footnote{See \nameref{ch:#1} on page \pageref{ch:#1} .}
}
答案1
編輯以使用熱鏈接。它使用aux檔來保存標籤訊息,因此可以向前和向後引用,如該MWE所示。
我已經\person
使用腳註連結實現了,並\personLink
實現了直接連結。編輯以實現\personFoot
它提供了一個簡單的腳註,沒有到另一個頁面的連結。
在此 MWE 中縮小了\textheight
以便更好地顯示結果。
\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}
注意:該\protected@iwrite
巨集來自egreg的回答將 \\ 寫入文件。