what I'm looking for...

I'm looking for a couple a commands, \disableAllButCounters and \enableAll that would do the following:

Everything between \disableAllButCounters and \enableAll would be ignored excepted commands such that \setcounter{counterA}{k}, so that the only common thing between




would be that after both, the values of the counters is the same. In particular, anything between these commands will not produce any output (nor aux).

I'm looking for a solution for latex and for a solution for luatex.

If it exists, these commands could provide a solution to this question.

but why!?

Basically, I would like to produce several outputs from a single latex file: one output for the content from A to B, one output for the content from B to C, etc. I plan to do it by cutting the file into multiple files. My question raises the problem of dealing with the references.

If by any chance, you think of a better solution, don't hesitate!!

  • 1
    Sounds like it might be a job for \include, unless you object to its always starting a new page. – Dan Mar 20 '14 at 22:05

You could try with


Since \setcounter and similar commands act globally, this should do; \write commands are executed only when the box eventually finds its way in the main vertical list, which the constructed box won't.













enter image description here

This is the .aux file:

\@writefile{toc}{\contentsline {section}{\numberline {1}A}{1}}
\@writefile{toc}{\contentsline {section}{\numberline {3}C}{1}}

which shows no entry related to section 2.

Beware that floats could ruin the thing; if you need them, some countermeasures should be taken.

  • Very, very sweet answer! – Steven B. Segletes Mar 19 '14 at 17:27
  • \begin{figure}... – David Carlisle Mar 19 '14 at 17:33
  • 1
    @DavidCarlisle There are other things that could go wrong. But without information about what the OP is expecting there, it would be a waste of time trying to catch all exceptions. – egreg Mar 19 '14 at 17:37
  • @egreg yes I'm just miffed that I decided not to post that as I didn't know if it was worth disabling floats, and then you posted it anyway and will no doubt get the 15pts:-) – David Carlisle Mar 19 '14 at 17:38
  • Hi @egreg and @DavidCarlisle. I am far too ignorant to understand your answer (@egreg) and why floats could create problems. But I think I might use floats: I'm not using figure but using mdframed environments. If one of you could elaborate on these floats, it could be useful. Thanks! ... and I might use also figure! – Colas Mar 19 '14 at 17:47

The following solution takes care of the problem caused by figure.


% Dealing with the figure environment
% Disabling everything but counter

% Reenabling everything but counter
% Dealing with the figure environment
  • I don't think this solves the problem; however, you should put the redefinitions after \bgroup so that you don't need to restore anything after \endgroup – egreg Mar 20 '14 at 20:45
  • @egreg on m'y MWE, it's working. Shall I put \bgroup before or after \egroup? – Colas Mar 20 '14 at 21:50
  • With \caption? Really? – egreg Mar 20 '14 at 21:58
  • @egreg by the way, why do you think it does not solve the problem? – Colas Mar 20 '14 at 22:02
  • Haven't tried \caption, but I can add a similar patch for caption. The drawback of this solution is that it is really an ad-hoc solution. – Colas Mar 20 '14 at 22:06

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.