5

I use \includeonly to do the page layout for single chapters. I worked an our one a lengthy chapter only to find out that it does not work with the whole document. After some search I found the reason. A single letter caused a cascade of different page layouts. When I did the layout with only one chapter included there was just one paper by Müller from 2004 in this chapter and the following was the result:

enter image description here

In the full book, I had four papers and I got a reference to Müller (2004d) instead of Müller (2004). This single letter caused the paragraph to take an extra line, which caused two lines floating to the next page, which ruined everything I did so far.

enter image description here

So, question: Can I make biblatex to include everthing it finds cited in aux files?

Edit 1:

I adapted https://tex.stackexchange.com/a/418639/18561 to biblatex, but it does not work. It only cites one reference. bibtex works out of the box without any additional mechanisms.

\documentclass{report}
\usepackage{filecontents}
\usepackage{pgffor}
\usepackage{lipsum}

\usepackage[backend=biber]{biblatex}

%\bibliographystyle{apalike}
\bibliography{bibliography}

\def\mincludeonly#1{\foreach \file in {#1} {\xdef\temp{#1}\global\expandafter\let\csname fileincluded\file\endcsname\temp}}
\newsavebox{\mybox}
\def\savecitations#1{\savebox\mybox{\vbox{\noindent\begin{minipage}[inner sep=0]{\textwidth}\include{#1}\end{minipage}}}}
\def\minclude#1{\ifcsname fileincluded#1\endcsname\include{#1}\else\savecitations{#1}%More needed commands
\addtocounter{chapter}{-1}%
\fi}

\mincludeonly{chap1}

\begin{filecontents}{bibliography.bib}
@article{item1,
  title = {Title Item 1},
  year  = {1998},
  author = {Author},
}
@article{item2,
  title = {Title Item 1},
  year  = {1998},
  author = {Author},
}
\end{filecontents}

\begin{filecontents}{chap1.tex}
  \chapter{test 1}
  This is a citation:\cite{item1}
\end{filecontents}
\begin{filecontents}{chap2.tex}
  \chapter{test 2}
  This is a citation:\cite{item2}

  \lipsum[1-20]
\end{filecontents}


\begin{document}
\tableofcontents

\minclude{chap1}
%\minclude{chap2}

\printbibliography 
\end{document}

Edit 2:

MWE based on the code above:

\documentclass{report}
\usepackage{filecontents}
\usepackage{lipsum}

\usepackage[backend=biber]{biblatex}

\bibliography{bibliography}

\includeonly{chap1}

\begin{filecontents}{bibliography.bib}
@article{item1,
  title = {Title Item 1},
  year  = {1998},
  author = {Author},
}
@article{item2,
  title = {Title Item 1},
  year  = {1998},
  author = {Author},
}
\end{filecontents}

\begin{filecontents}{chap1.tex}
  \chapter{test 1}
  This is a citation:\cite{item1}
\end{filecontents}
\begin{filecontents}{chap2.tex}
  \chapter{test 2}
  This is a citation:\cite{item2}

  \lipsum[1-20]
\end{filecontents}


\begin{document}
\tableofcontents

\include{chap1}
%\include{chap2}

\printbibliography 
\end{document}
4
  • What about adding a \nocite{*} somewhere on the code? Seems simple solution too me (It could be included in the \includeonly command if you want)
    – koleygr
    Mar 5, 2018 at 20:56
  • I have almost 6000 items in the bibliography. I would not want to have all in there. But in principle this workaround could be made to work. I have scripts that bild me a subbibliography with all I cite. I could use this bibliography and then do \nocite{*}. However, this would involve some extra runs through the whole document and given how powerful biblatex is there is probably a better way. Mar 5, 2018 at 21:11
  • 1
    I know this is a general question and it does not need an MWE to be understood. But you would certainly make my life easier if you could provide a short, self-contained example (using filecontents for the \included chapters) that shows the behaviour. I wanted to look at this just now, but the fact that I have to set up all this stuff means I'll probably wait until tomorrow.
    – moewe
    Mar 5, 2018 at 21:45
  • @StefanMüller, the problem was that second \minclude was commented out. Fixed that and mede the code easy to test usibg a variable \testonbiblatex (1 for biblatex other integer for bibtex)
    – koleygr
    Mar 6, 2018 at 13:05

