4

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?

0

1 Answer 1

2

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

6
  • Thanks! That solves my problem! As far as I understand the solution was \def\maketitle{\AB@maketitle}?
    – bn83
    Aug 23, 2015 at 22:56
  • One more tiny questions: what is the difference between these two lines: \global\let\AB@authlist\@empty and \renewcommand\AB@authlist{}?
    – bn83
    Aug 23, 2015 at 22:57
  • @bn83 For the first question: yes, basically. In the end, that is probably all I really did. (I did a lot of copying and pasting and inserting things and taking them out on the way, so it was hard to remember what I'd actually done in the end, as opposed to what I'd tried.) About the second: I just copied those from your code without thinking about them too much. But the first is doing nothing in my code, because the second immediately overrides it. They are different:\ifx\AB@authlist\@empty true\else false\fi will return true in one case and false in the other.
    – cfr
    Aug 23, 2015 at 23:56
  • Thanks for your answer. I had those lines in my code but one of them was commented. I wasn't sure which one is correct and if there is any difference between them. Now it's more clear.
    – bn83
    Aug 24, 2015 at 0:18
  • @bn83 You're right. You do actually have both uncommented but for different files i.e you use one command for the first file and the other for the second and third. If they both work, use the \renewcommand.... version as it is preferable to stick to LaTeX syntax when possible.
    – cfr
    Aug 24, 2015 at 0:21

You must log in to answer this question.

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