How to print out a backslash in LaTeX

Giovanni Funchal picture Giovanni Funchal · Jan 18, 2010 · Viewed 42.3k times · Source

I want to write a backslash character to a text file using LaTeX.

The first line of code below declares a variable 'file' which describes the file 'myfile.out'. The second line opens the file and the third one tries do write a backslash '\' to the file.

\documentclass{article}
\begin{document}
   \newwrite\file%
   \immediate\openout\file=myfile.out%
   \immediate\write\file{\}%
\end{document}

The third line does not work because LaTeX get confused with the backslash, anyone knows how can I make it work? I tried a lot of things including \textbackslash, $\backslash$ \char ``\` etc and nothing seems to work.

Thanks a lot

Answer

Martijn picture Martijn · Jan 18, 2010

Sound like you want a backslash in text mode; since \backslash does not work, try \textbackslash.

EDIT: \symbol{92} should also work.