# use variable inside include/input

I would like to use a variable so I can define which file to include at compile-time (argument passed to LaTeX - see below).

Problem here is that I cannot insert document name with "_", without crashing everything. Is thez a simple way to perform such task?

### Command line used

 pdflatex "\def\testpath{my\_document}\input{my_tex_document}"


### Below is a minimal example of my LaTex document

 \documentclass{article}

\title{Librairie \testpath}
\author{Author}

\begin{document}

\section{Insertion of \testpath}
\include{lib_12/\testpath}

\end{document}

-
The simple way would be to not have underscores in your filenames? –  Seamus Jul 20 '11 at 15:16

I would use the following command:

pdflatex --jobname 'my_document' my_tex_document


This will produce a my_document.pdf which makes more sense to me. You can then also use \jobname to access the file name without any issues with underscores. The content of that macro is already detokenized.

 \documentclass{article}

\title{Librairie \texttt{\jobname}}
\author{Author}

\begin{document}

\section{Insertion of \texttt{\jobname}}
\input{lib_12/\jobname}

\end{document}


You should then always make sure that you don't use \input{\jobname} and compile the document without the --jobname argument. Otherwise you create an endless loop.

If you need this to only compile certain chapters of a document (which are all included using \include) use the following command instead. Here an example of compiling the introduction of a thesis only:

pdflatex --jobname introduction '\includeonly{introduction}\input{thesis}'

-

You can try

pdflatex "\edef\testpath{\detokenize{my_document}}\input{my_tex_document}"

-