我正在尝试实现我自己的\affiliation
和版本,以便在海报中使用。我希望有选项以、和\author
的形式显示隶属关系索引。阿拉伯语和 alphaph 输出都可以正常工作,但 不行。\arabic
\alph
\fnsymbol
\fnsymbol
梅威瑟:
\documentclass[]{article}
\usepackage{etoolbox}
\begin{document}
\newcounter{x}
\csxdef{tmp}{}
\stepcounter{x}
\csxdef{tmp}{\csuse{tmp}\alph{x},}
\stepcounter{x}
\csxdef{tmp}{\csuse{tmp}\alph{x}}
Authorname$^{\csuse{tmp}}$ %
\setcounter{x}{0}
\csxdef{tmp}{}
\stepcounter{x}
\csxdef{tmp}{\csuse{tmp}\arabic{x},}
\stepcounter{x}
\csxdef{tmp}{\csuse{tmp}\arabic{x}}
Authorname$^{\csuse{tmp}}$ %
\setcounter{x}{0}
\csxdef{tmp}{}
\stepcounter{x}
\csxdef{tmp}{\csuse{tmp}\fnsymbol{x},}
\stepcounter{x}
\csxdef{tmp}{\csuse{tmp}\fnsymbol{x}}
Authorname$^{\csuse{tmp}}$ %
\setcounter{x}{0}
\csxdef{tmp}{}
\stepcounter{x}
\csxdef{tmp}{\csuse{tmp}\alph{x},}
\stepcounter{x}
\csxdef{tmp}{\csuse{tmp}\alph{x}}
Authorname$^{\csuse{tmp}}$ %
\end{document}
输出:
以及错误信息:
Missing } inserted. ...csuse{tmp} $\to$ Authorname$^{\csuse{tmp}
我理解,这\fnsymbol
会产生数学模式输出,而我的代码缺少文本和数学模式之间的正确切换,但我找不到发生这种情况的地方。
答案1
感谢大家,我凌乱的最终代码已经准备好了。这是我第一次编写软件包和使用 etoolbox。
% avauthors.sty
\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{avauthors}[2015/09/20 Authors and Affiliations]
\RequirePackage{etoolbox}
\RequirePackage{xstring}
\RequirePackage{tikz}
\newcommand{\avindex}[1]{\arabic{#1}}
\newif\if@alph\@alphfalse
\DeclareOption{alph}{\@alphtrue%
\renewcommand{\avindex}[1]{\alph{#1}}%
}
\DeclareOption{fn}{\renewcommand{\avindex}[1]{\fnsymbol{#1}}}
\DeclareOption{roman}{\renewcommand{\avindex}[1]{\roman{#1}}}
\DeclareRobustCommand*\superscript[1]{%
\@superscript{\selectfont#1}%
}
\def\@superscript#1{%
\if@alph
{\m@th\ensuremath{^{\textit{\mbox{\fontsize\sf@size\z@#1}}}}}%italic for letters
\else
{\m@th\ensuremath{^{\mbox{\fontsize\sf@size\z@#1}}}}%
\fi
}
\ProcessOptions\relax
\newcounter{avnumauthor}
\newcounter{avnumaffil}
\newcounter{avnumauthaffil}
\newcounter{avnumaffils}
\newcounter{avaffilindex}
\newcounter{avcounta}
\newcounter{avcntb}
\newcounter{avcntc}
\renewcommand{\author}[1]{
\stepcounter{avnumauthor}
\setcounter{avnumaffil}{0}
\listadd{\authors}{#1}
\csdef{author\theavnumauthor}{#1}
}
\newcommand{\affiliation}[1]{
\stepcounter{avnumaffils}
\stepcounter{avnumaffil}
\stepcounter{avaffilindex}
\stepcounter{avnumauthaffil}
\foreach \i in {1,...,\theavaffilindex}{
\setcounter{avcounta}{\i}
\IfStrEq
{\csuse{affil\theavcounta}}
{#1}
{\setcounter{avaffilindex}{\theavcounta}
\addtocounter{avnumaffils}{-1}
}{}
}
\csxdef{affil\theavaffilindex}{#1}
\csxdef{affindex\theavnumauthaffil}{\theavaffilindex}
\csxdef{auth\theavnumauthor}{\theavnumaffil}
\setcounter{avaffilindex}{\theavnumaffils}
}
\newcommand{\processall}{
\setcounter{avcounta}{0}
\foreach \i in {1,...,\theavnumauthor}{
\stepcounter{avcntb}
\csxdef{tmpb}{}%
\foreach \j in {1,...,\csuse{auth\theavcntb}}{%
\stepcounter{avcounta}%
\setcounter{avcntc}{\csuse{affindex\theavcounta}}
\csxdef{tmpb}{\csuse{tmpb}\avindex{avcntc}}
\ifnum \j < \csuse{auth\theavcntb}
\csxdef{tmpb}{\csuse{tmpb},}
\fi
}%
\csxdef{authfa\theavcntb}{\csuse{tmpb}}
}
}
\newcommand{\printauthor}[1]{
\csuse{author#1}\superscript{\csuse{authfa#1}}%
}
\newcommand{\printaffil}[1]{
\setcounter{avcntb}{#1}%
\superscript{\avindex{avcntb}}\csuse{affil#1}
}
\endinput
我们:
\documentclass[]{article}
\usepackage[fn]{avauthors} % no option: arabic; options: roman, alph and fn
\begin{document}
\author{Author A}
\affiliation{Physics Dept.}
\author{Author B}
\affiliation{Physics Dept.}
\affiliation{Chemistry Dept.}
\author{Author C}
\affiliation{Chemistry Dept.}
\affiliation{Biology Dept.}
\author{Author D}
\affiliation{Physics Dept.}
\affiliation{Geology Dept.}
\processall{}
\printauthor{1}
\printauthor{2}
\printauthor{3}
\printauthor{4}
\printaffil{1}
\printaffil{2}
\printaffil{3}
\printaffil{4}
\end{document}