2

I'm using the biocon package to organize plants in an academic work. I created new taxons as needed in the text, for instance, the family. In the final chapter of the work, I have a large table (about 300 entries) listing some information from the plants (which I have in all the new taxons).

Such a table is organized alphabetically by the family. Thus, in some cases I have repeating families in the first column. When this happens, I need to print only the first occurrence of the family, and the remaining ones should be blank.

I created a workaround but it does not work along with biocon. For simplification in the following MWE I ommited the table and instead I use the same structure in plain text:

\documentclass{article}
\usepackage{biocon}
\usepackage{ifthen}

\begin{document}

\newtaxon{family}
\newtaxastyle{Family}{\taxon{!family!}}

\newplant{araca}{genus=Psidium, epithet=cattleianum, author=Sabine, family=Myrtaceae}
\newplant{acafrao}{genus=Curcuma, epithet=longa, author=L., family=Zingiberaceae}
\newplant{gengibre}{genus=Zingiber, epithet=officinale, author=Roscoe, family=Zingiberaceae}

Testing the new taxon: \plant[Family]{araca}.

\newcommand{\myval}{}

\newcommand{\setMyVal}[1]{\gdef\myval{#1}}

\newcommand{\printOnlyFirstOccurence}[1]{
    \ifthenelse{\equal{\myval}{#1}}
        {}
        {\setMyVal{#1}(\myval)}%else
}

The same plant obviously would have the same family, thus: 
\plant[f]{araca}\printOnlyFirstOccurence{\plant[Family]{araca}} and \plant[f]{araca}\printOnlyFirstOccurence{\plant[Family]{araca}};

However, these two have the same family, and yet they are printed duplicated: 
\plant[f]{acafrao}\printOnlyFirstOccurence{\plant[Family]{acafrao}} and \plant[f]{gengibre}\printOnlyFirstOccurence{\plant[Family]{gengibre}};

\end{document}

In the above example, I use the definition of \printOnlyFirstOccurence to decide if the scientific name of a plant would be accompanied or not by its family name. I only want to show the first occurrence (in sequence) of a family (it is the same as for the table, but here my example fails in plain text).

The output of the second example is:

Testing the new taxon: Myrtaceae. The same plant obviously would have the same family, thus: Psidium cattleianum (Myrtaceae) and Psidium cattleianum ; However, these two have the same family, and yet they are printed duplicated: Curcuma longa (Zingiberaceae) and Zingiber officinale (Zingiberaceae);

But the desired output is:

Testing the new taxon: Myrtaceae. The same plant obviously would have the same family, thus: Psidium cattleianum (Myrtaceae) and Psidium cattleianum ; However, these two have the same family, and yet they are printed duplicated: Curcuma longa (Zingiberaceae) and Zingiber officinale;

Any thoughts?

1

We can also simplify the syntax, by providing a command \plantF that automatically adds the family name, provided it's not the same as the last family that has been typeset.

The idea is the same as yours, but we need to delve into the internals; in particular, the family name for araca is stored in \Paraca@family.

\documentclass{article}
\usepackage{biocon}
\usepackage{pdftexcmds}

\makeatletter
\newcommand{\opt@family}[1]{%
  \ifnum\pdf@strcmp{\csname P#1@family\endcsname}{\plantfamily@last}=\z@
  \else
    \protected@xdef\plantfamily@last{\csname P#1@family\endcsname}%
    \ (\plant[Family]{#1})%
  \fi
}
\newcommand{\resetfamily}{\gdef\plantfamily@last{}} % reinitialize
\resetfamily % initialize

% user command
\newcommand{\plantF}[2][]{%
  \plant[#1]{#2}\opt@family{#2}%
}
\makeatother

\begin{document}

\newtaxon{family}
\newtaxastyle{Family}{\taxon{!family!}}

\newplant{araca}{genus=Psidium, epithet=cattleianum, author=Sabine, family=Myrtaceae}
\newplant{acafrao}{genus=Curcuma, epithet=longa, author=L., family=Zingiberaceae}
\newplant{gengibre}{genus=Zingiber, epithet=officinale, author=Roscoe, family=Zingiberaceae}

Testing the new taxon: \plant[Family]{araca}.

The same plant obviously would have the same family, thus: 
\plantF[f]{araca} and \plantF[f]{araca}.

However, these two have the same family:
\plantF[f]{acafrao} and \plantF[f]{gengibre}.

The same plant obviously would have the same family, thus: 
\plantF[f]{araca} and \plantF[f]{araca}.

\resetfamily

The same plant obviously would have the same family, thus: 
\plantF[f]{araca} and \plantF[f]{araca}.

\end{document}

Note that in the last paragraph, the family is printed again because of \resetfamily.

enter image description here

| improve this answer | |
  • I used your solution with success, although several parts of it appear 'esoterical' to me. I can't quite understand the "=\z@". Any suggestion on where to begin studying LaTeX more in deep? – Isma Feb 13 '16 at 20:49
1

I on purpose left other answers first, for mine to be be listed on top ;-)

\documentclass{article}
\usepackage{biocon}
%\usepackage{ifthen}% already loaded by biocon

\newcommand*\OnlyFirstPlantFamily [1]{%
    \expandafter\ifx\csname OnlyFirst@\csname P#1@family\endcsname\endcsname
                    \relax
    \space(\plant[Family]{#1})%
    \global\expandafter
           \let\csname OnlyFirst@\csname P#1@family\endcsname\endcsname \empty
    \fi
}

\begin{document}

\newtaxon{family}
\newtaxastyle{Family}{\taxon{!family!}}

\newplant{araca}{genus=Psidium, epithet=cattleianum, author=Sabine, family=Myrtaceae}
\newplant{acafrao}{genus=Curcuma, epithet=longa, author=L., family=Zingiberaceae}
\newplant{gengibre}{genus=Zingiber, epithet=officinale, author=Roscoe, family=Zingiberaceae}

Testing the new taxon: \plant[Family]{araca}.

The same plant obviously would have the same family, thus: 
\plant[f]{araca}\OnlyFirstPlantFamily{araca} and \plant[f]{araca}\OnlyFirstPlantFamily{araca};

However, these two have the same family, and yet they are printed duplicated: 
\plant[f]{acafrao}\OnlyFirstPlantFamily{acafrao} and
\plant[f]{gengibre}\OnlyFirstPlantFamily{gengibre};

\end{document}

Uses internals of biocon.

Blockquote

| improve this answer | |
0

This will not work. \plant[Family]{acafrao} is very complicated command and absolutly not expandable and you can't use it in ifthenelse.

You can try something like this, but I don't know the package and so I'm only guessing that it will work:

\documentclass{article}
\usepackage{biocon}
\usepackage{ifthen}

\begin{document}

\newtaxon{family}
\newtaxastyle{Family}{\taxon{!family!}}

\newplant{araca}{genus=Psidium, epithet=cattleianum, author=Sabine, family=Myrtaceae}
\newplant{acafrao}{genus=Curcuma, epithet=longa, author=L., family=Zingiberaceae}
\tracingmacros=1
\newplant{gengibre}{genus=Zingiber, epithet=officinale, author=Roscoe, family=Zingiberaceae}
\tracingmacros=0
Testing the new taxon: \plant[Family]{araca}.

\makeatletter
\newcommand\Lastfamily{}
\def\Lastfamily{}
\newcommand{\printOnlyFirstOccurence}[1]{%
 \edef\Newfamily{\csname \curr@ntid family\endcsname}%
 \ifthenelse{\equal{\Lastfamily}{\Newfamily}}
        {}
        { #1}%else
 \let\Lastfamily\Newfamily        
}
\makeatother

The same plant obviously would have the same family, thus:
\plant[f]{araca}\printOnlyFirstOccurence{\plant[Family]{araca}} and \plant[f]{araca}\printOnlyFirstOccurence{\plant[Family]{araca}};

However, these two have the same family, and yet they are printed duplicated:
\plant[f]{acafrao}\printOnlyFirstOccurence{\plant[Family]{acafrao}} and \plant[f]{gengibre}\printOnlyFirstOccurence{\plant[Family]{gengibre}};

\end{document}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.