# Goto or jump command in LaTeX?

The answer to this is probably "no", but I just wanted to make sure... (also, I'm not trying to get into the whole "gotos are evil" debate :)).

Basically, one of the things that irritates me in my current workflow, is that eventually I get to a point where I'm on page 34, and there are a ton of images in the previous 33 pages; so if I get stuck with something on page 34, requiring multiple texing, I have to wait for all of the 33 pages to get done texing first (and this can take a while), before I can see the results of interest.

So I thought, it would have been awesome, if LaTeX (rather, for me currently, pdflatex) supported a sort of a "jump" or "goto" command, which I could use like this:

\documentclass{article}

\usepackage{tikz}

% ...

% probably something like this would be needed - pseudo:
\declareGotoMarker{\myjumplabelA}

\begin{document}

% at this point, I'm not interested in the content from
% start to page 33 - so I'm issuing a jump command
% right at the document start:

\JumpGoto{\myjumplabelA}

% here content of skipped pages

% ...

% here is the label, the tex processor

\myjumplabelA

\section{My page 34 section}

Here there is some content that I'm texing:

A test: \problemcommand

...

% here is end of the snippet that I care about texing at the moment;
% don't need a jump here - can just use \stop etc to exit prematurely:

\stop

% here content continues, to end of doc;
% but I won't be seeing it in PDF, as I issued
% \stop just previously:

\section{My page 45 section}

Here some more content, which I'll eventually tex - but not now...

...

\end{document}


Well, I guess the code speaks for itself - the desired output would be a PDF with the content, corresponding to pg 34-44 of the original document. Obviously page numbers, and page and some of the other (section, equation, etc.) references will not be available/working when doing this kind of "jump"-shortened run, but that is understood without saying; the goal of this is more-less to assist with troublesome snippets in large documents, without the need (or despite it) to separate content in section files, and then commenting the \input lines selectively.

Anything like that within the pdflatex world?

• Well, it is not precisely what you want to achieve, but what about the \includeonly command? – Christian Hupfer Feb 20 '14 at 6:43
• I am also no enlighted by splitting into files, otherwise, I have no other idea about goto commands within LaTeX in order to 'omit' some text not relevant for current editing – Christian Hupfer Feb 20 '14 at 7:56
• Use the comment package. – Ulrike Fischer Feb 20 '14 at 7:59
• @Christian the other problem with \includeonly is that it works on \include, and therefore the file to be \included is surrounded by page breaks, meaning that you would need to comment out a document part (chapter probably) that aligns with the document structure when this is rarely what's needed. I'm sure you know this, but wanted to present the flip side to your useful suggestion. – Chris H Feb 20 '14 at 10:12
• @ChrisH: Yes, I know, there is a pagebreak, but I recently learned from another user that there is package newclude preventing the newpage. See one of my recent answers, I can't link it at the moment, it is something called 'dividing into files' – Christian Hupfer Feb 20 '14 at 10:15

I would load the comment package and use its comment environment.

Place all the code you want to exclude inside the comment environment, that is replace \JumpGoto{\myjumplabelA} with \begin{comment} and \myjumplabelA with \end{comment}.

MWE

\documentclass{article}

\usepackage{comment}

\usepackage{lipsum} % only for the example

\begin{document}

This is printed.

\begin{comment}
This is not printed

\lipsum[1-15]
\end{comment}

\section{My page 34 section}

Here there is some content that I'm texing:

\end{document}


Output

If you then want to print what is inside the comment environment you just have to add the line

\includecomment{comment}

• Many thanks for the answer @karlkoeller - I was a bit afraid of comment because of the effect of opening and closing environments, but I just tried it, it works. Two things: don't break environments' nesting (e.g. \begin{itemize} \item{x} \begin{comment} ... \end{itemize} ... \begin{itemize} \item{y} \end{comment} \item{z} \end{itemize} will fail); don't change \begin{ to \includecomment{ (fails) - as post says, add \includecomment{ before \begin{comment}. Thanks again - cheers! – sdaau Feb 20 '14 at 12:32
• @sdaau: is that fantasy nesting of environments going to work anywhere? -- it's surely not a special constraint of comment.sty – wasteofspace Feb 20 '14 at 13:08

You can use a verbbox to stuff unwanted content into a verbatim box (that is not typeset). To undo it, comment out the \begine{verbbox} and \end{verbbox} commands. Note from the output, though, that the commented comment is as if it never existed, including section divisions, etc.

\documentclass{article}
\usepackage{verbatimbox}
\usepackage{lipsum}
\begin{document}
\section{First}
\begin{verbbox}
\lipsum[1-12]
\section{Second}
\lipsum[1-5]
\end{verbbox}
\section{Third}
\lipsum[1]
\end{document}


• Many thanks for the answer, @StevenBSegletes - never heard of verbbox before, good to know about it. Cheers! – sdaau Feb 20 '14 at 12:33

Nobody seems to know the package ifthen! Example:

\documentclass{article}
\usepackage{ifthen}
\begin{document}
\newcommand{\optionaltext}{1}%
%or: \newcommand{\optionaltext}{0}%
My mandatory text.
\ifthenelse{\equal{\optionaltext}{1}}{%
Optional line 1.
Optional line 2.
etc.
}{}%
Further mandatory text.
\end{document}

• That's because the package has been deprecated (if memory serves) :) – Sean Allred Apr 20 '15 at 12:37
• Why not use the standard TeX \if\else\fi commands in this instance, though? Ends up being much clearer IMO. – Sean Allred Apr 20 '15 at 12:39
• Oh!! And welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. :) – Sean Allred Apr 20 '15 at 12:40
• @SeanAllred Not deprecated, just that many people prefer to use the expandable logic in etoolbox. – Joseph Wright Apr 20 '15 at 12:42
• @JosephWright I suppose memory does not serve me today :) – Sean Allred Apr 20 '15 at 12:43