2

Edit. I edit my question in order to make it clearer.

Preamble. Thanks to filecontents environment, the compilation of the following with pdflatex generates two subfiles:

  1. a bibliographic file: subfile.bib,
  2. a complete .tex file: subfile.tex, that can eventually be processed by pdflatex (+ biber, etc.) in order to get a nice subfile.pdf with the bibliography provided by subfile.bib.

Note that, thanks to the standalone package with its sort option, the main.tex file \inputs the complete subfile.tex without any problem: its compilation with pdflatex (+ biber, etc.) goes smoothly and we also get a nice main.pdf with the bibliography provided by subfile.bib.

% Generates subfile.bib
\begin{filecontents}{subfile.bib}
  @book{foo,
    title                    = {Foo},
    author                   = {Bar},
    date                     = {2015-01-01}
  }
\end{filecontents}
%
% Generates subfile.tex
\begin{filecontents}{subfile}
  \documentclass{article}
  \usepackage[backend=biber]{biblatex}
  \addbibresource{subfile.bib}
  \begin{document}
  Look at \autocite{foo}.
  \printbibliography
  \end{document}
\end{filecontents}
%
% Main file `main.tex`
\documentclass{article}
\usepackage[%
  sort
  % ,group=false
]{standalone}
\usepackage[backend=biber]{biblatex}
\begin{document}
\input{subfile}
\end{document}

The point is, if group=false is commented out in main.tex, then its pdflatex compilation is still okay, but its biber compilation fails with the error:

INFO - This is Biber 2.1
INFO - Logfile is 'main.blg'
INFO - Reading 'main.bcf'
:2239: parser error : Premature end of data in tag section line 2237

^
:2239: parser error : Premature end of data in tag controlfile line 2

and indeed, the two corresponding XML tags in this main.bcf file are not closed.

The standalone package stipulates that:

if group=true (default), the document environment of the subfile is turned into an environment which does nothing, besides adding the usual group. If set to false this environment made transparent, so that no group is added.

Do you see why group=false (no group is added around the content of the subfile) gives this biber error?

Here is my file list:

 *File List*
 article.cls    2014/09/29 v1.4h Standard LaTeX document class
  size10.clo    2014/09/29 v1.4h Standard LaTeX file (size option)
standalone.sty    2015/07/15 v1.2 Package to include TeX sub-files with preambl
es
ifluatex.sty    2010/03/01 v1.3 Provides the ifluatex switch (HO)
   ifpdf.sty    2011/01/30 v2.3 Provides the ifpdf switch (HO)
 ifxetex.sty    2010/09/12 v0.6 Provides ifxetex conditional
 xkeyval.sty    2014/12/03 v2.7a package option processing (HA)
 xkeyval.tex    2014/05/09 v2.6d key=value parser (HA)
currfile.sty    2013/02/01 v0.7b Provides the file path elements of the current
 input file
kvoptions.sty    2011/06/30 v3.11 Key value format for package options (HO)
 ltxcmds.sty    2011/11/09 v1.22 LaTeX kernel commands for general use (HO)
kvsetkeys.sty    2012/04/25 v1.16 Key value parser (HO)
infwarerr.sty    2010/04/08 v1.3 Providing info/warning/error messages (HO)
etexcmds.sty    2011/02/16 v1.5 Avoid name clashes with e-TeX commands (HO)
filehook.sty    2011/10/12 v0.5d Hooks for input files
    main.sta
gincltex.sty    2011/09/04 v0.3 Include external LaTeX files like graphics
svn-prov.sty    2010/04/24 v3.1862 Package Date/Version from SVN Keywords
adjustbox.sty    2012/05/21 v1.0 Adjusting TeX boxes (trim, clip, ...)
 adjcalc.sty    2012/05/16 v1.1 Provides advanced setlength with multiple back-
ends (calc, etex, pgfmath)
trimclip.sty    2012/05/16 v1.0 Trim and clip general TeX material
graphicx.sty    2014/10/28 v1.0g Enhanced LaTeX Graphics (DPC,SPQR)
graphics.sty    2014/10/28 v1.0p Standard LaTeX Graphics (DPC,SPQR)
    trig.sty    1999/03/16 v1.09 sin cos tan (DPC)
graphics.cfg    2010/04/23 v1.9 graphics configuration of TeX Live
  pdftex.def    2011/05/27 v0.06d Graphics/color for pdfTeX
collectbox.sty    2012/05/17 v0.4b Collect macro arguments as boxes
tc-pdftex.def    2012/05/13 v1.0 Clipping driver for pdftex
ifoddpage.sty    2011/09/13 v1.0 Conditionals for odd/even page detection
varwidth.sty    2009/03/30 ver 0.92;  Variable-width minipages
filemod-expmin.sty    2011/09/19 v1.2 Get and compare file modification times (
expandable; minimal)
biblatex.sty    2015/04/19 v3.0 programmable bibliographies (PK/JW/AB)
biblatex2.sty    2015/04/19 v3.0 programmable bibliographies (biber) (PK/JW/AB)

etoolbox.sty    2015/08/02 v2.2a e-TeX tools for LaTeX (JAW)
  logreq.sty    2010/08/04 v1.0 xml request logger
  logreq.def    2010/08/04 v1.0 logreq spec v1.0
  ifthen.sty    2014/09/29 v1.1c Standard LaTeX ifthen package (DPC)
     url.sty    2013/09/16  ver 3.4  Verb mode for urls, etc.
  blx-dm.def
biblatex-dm.cfg
blx-compat.def    2015/04/19 v3.0 biblatex compatibility (PK/JW/AB)
biblatex.def    
standard.bbx    2015/04/19 v3.0 biblatex bibliography style (PK/JW/AB)
 numeric.bbx    2015/04/19 v3.0 biblatex bibliography style (PK/JW/AB)
 numeric.cbx    2015/04/19 v3.0 biblatex citation style (PK/JW/AB)
biblatex.cfg    
filecontents.sty    2011/10/08 v1.3 Create an external file from within a LaTeX
 document
 english.lbx    2015/04/19 v3.0 biblatex localization (PK/JW/AB)
    main.sta
supp-pdf.mkii
pdftexcmds.sty    2011/11/29 v0.20 Utility functions of pdfTeX for LuaTeX (HO)
epstopdf-base.sty    2010/02/09 v2.5 Base part for package epstopdf
  grfext.sty    2010/08/19 v1.1 Manage graphics extensions (HO)
kvdefinekeys.sty    2011/04/07 v1.3 Define keys (HO)
epstopdf-sys.cfg    2010/07/13 v1.3 Configuration of (r)epstopdf for TeX Live
 subfile.tex
 ***********
Denis Bitouzé
  • 9,652
  • 4
  • 27
  • 85
  • You should in any case have the filecontents environments before \documentclass to ensure that their contents is created exactly. I'm not saying that's the problem here, but it will cause problems at some point. – cfr Sep 16 '15 at 00:30
  • Putting the filecontents in the correct place doesn't solve the error you report, though. – cfr Sep 16 '15 at 00:59
  • @cfr Isn't the purpose of filecontents package to allow filecontents environment to be used after \documentclass. But I will edit my question for using it before \documentclass in order to not scramble the message. – Denis Bitouzé Sep 16 '15 at 05:19
  • 1
    I can only assume that biblatex hooks into the document environment to add those closing XML tags, and that is prevented by overriding the document environment to an empty group. Do you need top use group=false or is this a question just out of interest? Indeed you will find \AfterEndDocument{% \blx@auxwrite\blx@bcfout{}{% \blx@xml@endsection\blx@nl \csuse{blx@xml@slistsbib}% \blx@xml@endfile}% \immediate\closeout\blx@bcfout}} in biblatex2.sty so at least the </bcf:controlfile> tag is closed after \end{document} – moewe Sep 16 '15 at 06:06
  • @moewe I need standalone package to be loaded with both options sort and (because of http://tex.stackexchange.com/q/232185/18401) group=false. – Denis Bitouzé Sep 16 '15 at 06:20
  • 1
    Interestingly, \AfterEndDocument seems to work at least to some extend with both group=false and group=true (\AfterEndDocument{\typeout{foo}} works fine with both settings). But it really looks as if the \AfterEndDocument{ hook is ignored ... – moewe Sep 16 '15 at 06:35
  • 1
    @moewe May be related to http://tex.stackexchange.com/q/22995/18401, but it doesn't illuminate the situation for me. – Denis Bitouzé Sep 16 '15 at 07:51
  • 1
    You seem to have found the answer to your own question there. Load the package etoolbox before the standalone package in the main file. – moewe Sep 16 '15 at 08:03
  • @moewe Indeed! In fact, biblatex loads itself etoolbox and needs, in my context to be loaded after standalone. So I guessed such a (silent) reload of etoolbox after standalone would overwrite the benefit of explicitly loading the former before the latter... but I was wrong :) Maybe such a trick reflects that etoolbox/standalone interaction could be improved. Anyway, I let you the precedence of the answer :) – Denis Bitouzé Sep 16 '15 at 08:30
  • Yes, loading biblatex before standalone was my first try, but that does not work (because of the whole subfile procedure) so we have to load etoolbox explicitly before standalone. – moewe Sep 16 '15 at 08:53
  • I have added an answer now. It isn't very long and can't give the insight that the two answers in the linked questions gave. You may want to notify the authors of both packages of this glitch. (They are active here as well.) – moewe Sep 16 '15 at 08:56
  • @moewe I've edited my question to add etoolbox tag. Hence, my question being tagged with both etoolbox and standalone, their authors should be warned. – Denis Bitouzé Sep 16 '15 at 09:13
  • 1
    @DenisBitouzé I think the main thing filecontents does is overwrites even an existing file. egreg told me that filecontents should always come before \documentclass. Especially if you use any special characters, the contents is not written correctly otherwise. – cfr Sep 16 '15 at 10:08

1 Answers1

2

As you rightly point out your .bcf file is missing some closing XML tags and (at least some of) those tags are added via

\AfterEndDocument{%
  \blx@auxwrite\blx@bcfout{}{%
    \blx@xml@endsection\blx@nl
    \csuse{blx@xml@slistsbib}%
    \blx@xml@endfile}%
  \immediate\closeout\blx@bcfout}

So it seems that the etoolbox's \AfterEndDocument hook doesn't quite work as advertised here. (Though a few tests with \AfterEndDocument{\typeout{foo}} went rather well.)

You have to load etoolbox (which is needed by biblatex and loaded by that package) before the standalone package. A similar problem with \AfterEndDocument was discussed in Package incompatibilites: etoolbox, hyperref, and bm, standalone?

So

\listfiles
% Generates subfile.bib
\begin{filecontents}{subfile.bib}
  @book{foo,
    title                    = {Foo},
    author                   = {Bar},
    date                     = {2015-01-01}
  }
\end{filecontents}
%
% Generates subfile.tex
\begin{filecontents}{subfile}
  \documentclass{article}
  \usepackage[backend=biber]{biblatex}
  \addbibresource{subfile.bib}
  \begin{document}
  Look at \autocite{foo}.
  \printbibliography
  \end{document}
\end{filecontents}
%
% Main file `main.tex`
\documentclass{article}
\usepackage{etoolbox}
\usepackage[%
  sort
  ,group=false
]{standalone}
\usepackage[backend=biber]{biblatex}
\begin{document}
\input{subfile}
\end{document}

works as advertised.

moewe
  • 175,683
  • (+1) but it is strange, isn't it, that the \end{document} in the main file would not trigger the hook? – cfr Sep 16 '15 at 10:10
  • @cfr It is. And I have no idea why that happens, especially since my test with \AfterEndDocument{\typeout{foo}} gave the expected result... Of course I can't say for sure that the hook was not triggered, but what I'm seeing strongly suggests it. (Maybe there is a disagreement about who writes the .bcf between the \input document's document environment and the main document?) – moewe Sep 16 '15 at 10:51