LaTeXTools
LaTeXTools copied to clipboard
Bibliography autocompletion in subfiles: "No bib files found!" error, but builds fine
I am using the subfiles package to split my thesis into chapters. Bibliography autocompletion works in the main file, but not in the subfiles, where I get "No bib files found!". There are no problems when building files including citations, whether main file or subfiles.
I have a complete minimal example in this repo. Here are the most relevant parts:
The preamble (settings.tex):
\usepackage[%
backend=biber,
[...]
uniquename=init]{biblatex}
\usepackage{subfiles}
\bibliography{bibliography}
\newcommand{\onlyinsubfile}[1]{#1}
I am using the onlyinsubfile
command from here to only print the bibliography in a subfile when it is built standalone.
The main file:
\documentclass{scrbook}
\input{settings}
\begin{document}
\renewcommand{\onlyinsubfile}[1]{}
Main % citing here autocompletes and builds.
\subfile{chapter}
\printbibliography{}
\end{document}
The subfile:
\documentclass[main.tex]{subfiles}
\begin{document}
\chapter{Chapter}
Citation example\cite{latex} % builds fine, but doesn't auto-complete.
\onlyinsubfile{
\printbibliography{}
}
\end{document}
Clearing the cache doesn't help and other solutions from other issues don't seem applicable. Is there a way to enable autocompletion in subfiles? Am I using bibliographies wrong?
Do you use pre releases? https://github.com/SublimeText/LaTeXTools/blob/master/README.markdown#prereleases
Subfiles should be supported there.
I upgraded to the prerelease (v4.0.0-alpha.5), restarted Sublime and cleared the cache again, but no change.
I think we still haven't solved the problem of referencing the master file from the subfile but not compiling it. Usually one would add the magic comment %! TEX root = main.tex
on the top of the file to let LaTeXTools know about the root file, but then it would compile the root file instead of the subfile.
AFAIK we can currently not separate between "The root file we should use as base for our analysis" (extract completions, bibliography, ...) and "The root file we should compile". This is a subfiles specific difference we just currently don't support. (one may use a different build system for it)
As a workaround you could use the comment package and include the bibliography inside a comment environment.
Thanks! The comment package worked for me.
Is there a similar workaround for references to other subfiles? I tried to use the xr package, but the 'There were undefined references' LaTeX warning persists.
The message your seeing is caused by LaTeX itself not being able to find the references. You might have better luck asking on tex.stackexchange.com...
I seem to be following the exact same workflow as @nnmm for my thesis. I tried the comment suggestion, but still getting the no bib files found error message. This is what I tried in the top of the subfile, is it what you meant @r-stein?
\documentclass[thesis.tex]{subfiles}
\begin{comment}
\addbibresource{bibliography.bib}
\end{comment}
\begin{document}
\chapter{Chap}
no bibs found here
\end{document}
citation autocomplete works fine if I put
%!TEX root=thesis.tex
at the very top of the file, but then of course Cmd-B compiles the base file, not the subfile.
@r-stein could you provide an example of using the comment environment as a workaround? Wherever I put the comment, either in bibtex or biblatex form, I still see the 'No bib files found.' message. thanks.
The example above looks correct, but you may need to clear your cache (C-l, C-c or C-l, C-backspace) because we cache some information about the document structure.
thanks for that, I used the shortcuts above and all the cache clear commands in the C-shift-P palette, but it still doesn't find the bib file. I'll switch back to compiling all through the %!TEX root command for now.
Just ran into this issue---building a subfile is fine except the references are all out of whack (works fine when building the complete tex doc).
+1 on this issue persisting and being a pain in the ass, if devs point me to the place where .bib files are detected i could attempt a PR
edit: had to turn cite autocomplete off to prevent the popup from happening every time i used cite, if it's useful for future ppl
I think i've figured this out, you just have to use subfix
from the subfiles
package:
In main .tex file:
\documentclass{article}
\usepackage[
backend=biber,
style=alphabetic,
citestyle=authoryear
]{biblatex}
\usepackage{subfiles}
% --------------------------------------------------------
% Bibliography
\addbibresource{\subfix{../prelims_lit.bib}}
\begin{document}
...
\end{document}
I've been having issues with this as well. Including subfix doesn't work and I still get the prompt. Using Basic builder makes the subfile compile without an issue but the auto-completion doesn't work? @r-stein ? Any ideas?
Edit2: I've also noticed in the System Check that my TEX root is set to the subfile path despite being explicitly set to my parent thesis file using absolute path sitting in a directory a level above the subfile. I wonder if that's causing an issue..?