TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a large document with multiple parts:




% !TEX root = main.tex
Hello World!

This way, I can compile the PDF with part1.tex open, and I can compile just one part (\includeonly{part1}).

Is there a way to compile only the current document, i.e., insert \includeonly{currently opened file} before compiling?

My first idea was to use LuaTeX to insert an includeonly depending on command line arguments (using the Lua variable arg), but then I still didn't find a way to append the command line parameter.

share|improve this question
That's not possible. How would LaTeX know which document is "currently open" in your editor? – Jubobs Mar 30 '13 at 14:55
@Jubobs LaTeX doesn't know, but TeXworks knows. – tstenner Mar 30 '13 at 14:58
@tstenner exactly so this probably needs to be an editor script rather than something (lua)tex does. I don't know texworks but certainly an editor such as emacs can easily edit the master file to add the name of the current buffer. – David Carlisle Mar 30 '13 at 18:06
@tstenner Assuming countable part1.tex-part10.tex. you can add \includeonly{currentpart} manually to main.tex with main.tex and currentpart.tex windows open simultaneously in TeXworks. Post a TeXworks feature request. – texenthusiast Mar 30 '13 at 21:50

It isn't exactly what I was asking for, but I does the job quite well for me. It uses Lua to determine the file that was changed last (so usually the file I am currently editing) and writes \includeonly{file} to the preamble.


require "lfs"

function mtimesort(a,b)
   return lfs.attributes(a..'.tex',"modification") 



   files = {'part1','part2'}

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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