REVTex-like affiliation& author command

by Intercombats   Last Updated March 20, 2016 08:09 AM

I am trying to implement my own version of \affiliation and \author to use in my posters. I would like to have options to show indices of affiliations in the form of \arabic, \alph and \fnsymbol. Arabic and alph outputs both work correctly, but not \fnsymbol.

MWE:

\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}

The output:

Output

And error messages:

 Missing } inserted. ...csuse{tmp} $\to$ Authorname$^{\csuse{tmp}

I understand, that \fnsymbol produces math-mode output, and my code is missing proper switching between text and math modes, but I cannot find where this happens.

Tags : etoolbox


Answers 1


Thanks to all, my messy final code is ready. My first experience in writing packages & using 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\[email protected]\@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{%
   \[email protected]
      {\[email protected]\ensuremath{^{\textit{\mbox{\fontsize\[email protected]\[email protected]#1}}}}}%italic for letters
   \else
      {\[email protected]\ensuremath{^{\mbox{\fontsize\[email protected]\[email protected]#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

WE:

\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}

Output: Output

Intercombats
Intercombats
September 22, 2015 07:43 AM

Related Questions



Why won't my boolean work correctly?

Updated July 08, 2016 08:01 AM

Less-than string comparison like \ifstrequal

Updated June 30, 2017 15:23 PM

Using \docsvlist on a generated list with newcommand

Updated August 25, 2017 16:23 PM

question of \ifstrequal in etoolbox

Updated September 16, 2017 21:23 PM