在学术出版物中,有一条经验法则:第一次给出物种名称时,应完整写出属和种……第二次可以缩写属。
第一次:
大肠杆菌
第二次:
大肠杆菌
我想要一种乳胶方法来自动完成此操作。经过一番搜索,我最终想到了这个,我想分享一下。
%% Meta-Command for defining new species macros
\newcommand{\species}[4]{\newcommand{#1}{\ifdefined
#2{\itshape #4}\xspace \else\newcommand{#2}{}{\itshape
#3}\xspace \fi}
}
%% Defining new species
% The first argument is the name of the macro you will call in the document.
% The second argument is the name of a flag that is used to keep track of if this is the first time the macro is being called.
% The third argument is what is written the first time the macro is called
% The fourth argument is what is written every subsequent time the macro is called.
\species{\ecoli}{\ecolihbd}{Escherichia coli}{E.\;coli}
\species{\rsphaeroides}{\rspaheroideshbd}{Rhodobacter
sphaeroides}{R.\;sphaeroides}
\species{\abrasilense}{\abrasilensehbd}{Azospirillum
brasilense}{A.\;brasilense}
\species{\celegans}{\celeganshbd}{Caenorhabditis elegans}{C\;elegans}
\species{\pseudomonads}{\pseudomonadshbd}{Pseudomonads}{Pseudomonads}
%%
%%% Then later on, in the document:
\ecoli is an example of a model species. People study \ecoli because
people have studied \ecoli.
输出:
大肠杆菌就是一个典型模型物种。人们研究大肠杆菌是因为人们研究过大肠杆菌。
答案1
你不需要标志:只需定义宏来打印完整的名称,然后全球重新定义自身以打印缩写名称。需要全局定义,因为第一次出现可能在一个组中(例如,一个环境中)。
\documentclass{article}
\usepackage{xspace}
%% Meta-Command for defining new species macros
\newcommand{\species}[3]{%
\newcommand{#1}{\gdef#1{\textit{#3}\xspace}\textit{#2}\xspace}}
%% Defining new species
% The first argument is the name of the macro you will call in the document.
% The second argument is what is written the first time the macro is called
% The third argument is what is written every subsequent time the macro is called.
\species{\ecoli}{Escherichia coli}{E.~coli}
\species{\rsphaeroides}{Rhodobacter sphaeroides}{R.~sphaeroides}
\species{\abrasilense}{Azospirillum brasilense}{A.~brasilense}
\species{\celegans}{Caenorhabditis elegans}{C.~elegans}
\species{\pseudomonads}{Pseudomonads}{Pseudomonads}
%%
\begin{document}
\ecoli is an example of a model species. People study \ecoli because
people have studied \ecoli.
\end{document}
答案2
我会用glossaries
为了这。
\documentclass{article}
\usepackage[acronym]{glossaries}
\newacronym[first={Escherichia coli}]{ecoli}{E. coli}{Escherichia coli}
\begin{document}
\Gls{ecoli} is an example of a model species. People study \gls{ecoli} because
people have studied \gls{ecoli}.
\end{document}
创建\species
宏来创建\newacronym
应该非常简单。该glossaries
包会自动处理第一次/后续使用,并处理大写和复数。它还具有创建首字母缩略词列表的出色功能。
答案3
从 egreg 的回答开始,此示例使用不同的语法来解决 xspace 和斜体校正的问题。物种使用\newspecies
并\species
设置物种名称来定义。
\documentclass{article}
\newcommand*{\speciesformat}[1]{\textit{#1}}
\newcommand{\newspecies}[3]{%
\expandafter\newcommand\csname species@#1\endcsname{%
\expandafter\gdef\csname species@#1\endcsname{#3}%
#2%
}%
}
\makeatletter
\newcommand*{\species}[1]{%
\speciesformat{%
\@ifundefined{species@#1}{%
\latex@error{Species `#1' is undefined}\@ehc
[#1]%
}{%
\csname species@#1\endcsname
}%
}%
}
\makeatother
\newspecies{ecoli}{Escherichia coli}{E.~coli}
\newspecies{rsphaeroides}{Rhodobacter sphaeroides}{R.~sphaeroides}
\newspecies{abrasilense}{Azospirillum brasilense}{A.~brasilense}
\newspecies{celegans}{Caenorhabditis elegans}{C.~elegans}
\newspecies{pseudomonads}{Pseudomonads}{Pseudomonads}
\begin{document}
\textbf{\species{ecoli} is an example} of a model species.
People study \species{ecoli} because people have
studied \species{ecoli}.
\end{document}
一些评论:
该示例使用
\textbf
第一次\species
调用来展示为什么全局重新定义在这里很重要。该语法使包过时。在句号之前
xspace
的最后一次调用中可以看到隐藏的斜体更正。\species
下例计算缩写形式。如果长格式由两个以上的单词组成,则第一个单词被缩写。
\documentclass{article}
\newcommand*{\speciesformat}[1]{\textit{#1}}
\makeatletter
\newcommand{\newspecies}[2]{%
\expandafter\newcommand\csname species@#1\endcsname{%
\expandafter\speciesMakeShort\csname species@#1\endcsname#2 \@nil{#2}%
#2%
}%
}
\makeatletter
% Assumption: the first word consists of more than one letter.
\def\speciesMakeShort#1#2 #3\@nil#4{%
\begingroup
\def\x{#3}%
\ifx\x\@empty
% one word, no spaces
\gdef#1{#4}%
\else
\species@MakeShort#1#2 #3\@nil
\fi
\endgroup
}
\def\species@MakeShort#1#2#3 #4 \@nil{%
\gdef#1{#2.~#4}%
}
\newcommand*{\species}[1]{%
\speciesformat{%
\@ifundefined{species@#1}{%
\latex@error{Species `#1' is undefined}\@ehc
[#1]%
}{%
\csname species@#1\endcsname
}%
}%
}
\makeatother
\newspecies{ecoli}{Escherichia coli}
\newspecies{rsphaeroides}{Rhodobacter sphaeroides}
\newspecies{abrasilense}{Azospirillum brasilense}
\newspecies{celegans}{Caenorhabditis elegans}
\newspecies{pseudomonads}{Pseudomonads}
\begin{document}
\textbf{\species{ecoli} is an example} of a model species.
People study \species{ecoli} because people have
studied \species{ecoli}.
\begin{center}
\begin{tabular}{ll}
\species{rsphaeroides} & \species{rsphaeroides} \\
\species{abrasilense} & \species{abrasilense} \\
\species{celegans} & \species{celegans} \\
\species{pseudomonads} & \species{pseudomonads} \\
\end{tabular}
\end{center}
\end{document}