Befehl ignorieren / Mehrere Leerzeichen unterdrücken

Befehl ignorieren / Mehrere Leerzeichen unterdrücken

Wie kann ich in diesem Beispiel mehrere Leerzeichen unterdrücken:

\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}

Ich möchte es vollständig ignorieren \foo(es dennoch im Quellcode belassen).

Mit freundlichen Grüßen, Ivan

Antwort1

Der LaTeX-Kernel verfügt hierfür über \@bsphackund .\@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}

Bildbeschreibung hier eingeben

verwandte Informationen