1

How can I suppress multiple spaces in this example:

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

I want to completely ignore \foo (still leaving it in the source code).

Kind regards, Ivan

  • Do you want it to run sometimes or only on certain compiles? If you only want it to be active on some compiles, you can just have multiple definitions in the preamble, and outcomment all the ones you don't want ;-) – Thorbjørn E. K. Christensen Feb 19 '18 at 13:04
  • I use such command through whole book, and on certain compiles I would like compiler to completely ignore it. I thought that defining it as \relax will do, but it produces two spaces (one before + one after). – ivankokan Feb 19 '18 at 13:07
2

The LaTeX kernel has \@bsphack and \@esphack for this.

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

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.