[texhax] passing package options on the commandline

Uwe Lück uwe.lueck at web.de
Thu Jan 3 15:07:28 CET 2013


Am Donnerstag, den 03.01.2013, 04:48 -0800 schrieb
jtzzaa11-texhax2 at yahoo.com: 
> Im using linux and wondering if it's possible 
> to pass options to packages from the commandline.
> 
> Specifically, I want to generate a document version 
> where figures are replaced by rectangles. 
> This is achieved with the "draft" option in the graphicx package.
> 
> I want to automate this with a shell script, 
> so it'll produce one document version with the figures included, 
> and one in the "draft" mode. so I need to somehow pass the "draft" 
> options to graphicx togetehr with the "latex" command.

Am Donnerstag, den 03.01.2013, 12:57 +0000 schrieb Lars Madsen: 
> this might work (untested)
> 
> pdflatex "\RequirePackage[demo]{graphicx}\input{file.tex}"

results in 

    I can't find file `RequirePackage...

Better (the shell has a different idea about the backslash 
than TeX)

    pdflatex '\RequirePackage[draft]{graphicx}\input{file}'

or

    pdflatex \\RequirePackage[draft]{graphicx}\\input{file}

Another idea that I actually use (in an analogous situation) 
is replacing 

    \RequirePackage[draft]{graphicx}

by 

    \input{settings}

and using a script with content

    echo \RequirePackage[draft]{graphicx} > settings.tex
    pdflatex file

It may not be better right here, but is more essential when 
the content of settings.tex requires that other stuff has 
been loaded first, according to what file.tex has above 
\input{settings}; e.g. to override settings from other 
packages.

Yet another idea is replacing the option by \thegraphicxoption 
and then do

    pdflatex '\def\thegraphicxoption{draft}\input{file}'  

Yet another: If you really want to enter the option OPTION 
in the command line, with an option to enter "final": 
Make runwithoption.sh containing

    pdflatex \\RequirePackage[$1]{graphicx}\\input{file}    

So anybody might test

    ./runwithoption.sh draft

and 

    ./runwithoption.sh final

And don't forget to think about the /global/ option "draft".

Good LuX,

    Uwe.




More information about the texhax mailing list