TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

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


 \title{Librairie \testpath}


 \section{Insertion of \testpath}

share|improve this question
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.


 \title{Librairie \texttt{\jobname}}


 \section{Insertion of \texttt{\jobname}}


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}'
share|improve this answer

You can try

pdflatex "\edef\testpath{\detokenize{my_document}}\input{my_tex_document}"
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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