3

I have a command \by{ } that lets me list authors of an article like this:

\by{
{author 1}{tagline} \\
{author 2}{tagline} \\
{author 3}{tagline} \\
<etc.>
}

enter image description here

I would like to store author 1, author 2, author 3, etc. in some sort of list and print that list like this:

author 1 \\
author 2 \\
author 3 \\
<etc.>

I also want to be able to add names manually (i.e. names that are not used in \by). An exaple of this is the name Jane in the MWE.

One important thing is that each name only appears once in the list. If author 1 has written two articles, their name should still only appear once in the printed list of authors.

I also have an environment \mytextbox for displaying this list. However, I do not want to modify this environment to automaticually print authors, because I still want to be able to manually input authors in this environment as a "failsafe" if, for some reason, there should be an error with the automatic list (for example because of a new imported package in the future or another new pice of code). I chose to include this environment in the MWE to ensure that solutions will be compatible with it.

MWE:

\RequirePackage{fix-cm}
\documentclass[fontsize=13pt,paper=a4,openany,parskip=half,DIV=calc]{scrbook}
\usepackage[T1]{fontenc}
\usepackage{DejaVuSans} % Sans-serif
\usepackage{lipsum}


% mytextbox environment:
\RequirePackage{eso-pic}
\newcommand{\overlaytextbox}[3]{% \placetextbox{<horizontal pos>}{<vertical pos>}{<stuff>}
        \AddToShipoutPictureFG*{%
        \put(\LenToUnit{#1\paperwidth},%
        \LenToUnit{#2\paperheight}){\vtop{{\null}\parbox{0.3\textwidth}{#3}}}
  }%
}%
\newcommand{\mytextbox}[2][black]{%
    \overlaytextbox{0.05}{0.94}{% 0.65 og 0.94 for plassering til høyre
        \color{#1}
        \subsubsection*{Authors}%
        %\vspace{3mm}%
        \linespread{1.6}\selectfont
            {\itshape
            #2
            }%
    }%
}%

% \by command:
\def\by#1{\vspace{1mm}{\centering\fontsize{7}{10}\sffamily Written by \\}\vspace{5pt}\setbox1=\box0 \setbox1=\box3 \byA\\#1\end}
\def\byA#1{\ifx\end#1\expandafter\byC
   \else
   \expandafter\byB
   \fi
}
\def\byB#1#2{%
   \ifvoid3
      \setbox1=\hbox{\makebox{\vtop{\halign{\hfil##\hfil\cr{\fontsize{9}{11}\sffamily\MakeUppercase{#1}}\vspace{-5pt}\cr{\fontsize{7}{10}\sffamily#2}\cr}}}}%
      \ifvoid0\setbox0=\box1
      \else
         \setbox2=\hbox{\unhcopy0 \ \hspace{2mm}{\fontsize{7}{10}\sffamily and} \hspace{2mm} \unhcopy1 \ \hspace{2mm} {\fontsize{7}{10}\sffamily et al.}}
         \ifdim\wd2>\hsize 
            \setbox3=\hbox{ \unhbox0 \ \hspace{2mm}{\fontsize{7}{10}\sffamily et al.}\hspace{2mm}}
         \else
            \setbox0=\hbox{\unhbox0 \ \hspace{2mm}{\fontsize{7}{10}\sffamily and}\hspace{2mm} \unhbox1}
         \fi
      \fi
   \fi
   \byA
}
\def\byC{\ifvoid3 \setbox3=\box0 \fi \hbox to\hsize{\hss\box3\hss}\bigskip}

\begin{document}
\hfill
\begin{minipage}[t]{0.6\textwidth}
\begin{center}
    \lipsum[1-2]
\end{center}
\end{minipage}

\mytextbox[red]{
% some command to list authors here:
% for exaple \authorlist
Someone \\
Firstname Lastname \\
Myname is Bond \\
Paul \\
Jane \\
}
\clearpage

{\centering \sffamily\textbf{First Article}\\}
\by{
  {Someone}{Tagline}
}

\lipsum[1]

{\centering \sffamily\textbf{Second Article}\\}
\by{
{Firstname Lastname}{Hey ho matey yo ho} \\
{Someone}{New tagline}\\
{Myname is Bond}{Secret Service} \\
{Paul}{Physicist}
}

\lipsum[1]

{\centering \sffamily\textbf{Third Article}\\}
\by{
{Paul}{Still a physicist}
}

\lipsum[1]

{\centering \sffamily\textbf{Poem}\\}

\begin{center}
    foo \\
    baz \\
    baa foo!
\end{center}

Thank you Jane for creating this poem!

\end{document}

How can I do this? Where can I find more information on how to make lists like this in LaTeX? I guess I have to have some sort of if case to check if the author already is on the list?

The only solution I can currently think of would be an expl3 token list and \str_case:nnF{ author }{ {<compare to list element>}{} }{ <add to list> }. However, I think it may not be a good idea to combine expl3 and plain TeX. Also, I'm not entierly sure on how to implement this approach.

1 Answer 1

4

You can add \addauthor{#1} into the \byB macro (on the top of this macro):

\def\byB#1#2{%
   \addauthor{#1}%
   \ifvoid3
   ...

and you can define the macro \addauthor:

\def\authorlist{}
\def\addauthor#1{\immediate\write\csname @mainaux\endcsname{\string\xauthor{#1}}}
\def\xauthor#1{%
   \unless \ifcsname xa:#1\endcsname
      \expandafter\gdef\csname xa:#1\endcsname{}
      \expandafter\gdef\expandafter\authorlist\expandafter{\authorlist #1\\}
   \fi
}

Finally, you can use \authorlist in your red box because this list includes

author1\\author2\\author3\\...

after the second run of TeX. We used the .aux file because you want to know \authorlist before authors are read by \by.

If you want to add Jane to the list, you can do this manually in your red box or you can write \addauthor{Jane} after the "foo baz baa foo" poem in the "Thanks" text.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .