微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使用乳胶读取文件的所有内容,结束某些行有“%”

如何解决如何使用乳胶读取文件的所有内容,结束某些行有“%”

我是 Latex 新手,当我使用 pdflatex 读取文件时,我发现某些行(带有“%”)无法读取,我该如何绕过? 这是我的 .tex 文件

\documentclass{article}
\begin{document}
\newread\file
\openin\file=test.txt
\newwrite\fileo
\immediate\openout\fileo=ss.txt
\loop\unless\ifeof\file
\read\file to\fileline 
\immediate\write\fileo{\fileline}   
\repeat
\cloSEOut\fileo
\closein\file
sometext(not important)
\end{document}

这是 test.txt

%abcdefg
aaa
sss

pdflatex 后的 .tex 文件,结果是

aaa
sss

我怎样才能得到第一行:"%abcdefg"

解决方法

你必须逃避角色。某些字符在 LaTeX 中具有特殊含义:

& % # _ ~ ^ \ { } {{ 1}}

要避开其中的大部分,只需添加 $,其他人有自己的命令:

\

如您所见,如果您不对 % 字符进行转义,它会注释掉源代码中的一行文本。我希望我有帮助

编辑:正如您所说,您无法更改 test.txt 文件,您可以将 % 作为特殊字符在 \documentclass{article} \begin{document} \& \% \# \_ \$ \{ \} \textasciitilde \textasciicircum \textbackslash % A comment line % In your code should be: \%abcdefg \\ aaa \\ sss \end{document} 之后添加 \catcode`\%=12

\begin{document}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。