TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

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

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 \_):

\immediate\write\tempfile{this is interesting}
share|improve this question
up vote 9 down vote accepted

share|improve this answer

well, i ve just tried the simple


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

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


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.