在大多数出版物中,科学名称除了第一次使用外都是缩写的。此外,名称必须斜体且仅通用名称的首字母应大写。
该biocon
包允许为每个物种定义一个标识符来管理所有这些要求,但我不想依赖于记住每个物种的标识符。我还希望每次在同一步骤中包含一个格式良好的嵌套索引条目,这需要手动输入大量代码,从而混淆正文。
因此,我决定以命令的形式为此创建自己的宏\species{Genus}{species}
。 结果是 MWE 运行合理,但我发现一些问题似乎与etoolbox
包有关:
\setbool
表格内部不起作用,无法切换到缩写名称。参数区分大小写,但我无法减少所有可能的出现次数以获得每个物种的唯一布尔值。我试过了,
\providebool{\lowercase{#1#2}}
但没有成功。这样,我可以纠正输出中的大小写变化,但每次都有不同的布尔值,因此宏无法切换到缩写形式,更糟糕的是,会产生重复的索引条目。
\documentclass[11pt]{article}
\usepackage{etoolbox}
\usepackage{xstring}
\usepackage{mfirstuc}
\usepackage[colorlinks=true,linkcolor=blue]{hyperref}
\usepackage{makeidx}
\usepackage{biocon}
\makeindex
% Provide \genus{Generic name}
\newcommand\genus[1]{{\em\lowercase{\protect\makefirstuc{#1}}}
\index{#1@{\em\lowercase{\protect\makefirstuc{#1}}}|textbf}}
% Provide \species{Generic name}{specific name}
\newcommand\species[2]{%
\providebool{#1#2}%
\ifbool{#1#2}%
% abbreviated name
{\emph{\uppercase{\StrLeft{#1}{1}}. \lowercase{#2}}}%
% full name
{\setbool{#1#2}{true}{\em\lowercase{\protect\makefirstuc{#1} #2}}}%
%index entry for both types
\index{#1@{\em\lowercase{\protect\makefirstuc{#1}}}!#2@{\em\uppercase{\protect\StrLeft{#1}{1}}. \lowercase{#2}}}}
\begin{document}
\noindent Desired ouput of some \genus{Homo} species:\\\\
\species{Homo}{erectus} \texttt{(full name 1st time, OK)}\\
\species{Homo}{erectus} \texttt{(abbreviation 2nd time, OK)}\\
\species{Homo}{sapiens} \texttt{(indexed as Homo!sapiens, OK)}\\
\species{Homo}{erectus} \\
\species{Homo}{sapiens} \texttt{(indexed as as Homo!sapiens too, OK)}\\
\noindent Testing in tabular environment:\\\\
\begin{tabular}{|l|l|}
\hline\species{Homo}{habilis} & \\
\hline\species{Homo}{habilis} & \texttt{(not working inside tabular)}\\\hline
\end{tabular}\\
\noindent\species{Homo}{habilis} method (try again):\\
\noindent\begin{tabular}{|l|l|}
\hline\species{Homo}{habilis} & \texttt{
(\textbackslash{}setbool worked only outside tabular)}\\\hline
\end{tabular}\bigskip
\noindent Testing case correction:\\
\verb|\species{Homo}{Antecessor}|: \species{Homo}{Antecessor}\\
\verb|\species{Homo}{antecessor}|: \species{Homo}{antecessor}\\
\verb|\species{HOMO}{ANTECEsSOR}|: \species{HOMO}{ANTECEsSOR}\\\\
Problems with these three equivalents commands:\\
\texttt{not abbreviations}\\
\texttt{duplicated "Homo" at index}\\
\texttt{duplicated "antecessor" at index}\\
\printindex
\end{document}
答案1
这也是索引问题的一个希望完整的解决方案。假设物种名称中只有纯 ASCII 字符。
\documentclass[11pt]{article}
\usepackage{makeidx}
\usepackage{biocon}
\usepackage[colorlinks=true,linkcolor=blue]{hyperref}
\makeindex
% Provide \genus{Generic name}
\newcommand\genus[1]{%
\lowercase{\ifcsname genus@#1\endcsname}\else
\definnergenus#1\relax
\fi
\lowercase{\csname genus@#1\endcsname}%
}
\def\definnergenus#1#2\relax{%
\def\tempinitial{#1}%
\lowercase{\def\tempsecond{#2}\def\tempname{#1#2}}%
\begingroup\edef\x{\endgroup
\gdef\unexpanded\expandafter{\csname genus@\tempname\endcsname}{%
\noexpand\emph{\tempinitial\tempsecond}%
\noexpand\index{\tempname@{\noexpand\em\tempinitial\tempsecond}|textbf}%
}%
}\x}
% Provide \species{Generic name}{specific name}
\newcommand\species[2]{%
\lowercase{\ifcsname species@#1#2\endcsname\else}%
\definnerspecies#1\relax{#2}%
\fi
\lowercase{\csname species@#1#2\endcsname}%
\lowercase{\csname speciesindex@#1#2\endcsname}%
}
\def\definnerspecies#1#2\relax#3{%
\uppercase{\def\tempinitial{#1}}%
\lowercase{\def\tempfirst{#1}\def\tempsecond{#2}\def\tempthird{#3}}%
\edef\tempname{\tempfirst\tempsecond\tempthird}%
\begingroup\edef\x{\endgroup
\gdef\unexpanded\expandafter{\csname species@\tempname\endcsname}{%
\noexpand\emph{\tempinitial\tempsecond\space\tempthird}%
\gdef\unexpanded\expandafter{\csname species@\tempname\endcsname}{%
\noexpand\emph{\tempinitial.\ \tempthird}}}}\x
\begingroup\edef\x{\endgroup
\gdef\unexpanded\expandafter{\csname speciesindex@\tempname\endcsname}{%
\noexpand\index{%
\tempfirst\tempsecond@{\noexpand\em\tempinitial\tempsecond}!%
\tempthird@{\noexpand\em\tempthird}}%
}}\x}
\begin{document}
\noindent Desired ouput of some \genus{Homo} species:\\
\\
\species{Homo}{erectus} \texttt{(full name 1st time, OK)}\\
\\
\species{Homo}{erectus} \texttt{(abbreviation 2nd time, OK)}\\
\species{Homo}{sapiens} \texttt{(indexed as Homo!sapiens, OK)}\\
\species{Homo}{erectus} \\
\species{Homo}{sapiens} \texttt{(indexed as as Homo!sapiens too, OK)}
\noindent Testing in tabular environment:\\
\begin{tabular}{|l|l|}
\hline\species{Homo}{habilis} & \\
\hline\species{Homo}{habilis} & \texttt{(works also inside tabular)}\\\hline
\end{tabular}
\noindent\species{Homo}{habilis} method (try again):
\noindent Testing case correction:\\
\verb|\species{Homo}{Antecessor}|: \species{Homo}{Antecessor}\\
\verb|\species{Homo}{antecessor}|: \species{Homo}{antecessor}\\
\verb|\species{HOMO}{ANTECEsSOR}|: \species{HOMO}{ANTECEsSOR}
\printindex
\end{document}
每个\species
命令定义两个命令:例如
\species{Homo}{erectus}
定义
\species@homoerectus
\speciesindex@homoerectus
第一个扩展为直立人并在全球范围内重新定义自己,以扩展到直立人。输入已标准化,因此除了首字母之外,仅使用小写字母。第二个命令处理索引。
如果\speciec@homoerectus
未定义(首次出现时\species{Homo}{erectus}
,则\definespecies
调用全局定义上述两个命令的命令。
类似地,\genus{Homo}
在第一次调用时定义一个具有规范化输入的内部宏\genus@homo
,负责打印名称并发出索引命令。
以下是图片。
答案2
仅供记录。尽管埃格尔提供(几分钟内!)宏的完全重写,与不依赖etoolbook
包的奖励点完美配合,但没有解决为什么\lowercase
像\providebool
我钱包里的钱一样,是不可扩展的。
就像没人能打败我一样,尽管我还不知道如何使用 La(TeX) 的黑暗面,但我还是尝试了解决这个特定问题的方法。幸运的是,这个答案David Carlisle 让我走上了正轨。这是结果,似乎也没有问题:
\documentclass[11pt]{article}
\usepackage{etoolbox}
\usepackage{xstring}
\usepackage{mfirstuc}
\usepackage[colorlinks=true,linkcolor=blue]{hyperref}
\usepackage{makeidx}
\makeindex
% Note: ending % neeeded to avoid extra speces
% Provide \species{Generic name}{specific name}
\newcommand\species[2]{%
% expand lowercase https://tex.stackexchange.com/a/95662/11604
\lowercase{\def\tmpa{#1#2}}% Identifier
\lowercase{\def\tmpb{#1}}% Lower case genus
\lowercase{\def\tmpc{#2}}% Lower case species
\providebool{\tmpa}%
\ifbool{\tmpa}%
{\emph{\uppercase{\StrLeft{#1}{1}}.~\tmpc}}% abbreviated name
{\global\setbool{\tmpa}{true}{\em\lowercase{\protect\makefirstuc{#1} #2}}}% full name
\index{\tmpb@{\em\protect\makefirstuc{\tmpb}}!\tmpc@{\em\uppercase{\protect\StrLeft{\tmpb}{1}}. \tmpc}|textsf}}% Index
% Provide \genus{Generic name}
\newcommand\genus[1]{%
\lowercase{\def\tmpb{#1}}% Lower cases genus
{\em\lowercase{\protect\makefirstuc{#1}}}% Genus name
\index{\tmpb@{\em\protect\makefirstuc{\tmpb}}|textbf}} % Index
\begin{document}
Hominoidea as \species{Heliopithecus}{leakeyi} existed about 16 million years ago, but \species{PaN}{TroglodYTES} diverged from \genus{Homo} genus only about six millions years ago. The \genus{Homo} genus have many extint species as \species{Homo}{AnTecessor}. Problably \species{HOMO}{ANTECESSOR} was a evolutionary link between \species{hOmO}{ErgASter} and \species {Homo}{HEIDELBERGensis}. \species{homo}{Antecessor} is one of the earlist human species.
\newpage
The \genus{Pan}\footnote{Just for testing indexing in footnote, in Spanish \genus{pan} \index{pan (food)|see{bread}} mean "bread"\index{bread}.} actually is composed by \species{pan}{troglodytes} (chimpanzee) and \species{pan}{paniscus} (bonobo\index{bonobo|see{\emph{Pan paniscus}}}).
species, but \genus{hOMO} is represented only by \species{homo}{sapiens} and \index{Human!Dummy people} people that believe the speeches of politicians.
\newpage
Cheeta is a fictional character interpreted by several intelligents \species{Pan}{troglodytes} actors whereas Tarzan character was always an \index{hairless} hairless ape-men.
\printindex
\end{document}