1

I would like to understand if there is a simple way to implement the following feature in LaTeX:

I would like to create mycustomsty.sty that I would call like this:

\usepackage[author={string1, string2, ..., stringN}]{mycustomsty}

and that would have the same output as simply typing:

\author{string1 \and string2 \and ... \and stringN}

directly in the TeX file.

1
  • The package filecontents is used to have one single file (MWE). Of course you can put the sty in a separate file.
  • Use kvoptions to pass the string to the package.
  • Use xstring to make string substitutions.
  • To make it possible to replace a string with a command (\and), witch should not be expanded, but also interpret the inputstring as an expanded command \expandarg is used. (from xstring documentation: "In this case, the first token of each argument is expanded one time while all other tokens are left unchanged")

Code:

\documentclass{article}

\usepackage{filecontents}

\begin{filecontents}{myauthorgenerator.sty}
    \NeedsTeXFormat{LaTeX2e}[1994/06/01]
    \ProvidesClass{myauthorgenerator}[2018/06/03]

    \RequirePackage{kvoptions}
    \RequirePackage{xstring}

    \DeclareStringOption{author}[unknown]
    \ProcessKeyvalOptions*

    \author{%
        \saveexpandmode\expandarg%
        \StrSubstitute{\myauthorgenerator@author}{,}{\and }%
        \restoreexpandmode%
    }
\end{filecontents}

\usepackage[author={Frodo,Sam,Pippin, Merry}]{myauthorgenerator}

\title{Title}

\begin{document}
\maketitle
\end{document}

Result:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.