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.

With the commands \openout and \write I output text into a file. I want this file to have a name of containing an underscore (eg. name_01.txt), but I'm unable to get the underscore in the filename. My attempt (with \_):

\documentclass{article}
\begin{document}
\newwrite\tempfile
\immediate\openout\tempfile="name\_01.txt"
\immediate\write\tempfile{this is interesting}
\immediate\closeout\tempfile
\end{document}
share|improve this question

2 Answers 2

up vote 8 down vote accepted
\immediate\openout\tempfile="name\string_01.txt"

share|improve this answer

well, i ve just tried the simple

\immediate\openout\tempfile="name_01.txt"

... and it works ... Sorry. :)

share|improve this answer
1  
When I opened the question I was thinking exactly the same. :) Underscores (and other special characters I won't mention) are legal without any special precautions in a file name. Beware that at least one package makes the underscore active and, in this case, Herbert's solution is the best approach. –  egreg Jun 5 '12 at 21:46
    
By the way, how can i output a "tabulation" character ? can i also use \string in some way ? –  nicolas roy Jun 6 '12 at 6:01
    
Tabs are quite strange beasts; there is something about this problem on the site. –  egreg Jun 6 '12 at 6:24

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.