# How to use an underscore in a filename

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}

-

\immediate\openout\tempfile="name\string_01.txt"

-

well, i ve just tried the simple

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


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

-
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