How to print out a backslash in LaTeX

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

1

3 Answers

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

EDIT: \symbol{92} should also work.

6

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} 
2

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

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like