6

I would like to control class options such as draft and geometry package's showframe from a Makefile. Is there a way I can parameterise a document using LaTeX itself, or will I need to preprocess the document using sed from the Makefile?

1 Answer 1

8

This is something I use quite often.

In your document you do this:

\providecommand\classopts{}
\expandafter\documentclass\expandafter[\classopts]{article}

The \expandafter shouldn't be necessary, however, I always provide them.

The \providecommand only adds the command if it didn't already exist. So you just need to create the command beforehand and then you can switch between different schemes.

In your makefile you can then do:

draft:
    pdflatex "\def\classopts{draft}\input{document}"
pdf:
    pdflatex document

And then you have two different compilations, one with draft and the other with regular settings.

I typically use it for switching between compiling handouts and the presentation for a beamer presentation.

4
  • This works great! I've used pdflatex "\def\classopts{,draft}\input{document}" (note the leading comma) so that I can append options to a list of standard class options such as a4paper Apr 2, 2014 at 12:18
  • It works nice for me too. It has, however, a drawback: Since you call the main document with \input{document} from the command line it is not possible to input (or include) other files from there. This is a nice feature for large documents. The reason why this is not longer possible is that \input cannot be nested.
    – fborchers
    Feb 17, 2021 at 10:45
  • 1
    @fborchers you can nest as many \input as you want (basically), See here
    – nickpapior
    Feb 18, 2021 at 11:05
  • @fborchers, you might have been thinking of the \include command which cannot be nested. latex.org/forum/viewtopic.php?t=20341
    – Paul Wintz
    Jun 7, 2021 at 21:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .