[Tex/LaTex] Package clash between authblk and titling

authblktitlestitling

I'm trying to put several short articles together. Each article has a title and multiple authors with corresponding affiliations. To handle this I use authblk and titling packages:

FirstFile.tex

\Title{First File}
\author[2]{B. Second\thanks{B@Second}}
\author[1]{A. Gonzales\thanks{A@Gonzales}}
\author[1,2]{C. Dosch}

\affil[1]{Test A}
\affil[2]{Test B}

\Content{Bla Bla Bla}

SecondFile.tex

\Title{Second file}
\author[1]{C. Iggy}
\author[2]{H. Uno\thanks{H@Uno}}

\affil[1]{Test 1}
\affil[2]{Test 2}

\Content{Bla Bla Bla}

ThirdFile.tex

\Title{Third File}
\author[1]{A. First}
\author[1,2]{M. Middle\thanks{M@Middle}}
\author[2]{Z. Last}

\affil[1]{Test $\alpha$}
\affil[2]{Test $\beta$}

\Content{Bla Bla Bla}

main.tex

\documentclass{article}

%----
\makeatletter
    \newcommand{\Content}[1]{\def\@Content{#1}} 
    \newcommand{\Title}[1]{\def\@Title{#1}}
\makeatother

%----
\usepackage{titling}
    \pretitle{\begin{center}\Large\bfseries}
    \posttitle{\par\end{center}\vspace{\baselineskip}}
    %\preauthor{}
    %\postauthor{}

%----
\usepackage{authblk}    
    \renewcommand\Authfont{\bfseries}
    \renewcommand\Affilfont{\rm \sl\small}

%----
\date{}
%===================================%   B E G I N   %===================================%
\begin{document}

\input{FirstFile.tex}
\makeatletter
    \title{\@Title}
    \maketitle
    \@Content
    \global\let\AB@authlist\@empty
    %\renewcommand\AB@authlist{}
    \renewcommand\AB@affillist{}
\makeatother

\setcounter{affil}{0}
\setcounter{authors}{0}
\emptythanks

\clearpage


%===============
\input{SecondFile.tex}

\makeatletter
    \title{\@Title}
    \maketitle
    \@Content
    \renewcommand\AB@authlist{}
    \renewcommand\AB@affillist{}
\makeatother

\setcounter{affil}{0}
\setcounter{authors}{0}
\emptythanks

\clearpage


%===============
\input{ThirdFile.tex}

\makeatletter
    \title{\@Title}
    \maketitle
    \@Content
    \renewcommand\AB@authlist{}
    \renewcommand\AB@affillist{}
\makeatother

\setcounter{affil}{0}
\setcounter{authors}{0}
\emptythanks

\clearpage


\end{document}

When I compile main.tex I get the following error (twice; the other one is in line 61):

[1{C:/ProgramData/MiKTeX/2.9/pdftex/config/pdftex.map}] (SecondFile.tex)

! LaTeX Error: There's no line here to end.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.48    \maketitle

? 

I noticed that if I don't reset AB@authlist and AB@affillist, the problem with the line ending doesn't appear. If I uncomment \preauthor{} and \postauthor{}, the problem is also gone but all authors and affiliations are aligned to the left. Putting \centering or \begin{center} \end{center} into \pre and \postauthor{} doesn't solve the alignment problem.

Does anyone know if there is another way to reset the content of AB@authlist and AB@affillist or what else might be causing the line ending problem?

I wouldn't have to use titling package if I could use \maketitle several times. Is it possible to modify \maketitle without titling package in such a way that it could be used multiple times?

Best Answer

I'm not sure if this is how it is meant to look. This basically loads titling first and tweaks the redefinition of \maketitle by authblk. I've also defined some new commands for convenience so that \myinput{greatpaper} will input greatpaper.tex, issue \maketitle, \@Content and clean up ready for the next file.

Note that I've switched from the obsolete 2.09 syntax for font switches to the current 2e syntax. The obsolete switches (e.g. \rm, \sl and other two-letter switches) ought not to be used in LaTeX documents and have been deprecated for over two decades. This is not just a question of different commands: the new font commands (e.g. \rmfamily, \slshape, \textsl{} and similar) behave differently and, in particular, are designed to do what you would expect in various cases where the two-letter switches do not. There is a question on site which explains the issue in all its gory glory. Just search if you are interested in the lurid details.

Here's the code:

\begin{filecontents}{FirstFile.tex}
\title{First File}
\author[2]{B. Second\thanks{B@Second}}
\author[1]{A. Gonzales\thanks{A@Gonzales}}
\author[1,2]{C. Dosch}

\affil[1]{Test A}
\affil[2]{Test B}

\Content{Bla Bla Bla}
\end{filecontents}
\begin{filecontents}{SecondFile.tex}
\title{Second file}
\author[1]{C. Iggy}
\author[2]{H. Uno\thanks{H@Uno}}

\affil[1]{Test 1}
\affil[2]{Test 2}

\Content{Bla Bla Bla}
\end{filecontents}
\begin{filecontents}{ThirdFile.tex}
\title{Third File}
\author[1]{A. First}
\author[1,2]{M. Middle\thanks{M@Middle}}
\author[2]{Z. Last}

\affil[1]{Test $\alpha$}
\affil[2]{Test $\beta$}

\Content{Bla Bla Bla}
\end{filecontents}

\documentclass{article}
\usepackage{titling}
\usepackage{authblk}
\renewcommand\Authfont{\bfseries}
\renewcommand\Affilfont{\rmfamily\slshape\small}
\makeatletter
\newcommand{\Content}[1]{\def\@Content{#1}}
\pretitle{\begin{center}\Large\bfseries}
\posttitle{\par\end{center}\vspace{\baselineskip}}
\newcommand*\myinput[1]{% convenience command
  \input{#1}%
  \maketitle
  \@Content
  \clearpage
  \renewcommand\AB@affillist{}%
  \global\let\AB@authlist\@empty
  \renewcommand\AB@authlist{}%
  \setcounter{affil}{0}%
  \setcounter{authors}{0}%
  \emptythanks}
\def\maketitle{\AB@maketitle}% modified from authblk.sty
\makeatother
\date{}
\begin{document}
\myinput{FirstFile}
\myinput{SecondFile}
\myinput{ThirdFile}
\end{document}

multiple titles and contents