1

In economics, author order is traditionally alphabetical. Due to the known bias induced by this ordering, there is small movement to randomly order a paper's authors (example).

I can order document authors at compile time using pgfmathrandom, but this is insufficiently random. I would like to order authors dynamically at view time. The examples I can find of implementing Javascript functionality in LaTeX/PDF are inapplicable, as they do not handle directly adjusting document content (example).

Desired MWE (\maketitle does not need to be overridden, that part is simple):

 \documentclass{article}

 \usepackage{[magic-package]}

 \addauthor{Aaron}
 \addauthor{Zhang}

 \begin{document}
 \maketitle

 \end{document}

Should yield:

 +--------------+               +--------------+
 | Aaron, Zhang |               | Zhang, Aaron |
 |              |               |              |
 | Lorem ipsum  | w.p. 1/2,     | Lorem ipsum  | w.p. 1/2.
1

Here's an option using the eforms package.

It randomises the authors at document opening time using JavaScript and puts the result in a form field where the author is normally inserted in the title page.

There are some limitations though:

  • It's not really easy to use a non-standard font in PDF form text fields, so I've use Times everywhere.
  • You have to specify the height of the text field, so if your number of authors exceeds one line you'll need to adjust it manually. This could probably be automated if you were really keen.
  • And of course, it requires Adobe Reader.

MWE

\documentclass{article}

\usepackage{newtxtext,newtxmath}
\usepackage[useui]{eforms}

\newcommand{\randauthorformat}{%
  border={invisible},
  textsize={11.5},
  textfont={Times-Roman},
  align={centered},
  fieldflags={readonly,multiline,noscrolling},
  % Default value for readers that don't support JavaScript
  value={Author One, Author Two, Author Three, and Author Four},
  pageopen={%
    % Add authors to array
    var array = ["Author One", "Author Two", "Author Three", "Author Four"];
    % Shuffling algorithm from https://stackoverflow.com/a/2450976/12652399
    var currentIndex = array.length, temporaryValue, randomIndex;
    while (0 !== currentIndex) {
      randomIndex = Math.floor(Math.random() * currentIndex);
      currentIndex -= 1;
      temporaryValue = array[currentIndex];
      array[currentIndex] = array[randomIndex];
      array[randomIndex] = temporaryValue;
    }
    var i = array.length;
    currentIndex = 0;
    var authors = "";
    while (currentIndex < array.length) {
      authors += array[currentIndex];
      if (currentIndex < array.length - 1) {
        authors += ", ";
      }
      if (currentIndex == array.length - 2) {
        authors += "and ";
      }
      currentIndex += 1;
    }
    var f = this.getField("author");
    f.value = authors;
  }
}
\newcommand{\randauthor}{%
  \textField[\ui{presets=\randauthorformat}]{author}{\linewidth}{11.5pt}}

\title{Randomised Authors}
\author{\randauthor}

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

MWE output

1
  • Cool. The API documentation is ~800 pages long, it's tough to know where to start. Will play around with this, then accept. [ETA: +100 for randomness, the authors re-order every time you scroll back to the list] – kyle Sep 22 '20 at 19:57

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.