使用“重新定义”命令进行 Latex 编译

使用“重新定义”命令进行 Latex 编译

有没有办法传递这些字符串:

\let\includegraphicsbak\includegraphics
\renewcommand*{\includegraphics}[2][]{\fbox{\includegraphicsbak[#1]{#2}}}

通过命令行?

我试过:

 latex "\let\includegraphicsbak\includegraphics \renewcommand*{\includegraphics}[2][]{\fbox{\includegraphicsbak[#1]{#2}}} \input{myfile.tex}"

但显然,它不起作用,因为编译器抱怨“\includegraphics未定义”(此时)。有什么办法可以解决这个问题吗?

答案1

您可以使用以下方法来延迟重新定义\AtBeginDocument{....}

 latex "\AtBeginDocument{\let\includegraphicsbak\includegraphics \renewcommand*{\includegraphics}[2][]{\fbox{\includegraphicsbak[#1]{#2}}}} \input{myfile.tex}"

相关内容