% lin.sty - LaTeX2e functions for automating Linnaean taxa % % 0.1 Peter Flynn, 2002-04-28, with help from users on c.t.t. % % WARNING: BROKEN. THIS IS A PROOF-OF-CONCEPT NOT A PRODUCT % % Define names in the preamble with the command % % \lin{shortname}{Genus}{species} % % This creates \shortname as a command, which typesets the full % name the first time and the short form on subsequent uses. % Names are set using \emph, so they are italic in roman text % and roman in italic text. The command is reset automatically % when the chapter changes (in document classes where \chapter % is usable), when the section changes (in other classes), and % after the abstract, so that it again produces the full name % on next use and the abbreviated form subsequently. % % BUGS % % Currently the first name used after a section/chapter change % causes the context signal to be set false, so other names are % wrongly printed in short form on first reference that section % or chapter. The context signal needs to be on a per-name basis, % but that's going to be pretty expensive in namespace. % % TO DO % % Tidy this up into a proper package of .dtx / .ins files % % Add a 4th [optional] argument to allow subspecies, varieties, % or % % Make it force full format when used in the argument of titles % like \title, \chapter, and \section (tricky: command argument % in LaTeX are not object-aware) % % Force detection of already-defined Genus with the same initial, % and shift the capital abbreviation to two letters (cap+lc). % Presumably the rule means a third Genus would mean a shift to % three letters... % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % \newcommand{\lin}[3]{% % define the new command inside a command which will do the resetting % needed after abstracts, chapters, and sections \expandafter\def\csname LIN@reset@#1\endcsname{% % the next line defines the command \expandafter\def\csname #1\endcsname{% % which immediately expands to the full name and records the context % in terms of chapter or section number \emph{#2\ #3}\LIN@setcontext% % and then redefines itself to do several things \expandafter\def\csname #1\endcsname{% % a) to test the context to see if chapter or section has changed \LIN@testcontext % b) if it *has*, we want the full Monty again \ifLIN@newcontext % (i) perform a reset of itself \csname LIN@reset@#1\endcsname % (ii) set the context to "unchanged" \LIN@newcontextfalse % (iii) and finally call itself to typeset the full name \csname #1\endcsname % c) if the context has *not* changed \else % just typeset the short version, stripping Genus to an initial \emph{\LIN@init#2\sentinel.~#3}% \fi}}}% % having defined a command to define all this, now actually execute it \csname LIN@reset@#1\endcsname} % % UTILITIES % % Routine extract first character of a string (used for Genus) % This needs generalising with an extra argument for the length of % the initial substring to extract (or maybe just three versions % of the same command eg \LIN@initi, \LIN@initii, and \LIN@initiii % to extract 1, 2, or 3 characters). \def\LIN@init#1#2\sentinel{#1} % % Define a toggle to flag if the context (abstract, chapter, section) % has changed or not \newif\ifLIN@newcontext % Memorize the existing \endabstract (check if this can be relied upon) \let\LIN@endabstract\endabstract % Redefine \endabstract to force the context flag to signal "changed" \gdef\endabstract{\LIN@endabstract\LIN@newcontexttrue} % Define a counter to hold the current chapter or section number \newcounter{LIN@context} % Define the context-testing routine twice, once for articles, which % use \section as their top-level division, and once for books and % reports which use \chapter \@ifundefined{thechapter}% {\newcommand{\LIN@testcontext}% % If the context counter (ie existing value) is the same as the value % of the current section, set the flag to false (no change in section) {\ifnum\c@LIN@context=\c@section \LIN@newcontextfalse % otherwise set it to true \else \LIN@newcontexttrue % set the counter to the current (ie new) section value \fi\LIN@setcontext}% % and define the context-setter to use the section counter \newcommand{\LIN@setcontext}{\c@LIN@context=\c@section}}% % Same structure exactly for chapters {\newcommand{\LIN@testcontext}% {\ifnum\c@LIN@context=\c@chapter \LIN@newcontextfalse \else \LIN@newcontexttrue \fi\LIN@setcontext} \newcommand{\LIN@setcontext}{\c@LIN@context=\c@chapter}} % % Details see http://www.wikipedia.com/wiki/Linnaean+taxonomy % \endinput % % Sample instance % \documentclass{article} \usepackage{lin} \usepackage[latin1]{inputenc} \lin{daisy}{Ranunculus}{ficaria} \lin{oak}{Quercus}{robur} \begin{document} \title{Linnæan taxa} \author{Peter Flynn} \date{2002-04-29} \maketitle \begin{abstract} This is a story about the \daisy\ and the \oak. \end{abstract} \section{Introduction} Once upon a time there was a \daisy\ growing at the foot of the old \oak. Every time it rained, the \oak's leaves sheltered the little \daisy. \section{Conclusion} When the \daisy\ grew up and the \oak\ got older and wiser they gave a wild party. \end{document}