Take the 2-minute tour ×
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.

I am using the verbatim environment with

\begin{verbatim}
XXXX
\end{verbatim}

I would like the option of redefining the verbatim environment so that nothing between \begin{verbatim} and \end{verbatim} is printed. So I can print a long version of the paper with the verbatim information, and a short version with verbatim information omitted. I would be grateful if someone could tell me how to do this.

share|improve this question
1  
Related: Commenting out large sections –  Werner Apr 2 '13 at 6:12
    
Thanks @Werner! –  David Kohler May 15 '13 at 17:19
add comment

4 Answers

up vote 7 down vote accepted

The comment package allows you to (re)define comment environments. So, include the following in your document preamble:

\usepackage{comment}% http://ctan.org/pkg/comment
\excludecomment{verbatim}

which should exclude verbatim environment content from your document. If you want to include all the verbatim content again (for the longer version of your article, comment out the \excludecomment{verbatim} line.

For a more piece-meal approach to removing verbatim content, the following is possible:

enter image description here

\documentclass{article}
\usepackage{comment}% http://ctan.org/pkg/comment
\begin{document}

\begingroup
\excludecomment{verbatim}
A
\begin{verbatim}
&^_%\{}
\end{verbatim}
B
\endgroup

A
\begin{verbatim}
&^_%\{}
\end{verbatim}
B

\end{document}

Another mild alternative to comment would be to gobble the environment contents using environ. The following is not heavily tested, but works:

enter image description here

\documentclass{article}
\usepackage{environ}% http://ctan.org/pkg/environ
\makeatletter
\newcommand{\voidenvironment}[1]{%
  \expandafter\providecommand\csname env@#1@save@env\endcsname{}%
  \expandafter\providecommand\csname env@#1@process\endcsname{}%
  \@ifundefined{#1}{}{\RenewEnviron{#1}{}}%
}
\makeatother
\begin{document}

\begingroup
\voidenvironment{verbatim}%
A
\begin{verbatim}
&^_%\{}
\end{verbatim}
B
\endgroup

A
\begin{verbatim}
&^_%\{}
\end{verbatim}
B

\end{document}

Note the difference in output. After verbatim is gobbled, there's technically only a line-break (space) between A and B.

share|improve this answer
    
Excellent @Werner! This seems to work nicely and I can use it to get rid of proofs as well. –  WAJ Apr 2 '13 at 6:44
add comment

For the shorter version of your paper, you could load the comment package and replace all instances of {verbatim} with {comment}. That way, you won't have to deal with issues that arise from characters such as & and # occurring in the verbatim/comment areas.

share|improve this answer
1  
Haha.You beat me by 16 seconds! –  Gonzalo Medina Apr 2 '13 at 2:22
    
Thank you. That seems to work fine. Would it be possible for me to redefine the verbatim environment to be the comment environment? Then I would only to have to do that once at the beginning of the file instead of replacing every instance. –  WAJ Apr 2 '13 at 2:49
1  
@WAJ I think it's not possible due to the "voodoo" that verbatim does; but perhaps someone will prove me wrong. –  Gonzalo Medina Apr 2 '13 at 3:44
add comment

I come long after the battle but here is a way which just imitates the way verbatim is done in source2e.

\documentclass{article}
\usepackage{amsthm}
\newtheorem{theo}{Theorem}

\makeatletter
\let\original@proof\proof

% Plagiarizing verbatim set-up:
\begingroup 
    \catcode `|=0 \catcode `[= 1 \catcode`]=2 
    \catcode `\{=12 \catcode `\}=12 \catcode`\\=12 
    |long|gdef|suppressed@proof #1\end{proof}[|end[proof]]
|endgroup
\def\makeproofsinvisible
  {\def\proof
      {\catcode`\{=12 \catcode `\}=12 \catcode`\\=12 \suppressed@proof }}
\def\makeproofsvisible{\let\proof\original@proof }
\makeatother

\begin{document}

\begin{theo}[Unkn.]
  Dog exists.
\end{theo}

\begin{proof}
  First step: actually, we don't really exist.
\end{proof}

\makeproofsinvisible

\begin{proof}
  Second step is censored.
\end{proof}

\makeproofsvisible

\begin{proof}
  Third Step: hence Dog exists.
\end{proof}


\end{document}

invisible proofs

share|improve this answer
    
The reason this answer deals with the proof environment is that I was working on this other question when it got closed as duplicate. –  jfbu May 15 '13 at 17:44
add comment

The answer is from mine previous similar question Comment out lines without using % and comment enviroment which was answered by @egreg.

Seems to working properly with \begin{equation}.... But unfortunately it does not work well with \begin{verbatim}...

However, it is a good idea if finally corrected the bug. It will generally useful in the future

\documentclass[a4paper,10pt]{article}
\usepackage[utf8x]{inputenc}
\usepackage{verbatim}
\usepackage{lipsum}

\newif\ifprolog
\long\def\startprolog#1\stopprolog{%
  \ifprolog
  \par
  \begingroup
  \let\\\par
   #1 
  \par\medskip
  \endgroup
  \fi}

\prologtrue % comment out for omitted the inside \startprolog \stopprolog content
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

\begin{document}

\lipsum[1]

\startprolog
\begin{equation}
 k = \frac{1}{2} m u^2
\end{equation}
\stopprolog

\lipsum[1]

\startprolog
\begin{verbatim}
> eqn:=diff(y(t),t,t)+4*y(t)=0:
> inits:=y(0)=1,D(y)(0)=-1:
> dsolve({eqn,inits},y(t));
\end{verbatim}
\stopprolog

\lipsum[2]

\end{document}
share|improve this answer
add comment

Your Answer

 
discard

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.