3 Answers 3

1

biblatex always writes to the main .aux file, so the .aux files for the chapters do not contain enough information. But even if that were changed, the issue is still biblatex does not only manage its citations with the .aux file, it also writes them to the .bcf.

biblatex only writes to the .bcf if the citation is actually processed by TeX. If the citation lives in a file not included in the current run, the citations are not processed.

The following is a copy of the original \include and \includeonly (see ltfiles.dtx or source2e) that also secretly \inputs the chapter in a box that is never printed to let LaTeX process it for citations.

\documentclass{report}
\usepackage{filecontents}
\usepackage{lipsum}
\usepackage[backend=biber, style=authoryear]{biblatex}
\addbibresource{biblatex-examples.bib}

\begin{filecontents}{chap1.tex}
  \chapter{Chapter One}
  \cite{sigfridsson,knuth:ct:a,knuth:ct:b}
  \lipsum[1-5]
\end{filecontents}
\begin{filecontents}{chap2.tex}
  \chapter{Chapter Two}
  \cite{worman,knuth:ct:a,knuth:ct:c}
  \lipsum[1-5]
\end{filecontents}

\makeatletter
\newif\if@blx@partsw \@blx@partswfalse

\def\blxincludeonly#1{%
  \@blx@partswtrue
  \edef\@blx@partlist{\zap@space#1 \@empty}}
\@onlypreamble\blxincludeonly

\def\blxinclude#1{\relax
  \ifnum\@auxout=\@partaux
    \@latex@error{\string\include\space cannot be nested}\@eha
  \else \@blx@include#1 \fi}

\def\@blx@include#1 {%
  \clearpage
  \if@filesw
    \immediate\write\@mainaux{\string\@input{#1.aux}}%
  \fi
  \@tempswatrue
  \if@blx@partsw
    \@tempswafalse
    \edef\reserved@b{#1}%
    \@for\reserved@a:=\@blx@partlist\do
      {\ifx\reserved@a\reserved@b\@tempswatrue\fi}%
  \fi
  \if@tempswa
    \let\@auxout\@partaux
    \if@filesw
      \immediate\openout\@partaux #1.aux
      \immediate\write\@partaux{\relax}%
    \fi
    \@input@{#1.tex}%
    \clearpage
    \@writeckpt{#1}%
    \if@filesw
      \immediate\closeout\@partaux
    \fi
  \else
    \setbox0=\vbox{\begingroup\@input@{#1.tex}\endgroup}%
    \deadcycles\z@
    \@nameuse{cp@#1}%
  \fi
  \let\@auxout\@mainaux}
\makeatletter

\blxincludeonly{chap2}

\begin{document}
\tableofcontents

\blxinclude{chap1}
\blxinclude{chap2}

\printbibliography 
\end{document}
2
  • That does not seem to work for my wild code.! LaTeX Error: Not in outer par mode. See the LaTeX manual or LaTeX Companion for explanation. Type H <return> for immediate help. ... l.230 \centering ? Mar 9, 2018 at 16:14
  • @StefanMüller Yes, since we have to process the files that were not \includeonly'd we need to hide the output. We do that in a \vbox. While that works well for simple text, it can go wrong with floats and other things. ... Not sure if there is a good way. I only found tex.stackexchange.com/q/97347/35864 and that leaves an unwanted empty page ...
    – moewe
    Mar 9, 2018 at 16:31
1

This is what I do now: I copy my main file that includes the chapters to a file (check-gt.tex) and change the bibliography that is loaded (check-gt.bib). Instead of using my bibliography that contains 6000 items I use the bib that cites all items in the book (just 1471). I include a \nocite{*} in this file so that all items that are cited in the full book (grammatical-theory.tex) are also cited in the file that does not include all chapters (check-gt.tex). The following line produces the list of references that I include

 biber --output_format=bibtex --output_resolve grammatical-theory.bcf -O check-gt.bib

This has to be done once and I do not have to compile all the files that are not included. The book is over 800 pages long and I guess this solution is the most efficient one.

0

Here is a way with my versions of\include and \includeonly commands:

\documentclass{report}
\usepackage{filecontents}
\usepackage{pgffor}
\usepackage{lipsum}

%CHANGE TO 1 FOR BIBLATEX(BIBER)
\xdef\testonbiblatex{0}

%THE PART OF CODE NEEDED
\xdef\inclonl{0}
\def\mincludeonly#1{\xdef\inclonl{1}\foreach \file in {#1} {\xdef\temp{#1}\global\expandafter\let\csname fileincluded\file\endcsname\temp}}
\newsavebox{\mybox}
\def\savecitations#1{\savebox\mybox{\vbox{\noindent\begin{minipage}[inner sep=0]{\textwidth}\include{#1}\end{minipage}}}}
\def\minclude#1{\ifnum\inclonl=1\ifcsname fileincluded#1\endcsname\include{#1}\else\savecitations{#1}%More needed commands
  %This indented part fix the isue of @moewe's commant about pages numbers  
  \pgfmathsetmacro\pagestobeadded{int(round((\ht\mybox+\dp\mybox)/\textheight))}%
  \pgfmathsetmacro\morepagestobeadded{round((\ht\mybox+\dp\mybox)/\textheight)-(\ht\mybox+\dp\mybox)/\textheight))}%
  \ifdim\morepagestobeadded pt>0pt %
  \pgfmathsetmacro\finalpagestobeadded{int(\pagestobeadded)}%
  \else%
  \pgfmathsetmacro\finalpagestobeadded{int(\pagestobeadded+1)}%
  \fi%
  \addtocounter{page}{\finalpagestobeadded}%
\addtocounter{chapter}{-1}%
\fi\else\include{#1}\fi}

%ADDED FOR EASY TEST
\ifnum\testonbiblatex=1
\usepackage[style=authoryear,backend=biber]{biblatex}
\addbibresource{bibliography.bib}
\fi

\mincludeonly{chap1}

\begin{filecontents}{bibliography.bib}
  \@article{item1,
    title = {Title Item 1},
    year  = {1998},
    author = {Author}}
    \@article{item2,
    title = {Title Item 2},
    year  = {1998},
    author = {Author}}
\end{filecontents}

\begin{filecontents}{chap1.tex}
  \chapter{test 1}
  This is a citation:\cite{item1}
\end{filecontents}
\begin{filecontents}{chap2.tex}
  \chapter{test 2}
  This is a citation:\cite{item2}

  \lipsum[1-20]
\end{filecontents}


\begin{document}

\tableofcontents


\minclude{chap1}
\minclude{chap2}%My problem on your question Edit 1 was a % here

%ADDED just to make easy check of chapter numbers and possible side effects
\chapter{test}
\lipsum[1-2]

%ADDED FOR EASY TEST
\ifnum\testonbiblatex=1
\printbibliography
\else
\bibliographystyle{apalike}
\bibliography{bibliography}
\fi


\end{document}

Of course it will be much slower because it will read all the chapters included or not... But the idea can be used in other ways too.

(I haven't use or check enough how the original \includeonly command is supposed to work and I am not sure what would be the way to not use the other chapters... but this can be fixed in your needs I suppose)

Edit: all the parts with comment %ADDED FOR EASY TEST , are needed only to test between biblatex(biber) [variable \testonbiblatex value =1] and bibtex. The only needed change I made was to remove the "%" between second \minclude command. Also changed second article title but not really needed to work.

Output (bibtex):

enter image description here

Output (biblatex):

enter image description here

11
  • Please l;et me know the changes that you would like to have (like reducing the chapter by one for nun included or similar -this added- )
    – koleygr
    Mar 5, 2018 at 22:34
  • I suppose my answer works both on bibtex and biblatex
    – koleygr
    Mar 5, 2018 at 22:37
  • First photo added before change "Title item 1" to "Title item 2"...
    – koleygr
    Mar 6, 2018 at 13:06
  • Mhhh it may just be me, but the logic for \mincludeonly doesn't quite seem to do what I expect. If there is no \mincludeonly I only get chapter1. And if I have \mincludeonly{chap1} I get to see both chapters ...
    – moewe
    Mar 6, 2018 at 14:51
  • 1
    Good! That works now. But as far as I can see your solution does not preserve page numbers. If all chapters are printed the bibliography is on page 9, but if we do \mincludeonly the bibliography goes to page 4. With standard \include/\includeonly the bibliography would stay on page 9.
    – moewe
    Mar 6, 2018 at 15:39

You must log in to answer this question.

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