Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
\documentclass{article}
\usepackage{etoolbox}
\usepackage{zref}
\makeatletter
%% lifespan macros:
\newbool{fl_called}
\newcommand\fl@lifespan{}
\zref@newprop{lifespan}[]{\fl@lifespan}
\newcommand\fl@prefix{fl.~}
\newcommand\fl@infix{--}
\newcommand\fl@suffix{}
\newcommand\fl@handler[1]{%
\ifnumcomp{#1}{<}{\fl@from}{\renewcommand\fl@from{#1}}{}%
\ifnumcomp{#1}{>}{\fl@to}{\renewcommand\fl@to{#1}}{}%
}
\newcommand\floruitsave[1]{%
\ifbool{fl_called}{%
\newcommand\fl@from{10000}%
\newcommand\fl@to{0}%
\forlistloop{\fl@handler}{\fl@years}%
\def\@fl{%
\fl@prefix%
\ifnumcomp{\fl@from}{=}{\fl@to}{\fl@to}{\fl@from\fl@infix\fl@to}%
\fl@suffix%
}%
\renewcommand\fl@lifespan{\@fl}%
}{}%
\zref@labelbyprops{#1}{lifespan}%
}
\newcommand\floruitoutput[1]{%
\zref@extract{#1}{lifespan}%
}
\newcommand\floruit[1]{#1\booltrue{fl_called}\listadd\fl@years{#1}}
\makeatother
%% person environment:
\newcounter{person}
\newenvironment{person}[1]{%
\refstepcounter{person}%
\textbf{\theperson:~#1} \textit{\floruitoutput{person:\theperson}}\par%
}{%
\floruitsave{person:\theperson}%
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\begin{person}{Old MacDonald}
Old MacDonald had a farm in \floruit{1923}, but appears to have sold it by \floruit{1940}.
\end{person}
\begin{person}{Gary Cooper}
Gary Cooper starred in High Noon (\floruit{1952})...
\end{person}
\begin{person}{John Doe}
Blah blah (\floruit{1912}), more blah (\floruit{1930}) \& finally blah (\floruit{1931}).
\end{person}
\begin{person}{Jane Doe}
No floruit here...
\end{person}
The floruit should be with the name like so:
\textbf{3: John Doe} \textit{fl. 1912--1931}\par
Blah blah (1912), more blah (1930) \& finally blah (1931).\par
\end{document}
@ghost

This comment has been minimized.

Copy link

ghost commented Jan 5, 2017

In my opinion this is very nice -- I did not think of writing the full lifespan to the .aux file via zref. This is possible of course, but it will bite you if you need the 'from' or 'to' value separately (just in case?)

@mikkelee

This comment has been minimized.

Copy link
Owner Author

mikkelee commented Jan 5, 2017

I renamed it to lifespan as I intend to add \born{} and \died{} macros too, which if present will then override and be used instead of any \floruits.

But good point on saving from/to! It's still pretty early going for this project, so they might end up needed after all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.