Question

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

Was it helpful?

Solution

You can use \@backslashchar. The following works for me:

\documentclass{article}
\begin{document}
\newwrite\file
\immediate\openout\file=myfile.out
\makeatletter
\immediate\write\file{\@backslashchar}
\makeatother
\closeout\file
\end{document}

OTHER TIPS

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

EDIT: \symbol{92} should also work.

"AB/FQS/ET004/2014" write it in latex with space as "AB/ FQS/ ET004/ 2014"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top