TeX - LaTeX Asked by Ceschi on February 6, 2021
I am assembling my final dissertation from some articles I have written over the past years. I am using subfile
and a main.tex
file to collect all the preambles in one place and just plug in all the articles. Every individual article/chapter sits in its own folder with a bunch of other subfiles and images, while the massive bib
file that I use for all projects sits in the upper level folder with respect to main.tex
. A schematic folder tree can be the following:
bibliography.bib
main.tex
chap1.tex
chap2.tex
tex
I would like to be able to compile single files individually as well as the main document, with graphs, external tables, and bibliographic references (although the full list of references will be only on the compiled main document). I found ways of having the plots paths change but that breaks the references and vice versa. Is there a comprehensive, elegant solution to this?
MWE:
MAIN.tex
documentclass{report}
usepackage[backref=true,
backend=biber,
style=authoryear-comp,
url=false,
doi=false,
isbn=false,
eprint=false,
language=auto,
natbib=true
]{biblatex}
addbibresource{../bibliography.bib}
usepackage{csquotes}
usepackage{subfiles}
begin{document}
chapter{Chapter I}
%graphicspath{{./chap1/plots}{plots/}}
subfile{./chap1/chap1.tex}
chapter{Chapter II}
%graphicspath{{./chap2/plots}{plots/}}
subfile{./chap2/chap2.tex}
end{document}
Chap1.tex
documentclass[../main.tex]{subfiles}
begin{document}
Some text with a citation from the all-encompassing bib citep{item} to illustrate next table ref{tab_in_chap2} with relative path
subfile{../chap2/tables/table.tex}
and a plot too, local to this file
begin{figure}
includegraphics{./plots/a_plot.pdf}
end{figure}
Last, a piece of tex from this local folder
subfile{./chap1/tables/tab.tex}
end{document}
You can use the xr
package.
Clean solution: In the main file, include the lines
usepackage{xr}
usepackage{subfiles}
externaldocument[M-]{subfix{main}}% must appear after usepackage{subfiles}
In the subfiles, prefix all references that are supposed to show the same value as when typesetting the main document, with M-
. This means: For labeling, you write label{XXX}
, and for referencing, you write ref{M-XXX}
and pageref{M-XXX}
.
Before typesetting the subfiles, you have to typeset the main file a few times to get a stable main.aux
containing the correct references.
Dirty solution: If you want to avoid modifying all references from XXX
to M-XXX
, omit the option M-
in the externaldocument
command. The downside is that you get multiply defined label
warnings, and you should check whether your ref
/pageref
commands show the value you expect.
The background is that the labels are indeed multiply defined, once with the number/page number from the main document and once with the number from the subfile. It seems that the number from the main document trumps the one from the subfile, so you get what you want, but it may be different in a changed setting.
Answered by gernot on February 6, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP