我正在使用该biocon
软件包整理学术著作中的植物。我根据文本中的需要创建了新的分类单元,例如科。在著作的最后一章中,我有一个大表格(约 300 个条目),列出了一些植物信息(我在所有新分类单元中都有这些信息)。
这样的表格是按家族的字母顺序排列的。因此,在某些情况下,我在第一列中有重复的家族。当发生这种情况时,我只需要打印该家族的第一个出现,其余的应该是空白的。
我创建了一个解决方法,但它与 不兼容biocon
。为了简化以下 MWE,我省略了表格,而是使用纯文本中的相同结构:
\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}
在上面的例子中,我使用 的定义来\printOnlyFirstOccurence
决定植物的学名是否应该与其科名一起出现。我只想显示科的第一次出现(按顺序)(与表格相同,但这里我的示例在纯文本中失败)。
第二个示例的输出是:
测试新的分类单元:桃金娘科。同一种植物显然属于同一科,因此:石蒜(桃金娘科)石蒜;然而,这两个属于同一个家族,但却被重复印刷:姜黄(姜科)和姜(姜科);
但期望的输出是:
测试新的分类单元:桃金娘科。同一种植物显然属于同一科,因此:石蒜(桃金娘科)石蒜;然而,这两个属于同一个家族,但却被重复印刷:姜黄(姜科)和姜;
有什么想法吗?
答案1
我们还可以通过提供一个自动添加家族名称的命令来简化语法,\plantF
只要它与最后排版的家族名称不同。
这个想法和你的一样,但我们需要深入研究内部结构;特别是,的家族名称araca
存储在中\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}
请注意,在最后一段中,由于 ,再次打印了家庭\resetfamily
。
答案2
我特意先留下其他答案,以便我的答案能列在最上面;-)
\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}
使用 biocon 的内部结构。
答案3
这不起作用。\plant[Family]{acafrao}
是非常复杂的命令,绝对不可扩展,并且您不能在 ifthenelse 中使用它。
您可以尝试这样的方法,但我不知道这个包,所以我只是猜测它会起作用:
\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}