I have the following file structure for my document:

├── acronym.tex
├── bibliography.bib
├── chapters
│   ├── some-chapter.tex
│   └── another-chapter.tex
├── figures
│   ├── some-figure.pdf
│   └── another-figure.pdf
└── main.tex

Now I want to open a file in the chapters folder and (inside the text editor) run a command to compile the whole document.

If I try to run latexmk -pdf or latexmk -pdf some-chapter inside the chapters folder I get a ton of error messages because latexmk doesn't know about the main.tex.

Is there a way to tell latexmk that it should also look in the parent folder? Or somehow declare the main.tex as main file?

I tried latexmk -pdf ../main (which anyways would not be satifying) but then I get ! LaTeX Error: Fileacronym.tex' not found.`

So far I had a main.tex.latexmain file in the document folder and vim-latex was able to find the main in the parent folder (see the vim-latex documentation). A similar solution with latexmk would be perfect.

  • 2
    Have you tried to put % !TeX root = main.tex as the first line of your main.tex ? – Jérôme Dequeker Dec 10 '15 at 14:22
  • 1
    Does adding a -cd option help? I.e., try using the command line latexmk -cd -pdf ../main – John Collins Dec 10 '15 at 18:29
  • Thank you for your comments @JohnCollins and Jérôme! I've tried the !Tex one before and it didn't seem to have any effect. The -cd option indeed works! I'll now somehow have to figure out how to set the file path because I want to write a shortcut for the compiling and of course it won't always be "../main". Anyways, thank you a lot! – mkrnr Dec 10 '15 at 18:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.