The following code works, although I have a feeling my \settowidth method of discarding the output is not how it should be done:
\documentclass{article}
\newlength{\trashlength}
\long\def\ignoreoutput#1{%
\settowidth{\trashlength}{#1}%
}
\long\def\command#1{
This \gdef\stuff{Stored: #1} shouldn't be here.
}
%% Should not raise Missing \begin{document} error here:
%\ignoreoutput{\command}
\begin{document}
% Should produce "nothing":
no\ignoreoutput{\command{Side %\par %%%%% this breaks everything.
effect!}}thing.
% Should output the text previously stored:
\ifx\stuff\undefined No side effect.
\else \stuff \fi
\end{document}
When uncommenting the \par though, it breaks: with Paragraph ended before \@settodim was complete.
So how do I ignore commands that allow long input?
\saveboxetc... But it doesn't work before\begin{document}though (but I could defer it usingAtBeginDocument) – pascal Jan 15 '11 at 03:17\newsaveboxand just use\setbox0as in TH's answer, even without the extra group that he uses – since box registers with numbers below 10 are reserved for temporary use. – Harald Hanche-Olsen Jan 15 '11 at 10:10\long\def\ignoreoutput#1{\setbox0\vbox{\everypar{}#1}}and it works. (since I use local macros in the ignored command, I prefer manual\gdef) – pascal Jan 15 '11 at 18:03\everypar{}. – TH. Jan 15 '11 at 21:00