I want to write a backslash character to a text file using LaTeX.
The firs开发者_如何转开发t 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
Sound like you want a backslash in text mode; since \backslash
does not work, try \textbackslash
.
EDIT: \symbol{92}
should also work.
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}
"AB/FQS/ET004/2014" write it in latex with space as "AB/ FQS/ ET004/ 2014"
精彩评论