title: Makefile for multi-file LaTeX document
body: <p>I'm trying to simplify/improve the Makefile for compiling my thesis. The Makefile works nicely for compiling the whole thing; I've got something like this:</p>
  
  <pre><code>show: thesis.pdf
      open thesis.pdf
  
  thesis.pdf: *.tex
      pdflatex --shell-escape thesis
  </code></pre>
  
  <p>This allows me to type <code>make</code> and any changes are detected (if any) and it's recompiled before being displayed.</p>
  
  <p>Now I'd like to extend it to conditionally compile only individual chapters. For example, this allows me to write <code>make xpmt</code> to get just a single chapter in a round-about sort of way:</p>
  
  <pre><code>xpmt: ch-xpmt.pdf
      open ch-xpmt.pdf
  
  ch-xpmt.pdf: xpmt.tex
      pdflatex --shell-escape --jobname=ch-xpmt \
        "\includeonly{xpmt}\input{thesis}"
  </code></pre>
  
  <p>But I don't want to have to write this down identically for each individual chapter. How can I write the rules above in a general enough way to avoid repetition?</p>
  
  <p>(More of an exercise in learning how to write Makefiles rather than to solve any real problem; obviously in this case it would actually be trivial to copy and paste the above code enough times!)</p>