Take the 2-minute tour ×
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.

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}
share|improve this question
5  
The simple way would be to not have underscores in your filenames? –  Seamus Jul 20 '11 at 15:16
add comment

2 Answers

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

You can try

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

Your Answer

 
discard

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.