我过去常常\includeonly
为单个章节做页面布局。我做了一个很长的章节,结果发现它不适用于整个文档。经过一番搜索,我找到了原因。一个字母导致了不同页面布局的级联。当我只包含一个章节的布局时,这一章中只有一篇 Müller 于 2004 年发表的论文,结果如下:
在整本书中,我写了四篇论文,但引用的却是 Müller (2004d),而不是 Müller (2004)。这个字母导致段落多占一行,导致两行内容跳转到下一页,这毁了我目前所做的一切。
所以,问题是:我可以让 biblatex 包含它在辅助文件中找到的所有内容吗?
编辑1:
我适应了https://tex.stackexchange.com/a/418639/18561到 biblatex,但它不起作用。它只引用了一个参考文献。bibtex 开箱即用,无需任何附加机制。
\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}
编辑2:
基于上述代码的MWE:
\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}
答案1
biblatex
始终写入主.aux
文件,因此.aux
章节文件不包含足够的信息。但即使这一点已更改,问题仍然是biblatex
不仅使用文件管理其引用.aux
,还将其写入.bcf
。
biblatex
仅当引用确实由 TeX 处理时才写入.bcf
。如果引用位于当前运行中未包含的文件中,则不会处理引用。
以下是原件的副本\include
(\includeonly
见ltfiles.dtx
或者source2e
) 还秘密地\input
将章节放在一个永远不会打印的框中,以便让 LaTeX 对其进行引用处理。
\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
我现在做的是:我将包含章节的主文件复制到一个文件 (check-gt.tex),并更改加载的参考书目 (check-gt.bib)。我没有使用包含 6000 个项目的参考书目,而是使用引用书中所有项目的 bib(仅 1471 个)。我\nocite{*}
在此文件中包含一个,以便整本书 (grammatical-theory.tex) 中引用的所有项目也在不包含所有章节的文件 (check-gt.tex) 中引用。以下行生成我包含的参考列表
biber --output_format=bibtex --output_resolve grammatical-theory.bcf -O check-gt.bib
这只需做一次,我不需要编译所有未包含的文件。这本书有 800 多页,我想这个解决方案是最有效的。
答案3
\include
以下是使用我的版本和命令的方法\includeonly
:
\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}
当然,它会慢得多,因为它会读取或不读取所有包含的章节......但这个想法也可以以其他方式使用。
(我还没有充分使用或检查原始 \includeonly 命令如何工作,我也不确定不使用其他章节的方法是什么......但我想这可以根据您的需要进行修复)
编辑:所有带有注释 %ADDED FOR EASY TEST 的部分仅用于在 biblatex(biber) [变量\testonbiblatex
值 =1] 和 bibtex 之间进行测试。我所做的唯一需要的更改是删除第二条\minclude
命令之间的“%”。还更改了第二篇文章的标题,但实际上不需要工作。
输出(bibtex):
输出(biblatex):