TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

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

Possible Duplicates:
Conditional Compiling and \documentclass
Passing parameters to a document
Changing LaTeX headers via a makefile

I'm setting up a Rakefile for a LaTeX document and I'd like to be able to build different versions of the document with this script without changing the LaTeX source. The two different options that I'd like to change are:


which can be changed to:


by invoking a different target. Is it possible to change these on-the-fly at compile time? I'm using xelatex if that makes any difference.

share|improve this question

marked as duplicate by Martin Scharrer Jul 28 '11 at 19:23

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

up vote 3 down vote accepted

Step 1

Create a batch file as follows, name it batch.bat for instance.

rem batch.bat takes file name without extension and the mode.
rem for example you can execute as follows.
rem batch yourtexfile final
rem or
rem batch yourtexfile draft
echo off
xelatex "\def\mode{%2}\input{%1.tex}"
acrord32 %1.pdf

Step 2

Create an input file, name it yourtexfile.tex for instance.


Step 3

Execute the batch by supplying the file name and mode as follows.

enter image description here

share|improve this answer
See Conditional Compiling and \documentclass, especially about \PassOptionsToClass{..}{article}. – Martin Scharrer Jul 28 '11 at 19:45
You shouldn't attach pictures to show just text. Using the backticks, code blocks or <pre> … </pre> is a lot better. Also, who said the op uses Windows and Adobe Reader? – Andrey Vihrov Jul 28 '11 at 21:47
@Andrey: A picture is worth a thousand words‌​. I let him/her adapt my example in Windows to suit his/her need. – xport Jul 28 '11 at 22:06
@xport: Except of course when you are blind, on a slow internet connection, a small/bad screen or want to use copy&paste. Or when you don't want to be confused by underscores that shouldn't be there. – Caramdir Jul 28 '11 at 22:20
Hopefully no blind exploring tex.sx with a mac tiny nano connected to 1 bps line and attempting to copy/paste the contents. – xport Jul 28 '11 at 22:54

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