TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The following code works, although I have a feeling my \settowidth method of discarding the output is not how it should be done:

 This \gdef\stuff{Stored: #1} shouldn't be here.
%% Should not raise Missing \begin{document} error here:
 % Should produce "nothing":
 no\ignoreoutput{\command{Side %\par %%%%% this breaks everything.  

 % Should output the text previously stored:
 \ifx\stuff\undefined No side effect.
 \else \stuff \fi

When uncommenting the \par though, it breaks: with Paragraph ended before \@settodim was complete.

So how do I ignore commands that allow long input?

share|improve this question
up vote 4 down vote accepted
\long\def\ignoreoutput#1{\setbox\trashbox\vbox{\everypar{}\globaldefs1 #1}}

seems to work.

(Edit: make assignments global as per TH's answer, and locally disable LaTeX's \everypar-based mechanism for complaining about a missing \begin{document}.)

share|improve this answer
Ah, very short. Must have missed it when looking up \savebox etc... But it doesn't work before \begin{document} though (but I could defer it using AtBeginDocument) – pascal Jan 15 '11 at 3:17
@pascal: That can be fixed. See my edits above. I think it would be safe to forgo the usage of \newsavebox and just use \setbox0 as 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
Perfect. I used \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
Good call on the \everypar{}. – TH. Jan 15 '11 at 21:00

I would use something similar to Harald's example (which appeared just before I posted this).



The \globaldefs1 makes assignments global.

share|improve this answer
thanks, didn't know about \globaldefs or temporary boxes. – pascal Jan 15 '11 at 18:03

Just tried this, but it seems even fishier:

% etc like above

But it can break with Dimension too large.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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