# LATEX - list of items using enumerate for typesetting a dichotomous key (Bestimmungsschluessel)

Today I am looking for a way to typeset a dichotomous key (German: Bestimmungsschluessel, biol.) with LATEX using the

\begin{enumerate}
\item ...
\end{enumerate}


environment.

Such a key is used for plants or animals and is used like this:
Choose one of two options

>1   description one .... go to #2
>1*  description alternative one ... go to #4
>2   description two ... go to
>2*  description alt. two
>...
>...


It should look like this, (real example on German): http://www.sn.schule.de/~biologie/lernen/bestimmung/schlussel.html

So I need a list for automatically numbering every second item with the same number and a star-like symbol within the enumerate environment.
Creating a fixed list might not do, because there is a high possibility of adding further items.

\ref


at the end of each line to get to the next number. Is there a way to NOT label each item and using ref manually? Just thinking about a possible description of more than a 1000 plants or 600 and 600* items.

MWE:

\documentclass[10pt, a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage[english, ngerman]{babel}
\usepackage{lipsum}
\usepackage{hyperref}
\usepackage{enumerate}
\usepackage{enumitem}

\begin{document}
\thispagestyle{empty}
% \maketitle
% \clearpage

\begin{enumerate}
\item\label{item1} \lipsum[1] \dotfill \ref{item2} % this would be #1 description one  ... hinting to #2
\item              \lipsum[2] \dotfill \ref{item3} % this would be #1* description alternative one ... hinting to #3
\item\label{item2} \lipsum[3] \dotfill  \ref{item4} % this would be #2 description two ... hinting to #4
\item              \lipsum[4] \dotfill  % \ref{item5} % this would be #2 description two ... hinting to #5
\item\label{item3} \lipsum[5] \dotfill  % \ref{item10}
\item              \lipsum[6] \dotfill
\item\label{item4} \lipsum[7] \dotfill
\item              \lipsum[8] \dotfill
\end{enumerate}

\end{document}


Things I tried, who did not work for me (but feel free to try again!):

\setlist[]{}
\newcounter{}


I'd appreciate any help, thanks in advance!!

## migrated from stackoverflow.comSep 27 '16 at 8:01

This question came from our site for professional and enthusiast programmers.

• doing it the very hard way: use \begin{description} \item[1~~~]\label{itema1} .... \item[1*~~] .... \end{description} is possible, but no way for more than 10 times 2 entries. Furthermore no automatically numbering or references... – Sebastian Sep 27 '16 at 15:14
• Does your list always have a starred number for every unstarred one? So, 600 plants will require a list containing 1200 items? – Werner Sep 28 '16 at 1:03
• @Werner: yes, indeed. 600 was just an example, but I already got really tired after 10*2 entries. So I was looking for a better way. – Sebastian Sep 28 '16 at 9:21

Do you mean something like this:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{enumitem, etoolbox}

\setlist[1]{labelindent=\parindent}

\newlist{Bestimmungsschluessel}{enumerate}{1}
\setlist[Bestimmungsschluessel]{leftmargin=*, label=\arabic*, labelsep=10pt, format=\bfseries}

\newcounter{schlussel}
\setcounter{schlussel}{0}

\newcommand\iitem{%
\refstepcounter{schlussel}%
\ifnumodd{\value{schlussel}}{\iitemnostar}{\iitemstar}%
}

\makeatletter

\newcommand\iitemstar{%
\item[\@itemlabel\rlap{*}]}

\newcommand\iitemnostar{\item}

\makeatother

\begin{document}

\begin{Bestimmungsschluessel}
\iitem One  \label{one}
\iitem One*
\iitem Two  \label{two}
\iitem Two*
\iitem Three.  See \ref{two}.
\iitem Three*. See \ref{one}.
\end{Bestimmungsschluessel}

\end{document}


If you want to have things like multiple optional arguments and conditional behaviour, it is best to use a delimited argument, so \iitem final description of plant or animal is not a good way to do it.

But with xparse, you can easily construct a delimited argument:

\usepackage{xparse}
\NewDocumentCommand{\iitem}{omd()o}{%
% usage: \iitem[<label>]{<mandatory text>}(<Latin name>)[<label>]
\refstepcounter{schlussel}%
\ifnumodd{\value{schlussel}}{\iitemnostar}{\iitemstar}%
\space
\IfValueT{#1}{\label{#1}}%
#2%
\dotfill
\IfValueTF{#3}{\textsc{#3}\space}{\relax}%
\IfValueT{#4}{\bsrefstring \space \ref{#4}}%
}


Basically, everything else stays the same, though you will also need to revise how you use \iitem.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{enumitem, etoolbox}
\usepackage{xparse}

\setlist[1]{labelindent=\parindent}

% Set up new list
\newlist{Bestimmungsschluessel}{enumerate}{1}
\setlist[Bestimmungsschluessel]{leftmargin=*, label=\arabic*, labelsep=10pt, format=\bfseries}

\newcounter{schlussel}
\setcounter{schlussel}{0}

\NewDocumentCommand{\iitem}{omd()o}{%
% usage: \iitem[<label>]{<mandatory text>}(<Latin name>)[<label>]
\refstepcounter{schlussel}%
\ifnumodd{\value{schlussel}}{\iitemnostar}{\iitemstar}%
\space
\IfValueT{#1}{\label{#1}}%
#2%
\dotfill
\IfValueTF{#3}{\textsc{#3}\space}{\relax}%
\IfValueT{#4}{\bsrefstring \space \ref{#4}}%
}

% An optional text string for the cross-references

\makeatletter

\newcommand{\iitemstar}{\item[\@itemlabel\rlap{*}]}
\newcommand\iitemnostar{\item}

\makeatother

\begin{document}

\begin{Bestimmungsschluessel}
% usage: \iitem[<label>]{<MANDATORY text>}(<Latin name>)[<ref>]
\iitem[labelone]{Text one}
\iitem{One*}(Plantus officinale (L.))
\iitem[labeltwo]{Text two, ref to labelone}[labelone]
\iitem{Two*, ref to labeltwo}[labeltwo]
\iitem[labelthree]{Text three, ref to labelone}[labelone]
\iitem{Text three*, ref to label three}(Other thing)[labelthree]
\end{Bestimmungsschluessel}

Please refer to labelone (\ref{labelone}), labeltwo (\ref{labeltwo}), and labeltree (\ref{labelthree}).

\end{document}


Once commands start getting this complex, however, a so-called 'key-value' approach starts making more and more sense.

• This works like a dream! But, as an extra, how to include a text-variable, \dotfill, \label{} or \ref{} as options of the new iitem? Would this be possible by a \newenvironment? – Sebastian Sep 27 '16 at 22:03
• Can you give an example of how you would want to use the command? \label and \ref seem fairly straightforward, but how would \dotfill be used? – jon Sep 27 '16 at 22:46
• Taking your command \newcommand\iitem{% \refstepcounter{schlussel}% \ifnumodd{\value{schlussel}}{\iitemnostar}{\iitemstar}% \atextvariable \label{} \dotfill \ref{} } (not working) and adding some parameters for a macro to include the needed commands by default. So to say, a wishfull thinking of \iitem{auto. enumeration(given)}{text}{\label{}}{\dotfill(given)}{\ref{}}. \dotfill is just used for optics and getting \ref{} at the end of the line, optics comparable to \tableofcontents'. – Sebastian Sep 28 '16 at 9:18
• So a command with usage like: \iitem[<label>]{<text>}[<ref>] where \label and \ref are optional arguments, or are they mandatory arguments? And if there's no \ref, then is there still a \dotfill? – jon Sep 28 '16 at 14:29
• One that is 'delimited' by some means or another. The most common is braces \mycmd{this is delimited}. The delimited macros with several arguments are annoying to write if you use the command frequently: \mycmd{arg1}{arg2}{arg3}. But if you have mandatory and optional (and/or conditional) arguments, then they are the 'safest' way to design the macro ... rather than \iitem[<optional arg.>] <mandatory text but not delimited> [<optional arg.>]`. – jon Sep 29 '16 at 20:05