# hyperref' and biblatex' used with the combine' package

I'm facing a hard time getting the combine package to work with biblatex and hyperref. My minimalistic example:

Some article to be included in combine'd document (article-1.tex):

\documentclass[a5paper,twocolumn]{article}
\input{common}

\title{Some Title}
\date{}
\author[1]{Some Author}
\author[2]{Another Author}
\affil[1]{Some where}
\affil[2]{Else}

\begin{document}
\maketitle
This is some text, even citing some publicaton: \cite{patrick2011}.

\printbibliography
\end{document}


My common.tex just contains some macros that should be available in every article:

\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{gensymb}
\usepackage[backend=biber]{biblatex}
\usepackage{authblk}
\usepackage[german]{babel}
\usepackage[top=1.5cm,bottom=1.5cm,left=1.2cm,right=1.2cm]{geometry}
\usepackage{hyperref}

\providecommand*{\taxon}[1]{\textit{#1}}
\providecommand*{\centigrade}[1]{$#1^\circ\textrm{C}$}
\providecommand*{\kelvin}[1]{$#1\textrm{K}$}
\providecommand*{\person}[1]{\textsc{#1}}


The cham-literature.bib file:

@article{patrick2011,
author  = "David A. Patrick AND Philip Shirk AND James R. Vonesh AND Elizabeth B. Harper AND Kim M. Howell",
title   = "Abundance and Roosting Ecology of Chameleons in the East Usambara Mountains of Tanzania and the Potential Effects of Harvesting",
journal = "Herpetological Conservation \& Biology",
year    = "2011",
volume  = "6",
number  = "3",
pages   = "422--431"
}


And finally the combining document (sourcing only the one article mentioned above)

\documentclass{combine}
\input{common}

\title{Journal 2016-1}
\author{Jan-Benedict Glaw (Hrsg.)}
\date{31. Februar 2016}

\begin{document}
\pagestyle{combine}
\maketitle
\tableofcontents
\clearpage
\begin{papers}
\coltoctitle{Title 1}
\coltocauthor{Author 1}
\import{article-1}
\end{papers}
\end{document}


This works nicely when I remove all the biblatex and hyperref stuff, but well, that's kind of not what I want. Right now, this results in:

! Undefined control sequence.
\@begindocumenthook ...\undef \blx@dopreamblecmds
\let \do \noexpand \expand...
l.11 \begin{document}


Would be quite grateful for any help!

• I'm not really surprised. Given that natbib and cite need special handling and given the acrobatics Biblatex does and given the doctoring to basic stuff done by hyperref ... it would be pleasantly astonishing if it all happened to work ;). – cfr Aug 10 '16 at 3:16
• I think that Biblatex undefines various commands at \begin{document}. (See biblatex.sty.) These include \blx@dopreamblecmds. You can surely work around this, but I suspect it is only the beginning of the troubles .... – cfr Aug 10 '16 at 3:31
• Well, going for Bibtex instead of biblatex (would love to keep ist, but I'd let it go), this remains with hyperref: ! Undefined control sequence. \@begindocumenthook ...fi \Hy@AtBeginDocumentHook  {}\let \Hy@AtBeginDocument... l.15 \begin{document} – Jan-Benedict Glaw Aug 10 '16 at 20:56
• Both hyperref and Biblatex redefine a lot of LaTeX internals, as does combine. There are some suggestions in combine's manual for working around or avoiding errors. Did you try those? – cfr Aug 10 '16 at 21:38
• I finallyy gave up on trying to get combine working with anything more complicated than very simple articles (ie. without hyperref, biblatex etc.) Now building a script to build the articles individually, and later on combining them with pdfpages (combined with pax) into a final document. – Jan-Benedict Glaw Aug 14 '16 at 12:42

I had the same problem when trying to generate conference proceedings using combine, with each article being able to use biblatex. My solution is below. Additionally, I needed to leave the option to use built-in thebibliography environment for some articles. Although I did not have to use hyperref, I am sure this solution works for it as well.

## Some lyrical digression

The problem with \import {subfile} command from combine class given in main.tex is that it redefines \jobname macro to subfile. Additionally, it redirects AUX file output from main.aux to subfile.aux. This is needed for the labels and citations to be local for each subfile. This also results in redirecting output from main.bcf (biblatex auxiliary file) to subfile.bcf. This is incompatible with biber as it tries to read main.bcf, which becomes partially generated, as well as subfile.bcf. I could manage to make biblatex write subfile.bcf correcly, but this does not help with typesetting main.tex with correct bibliography. I also tried to "patch" combine so it would not redirect output to subfiles, but I got even more problems.

Finally, I decided to abandon \import altogether in favor of \input from docmute package (the same functionality from newclude package seems to be broken for the long time). I still use combine to typeset the table of contents with article titles and authors.

## The solution

The article data are stored in the newpapers.csv file with the following structure:

<authors to appear in TOC>;<relative path>;<TEX file name>;<BIB file name>
...


The directory structure is supposed to be similar to the proceedings volume archive generated by EasyChair.

\documentclass %
[ %
% Options...
] %
{combine}

\usepackage {datatool}    % to read the list of articles from an external file
\usepackage {docmute}     % \input command that reads only document environment
\usepackage {titling}     % to enable using \maketitle many times

\let \bibtexcite \cite    % remembering the original \cite

\usepackage {csquotes}
\usepackage %
[ %
% Options...
] %
{biblatex}

\let \biblatexcite \cite

\DTLsetseparator {;}

[ %
keys = {name,relpath,texfile,bibfile}, %
] %
{newpapers} %
{newpapers.csv}

\def \sominternalmacro {}

\begin {DTLenvforeach*} %
{newpapers} %
{\myname=name,\relpath=relpath,\texfile=texfile,\bibfile=bibfile} %
%
% Test whether \bibfile is empty
\ifx \sominternalmacro \bibfile \sominternalmacro
% Nothing
\else
{papers/00010\relpath/\bibfile.bib}
% EasyChair directory structure
\fi
%
\end {DTLenvforeach*}

% ----------------------------------------------------------------
\begin {document}
% ----------------------------------------------------------------

% Title page, foreword, etc....

\clearpage

\tableofcontents

\let \oldmaketitle \maketitle

% Used to disable adding sections from articles to the TOC

\newcommand {\nocontentsline} [3] %
{}

\def \maketitle %
{%
%
% Adding the title and authors to the TOC
%
{toc} %
{%
\protect \contentsline {coltoctitle}%
{\protect \numberline {}\thetitle} {\thecolpage}%
}%
%
{toc} %
{coltocauthor} %
{\protect \numberline {}\myname}
%
\oldmaketitle
%
% Disabling adding sections from articles to the TOC
%
\setcounter {section} {0}
\setcounter {subsection} {0}
\setcounter {figure} {0}
\setcounter {table} {0}
}%

% Looping over each article:

\begin {DTLenvforeach*} %
{newpapers} %
{\myname=name,\relpath=relpath,\texfile=texfile,\bibfile=bibfile} %
%
% Some custom definitions...
%
\clearpage
%
% If bibfile is empty,
\ifx \sominternalmacro \bibfile \sominternalmacro
% use the usual LaTeX \cite
\let \cite \bibtexcite
\else
% otherwise, use biblatex \cite
\let \cite \biblatexcite
%
% Start a new biblatex reference section with local references
\newrefsection %
[papers/00010\relpath/\bibfile.bib]
\fi
%
% Input the article TEX file
\input {papers/00010\relpath/\texfile}
%
% Other settings...
%
\end {DTLenvforeach*}

% ----------------------------------------------------------------
\end {document}
% ----------------------------------------------------------------

• I should add that in this solution, other counters should probably be reset along with section. Without it, all figures, tables, etc. have the global numbering throughout the collection, which is usually not the desired behavior. – stu003 Apr 6 '17 at 12:16
• Added resetting figure and table counters for each article. – stu003 Apr 10 '17 at 23:40

In the end, I couldn't make combine' to really work with anything more complex than some simple paragraphs of text.

My solution was to have the articles freestanding as usual, and have (besides all other stuff) this in a central .tex file \input{}ed by every article:

\usepackage{catchfile}
\newcommand{\getenv}[2][]{
\CatchFileEdef{\temp}{"|kpsewhich --var-value #2"}{}
\if\relax\detokenize{#1}\relax\temp\else\let#1\temp\fi
}


Within the preamble in each article, I fetch some data from environment variables, ie.:

\getenv[\STARTPAGENUMBER]{STARTPAGENUMBER}
\getenv[\PUBLISHEDINIFO]{PUBLISHEDINIFO}


used later on to print a publishing info (year, issue, page range) on every article's first page as well as to adjust the starting page number:

\begin{document}
\IfInteger{\STARTPAGENUMBER}{
\setcounter{page}{\STARTPAGENUMBER}
}{}
\maketitle

\begin{tikzpicture}[remember picture, overlay]
\node [anchor=north, yshift=-0.8cm] at (current page.north)
{\PUBLISHEDINIFO};
\end{tikzpicture}


Another wrapping LaTeX file is prepared to contain cover pages, the TOC etc., and it pulls in all the individual articles:

\phantomsection