4

I currently use emacs to write and compile LaTeX files using the key combo: C-c C-f. Now this is all well and good, but now I'm working on a much bigger project that is divided into many chapters. My main file includes these chapters using \include{chp1} for example, and so I have to go back to the main file to use C-c C-f to compile everything.

So here's my question: When I am editing chp1.tex, is there any way to turn OFF the automatic recognition of LaTeX mode so that if I mistakenly hit C-c C-f, it doesn't freak out and spam me with pages and pages of LaTeX error messages? I'd like it to just tell me when I type C-c C-f in chp1.tex, "you stupid idiot, this is not the main file," rather than try to compile chp1 by itself.

  • Do you have a Makefile for your bigger project? – abo-abo Dec 31 '14 at 17:39
  • Check out the AUCTeX manual on multifile documents. I suspect if you (setq-default TeX-master nil) as it suggests, AUCTeX will ask you for your master file before compiling. – Dan Dec 31 '14 at 17:44
  • 2
    You don't have to disable LaTeX mode: see Multifile Documents. If you set TeX-master as described in the manual you should be able to compile the whole document using C-c C-f from a buffer visiting a chapter file. – Constantine Dec 31 '14 at 17:44
  • 1
    Oh, and are you sure you didn't mean C-c C-c (TeX-command-master)? The default binding for C-c C-f is TeX-font. – Dan Dec 31 '14 at 17:46
  • 1
    What am I, chopped liver? ;) @Constantine: could you convert your comment to an answer so it can be marked as answered? – Dan Dec 31 '14 at 22:00
6

If you break latex doc into several files you can still work with the whole project just fine in emacs, all you need is to set the master file in each file you include. For this put the following at the top line of each file you include:

% -*- TeX-master: "dissertation.tex" -*-

(assuming your master file is called dissertation.tex). This way you get, for example, a working table of contents with C-c = and, I think, build with C-c C-f will work too. (personally I prefer including a build.bash or build.py file in every large project, so I don't use auctex-mode's build scripts)

One more nice binding for this work flow is C-c ^ which switches you to master file buffer.

  • C-c C-f definitely works then. Another interesting binding with this workflow is C-c C-b, which will compile the current buffer only (but with the preamble from the master file, because *magic*). – T. Verron Jan 6 '15 at 16:54
  • 2
    Not really related to the question, but do you really need to include a build script in every project? Some people have spent some time developing complete such scripts, and they are distributed with texlive (if you haven't already tried them, you can look up latexmk, rubber or arara). – T. Verron Jan 6 '15 at 16:56
  • @T.Verron: well - yes. Because my build scripts do more then just latex build. For example I include svg files in latex (using Inkscape export to latex). So my build script converts, e.g., image.svg to image.pdf, if the later is outdated (script checks that). Also my build script builds everything in ./tmp dir of the project to keep master dir clean: it only contains pdf file of the build, master tex file and folders: tex, img, bib, tmp. Finally the whole procedure should be modified slightly if I use minted for source code coloring. – Adobe Jan 6 '15 at 17:25
  • 3
    I would suggest to put TeX-master as a file local variable to the end of the file, instead of the beginning. The TeX-master-file-ask function (bound to C-c _ and used in many places in AUCTeX) searches only for the former format. – giordano Jan 6 '15 at 17:39

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.