-
Notifications
You must be signed in to change notification settings - Fork 68
Latexmk re-bases all paths searched relative to its configuration file, not relative to the main document file. #1439
Description
I have a monorepo for my LaTeX documents, which looks like this:
my-latex-documents
- latexmkrc
- resources/
- common.bib
- reports/
- foo/
- foo.tex
- thesis/
- thesis.tex
- preamble/
- ...
- chapters/
- ...
My latexmkrc file defines a few variables to redirect the .aux files and all related build artifacts to a separate folder, here's the relevant parts:
# Change into the file's directory before build:
$do_cd = 1;
# All aux/bib/build files in build:
$aux_dir = './build';
$out_dir = './build';To compile my documents manually, I thus call latexmk thesis/thesis (for example) from my-latex-documents, and the command compiles my documents without any issue.
However, currently, opening up my editor (neovim) on the file thesis.tex from the my-latex-documents/thesis directory, with a near-stock Texlab configuration, fails to find any paths because the parsing of the latexmkrc file rebases all search paths from my-latex-documents and not my-latex-documents/thesis.
This can be checked by adding a few log lines (mainly in the texlab::Server::did_open() function, as well as the base_db crate) to texlab, and launching it with the -vvvv flag:
WARN - Graph::new() document="$HOME/my-latex-documents/thesis/thesis.tex"
WARN - Found project root (as parent) = { .compile=file://$HOME/my-latex-documents/thesis/, .src=file://$HOME/my-latex-documents/thesis/, .aux=file://$HOME/my-latex-documents/thesis/, .log=file://$HOME/my-latex-documents/thesis/, .pdf=file://$HOME/my-latex-documents/thesis/ }
WARN - Graph::new(): new project root: ProjectRoot { compile_dir: "file://$HOME/my-latex-documents/thesis/", src_dir: "file://$HOME/my-latex-documents/thesis/", aux_dir: "file://$HOME/my-latex-documents/thesis/", log_dir: "file://$HOME/my-latex-documents/thesis/", pdf_dir: "file://$HOME/my-latex-documents/thesis/", additional_files: [], file_name_db: "..." }
INFO - WorkspaceDidOpen -- finished opening the workspace. Updating it...
INFO - Workspace::discover(): Current checked paths: []
INFO - Workspace::discover_parents(): to check = ["$HOME/my-latex-documents", "$HOME/my-latex-documents/thesis"]
DEBUG - Loading document $HOME/my-latex-documents/latexmkrc from disk...
DEBUG - Opening document file://$HOME/my-latex-documents/latexmkrc...
DEBUG - Latexmkrc parsing result: src_dir="$HOME/my-latex-documents", output=Ok(LatexmkrcData { aux_dir: Some("build"), out_dir: Some("build"), file_name_db: FileNameDB { files: {} } })
INFO - Workspace::open(): updating graphs...
WARN - Graph::new() document="$HOME/my-latex-documents/latexmkrc"
WARN - Found project root = { .compile=file://$HOME/my-latex-documents/, .src=file://$HOME/my-latex-documents/, .aux=file://$HOME/my-latex-documents/build/, .log=file://$HOME/my-latex-documents/build/, .pdf=file://$HOME/my-latex-documents/build/ }
WARN - Graph::new(): new project root: ProjectRoot { compile_dir: "file://$HOME/my-latex-documents/", src_dir: "file://$HOME/my-latex-documents/", aux_dir: "file://$HOME/my-latex-documents/build/", log_dir: "file://$HOME/my-latex-documents/build/", pdf_dir: "file://$HOME/my-latex-documents/build/", additional_files: [], file_name_db: "..." }
WARN - Graph::new() document="$HOME/my-latex-documents/thesis/thesis.tex"
WARN - Found project root = { .compile=file://$HOME/my-latex-documents/, .src=file://$HOME/my-latex-documents/, .aux=file://$HOME/my-latex-documents/build/, .log=file://$HOME/my-latex-documents/build/, .pdf=file://$HOME/my-latex-documents/build/ }
WARN - Graph::new(): new project root: ProjectRoot { compile_dir: "file://$HOME/my-latex-documents/", src_dir: "file://$HOME/my-latex-documents/", aux_dir: "file://$HOME/my-latex-documents/build/", log_dir: "file://$HOME/my-latex-documents/build/", pdf_dir: "file://$HOME/my-latex-documents/build/", additional_files: [], file_name_db: "..." }
INFO - Adding parent file "$HOME/my-latex-documents/latexmkrc", changed workspace ? => true
INFO - Workspace::discover_children(): to check = ["$HOME/my-latex-documents/preamble/commands.tex", "$HOME/my-latex-documents/chapitres/wasserstein", "$HOME/my-latex-documents/chapitres/conclusion", "$HOME/my-latex-documents/build/thesis.aux", ...]
Look at the last line: all the paths listed are included in thesis/thesis.tex as a path relative to my-latex-documents/thesis/, but they are interpreted as being relative to my-latex-documents/.
As I can guess from a cursory look at the code base, the latexmk folder detection only ever checks the directory reports when invoked without any arguments. However, it should be run with a relative path from the RC file to the main document file. Compare the result of latexmk -dir-report-only (with an existing empty dummy.tex file in the /tmp directory):
Rc files read:
latexmkrc
Latexmk: Cwd: '/tmp'
Latexmk: Normalized aux dir, out dir, out2 dir:
'build', 'build', 'build'
Latexmk: Combining forms of aux dir, out dir, out2 dir:
'build/', 'build/', 'build/'
Latexmk: Base name of generated files:
'dummy'
and latexmk -dir-report-only thesis/thesis (with an empty thesis/thesis.tex file):
Rc files read:
latexmkrc
Latexmk: Cwd: '/tmp/thesis'
Latexmk: Normalized aux dir, out dir, out2 dir:
'build', 'build', 'build'
Latexmk: Combining forms of aux dir, out dir, out2 dir:
'build/', 'build/', 'build/'
Latexmk: Base name of generated files:
'thesis'
This is due to the fact that not only is latexmk run without any arguments after the -dir-report-only, but also because the CWD report is omitted completely, even when $do_cd is enabled:
texlab/crates/parser/src/latexmkrc.rs
Lines 124 to 131 in d80c436
| fn extract_dirs(lines: Lines) -> Option<(String, String)> { | |
| let mut it = lines | |
| .skip_while(|line| { | |
| !(line.starts_with("Latexmk: Normalized aux dir and out dirs:") | |
| || line.starts_with("Latexmk: Normalized aux dir, out dir, out2 dir:")) | |
| }) | |
| .nth(1)? | |
| .split(','); |
Ideally, the root detection algorithm would be building a dependency graph from the main document file (containing \begin{document} and \end{document}) using the build and aux directory detected using the latexmkrc configuration file. However, this faulty parsing prevents all references, citations and labels from being detected properly.
I should mention such a setup, with the same file structure, worked in texlab v4.3.2 using texlive 2024.