我按照建议做了这里(为了实验,我只是想使用$...$
而不是):\texttt{...}
\documentclass{article}
\catcode`\$=\active
\gdef$#1${\texttt{#1}}
\begin{document}
Hello, $world$!
\immediate\write18{echo $HOME}
\end{document}
这条Hello, $world$
线路运行正常。但是,\write18
失败了:
! Argument of $ has an extra }.
<inserted text>
\par
l.6 \immediate\write18{echo $HOME}
在这种情况下,使用$
inside 的正确方法是什么\write18
?我试过了\$
,没有成功。
答案1
echo \string$HOME
或者在本地重置 catcode
其他一些可能性
1 xyz, /home/davidc
2 abc , string /home/davidc
3 abc , string /home/davidc
4 xyz, /home/davidc
5 xyz, /home/davidc
从
\documentclass{article}
\catcode`\$=\active
\gdef$#1${\texttt{#1}}
\def\abc{xyz}
\begin{document}
Hello, $world$!
\immediate\write18{echo 1 \abc, \string$HOME}
\immediate\write18{\detokenize{echo 2 \abc, $HOME}}
\immediate\write18{\unexpanded{echo 3 \abc, $HOME}}
{\catcode`\$=12
\immediate\write18{echo 4 \abc, $HOME}}
{\edef${\string$}
\immediate\write18{echo 5 \abc, $HOME}}
Hello, $world$!
\end{document}