忽略命令/抑制多个空格

忽略命令/抑制多个空格

在此示例中,如何抑制多个空格:

\documentclass{article}
\begin{document}
\newcommand*{\foo}[1]{dummy foo output}
Test this \foo{3} command.
% but now I want to ignore it completely
\renewcommand*{\foo}[1]{\relax}
Test this \foo{3} command.
% ...and have no multiple spaces between "this" and "command"
\end{document}

我想完全忽略\foo(仍然将其​​保留在源代码中)。

谨致问候,伊万

答案1

LaTeX 内核有这个\@bsphack功能\@esphack

\documentclass{article}

\makeatletter
\newcommand{\kokanignore}{\@bsphack\@esphack}
\makeatother

\begin{document}

\newcommand*{\foo}[1]{dummy foo output}
Test this \foo{3} command.

\foo{3} xyz

% but now I want to ignore it completely
\renewcommand*{\foo}[1]{\kokanignore}
Test this \foo{3} command.
% ...and have no multiple spaces between "this" and "command"

\foo{3} xyz

\end{document}

在此处输入图片描述

相关内容