7

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

\disableAllButCounters
\manyCommands
\enableAll

and

%\disableAllButCounters
\manyCommands
%\enableAll

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!!

Colas
  • 6,772
  • 4
  • 46
  • 96
  • 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

2 Answers2

9

You could try with

\newcommand{\disableAllButCounters}{\setbox0=\vbox\bgroup}
\newcommand{\enableAllButCounters}{\egroup}

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.

\documentclass{article}

\newcommand{\disableAllButCounters}{\setbox0=\vbox\bgroup}
\newcommand{\enableAllButCounters}{\egroup}

\begin{document}

\section{A}

Text

\disableAllButCounters

\section{B}

Text

\enableAllButCounters

\section{C}

Text

\end{document}

enter image description here

This is the .aux file:

\relax 
\@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.

egreg
  • 1,121,712
  • 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
  • see edit on why I'm looking for such commands. – Colas Mar 19 '14 at 17:54
  • @DavidCarlisle and @egreg I have found a solution for the figure environment. Shall I post it or shall I propose an edit of @egreg's answer? Actually, I see my answer more as a proposal to you than a definitive answer. – Colas Mar 20 '14 at 19:19
0

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

\usepackage{letltxmacro}

\newcommand{\disableAllButCounters}{%
% Dealing with the figure environment
\LetLtxMacro{\savedfigure}{\figure}
\renewcommand{\figure}{}
\LetLtxMacro{\savedendfigure}{\endfigure}
\renewcommand{\endfigure}{}
% Disabling everything but counter
\setbox0=\vbox\bgroup
}

\newcommand{\enableAllButCounters}{%
% Reenabling everything but counter
\egroup
% Dealing with the figure environment
\renewenvironment{figure}{\savedfigure}{\savedendfigure}
}
Colas
  • 6,772
  • 4
  • 46
  • 96
  • 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