宏擴充和biocon包

宏擴充和biocon包

我正在使用該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}

相關內容