[comp.text.tex] Ignoring text in LaTeX

smithda@cpsvax.cps.msu.edu (J. Daniel Smith) (04/08/90)

Has anyone written a "comment" environment for LaTeX?  The text
between "\begin{comment}" and "\end{comment}" would not be typeset by
LaTeX. 

Thanks for any and all help,
   Dan
=========================================================================
J. Daniel Smith                      Internet: smithda@cpsvax.cps.msu.edu
Michigan State University              BITNET: smithdan@msuegr
East Lansing, Michigan                 Usenet: uunet!frith!smithda

Important references are given in boldface.  Italicized numbers indicate
fleeting references, wheras numbers in parentheses refer to mere
implications or unwarranted extrapolations.  Asterisks are used to
identifiy particularly distasteful passages.
          - Peter Schickele, The Definitive Biography of P.D.Q. Bach
=========================================================================

douglis@kvetching.Berkeley.EDU (Fred Douglis) (04/11/90)

I got this from Ed Wang a while ago...  works for me.

Fred

% comment.sty
% 25-Oct-89
% By Ed -- modified from verbatim in /usr/loca/lib/tex82/latex.tex

% \begin{comment}
% \end{comment}

\makeatletter

\begingroup \catcode `|=0 \catcode `[= 1
\catcode`]=2 \catcode `\{=12 \catcode `\}=12
\catcode`\\=12 |gdef|@xcomment#1\end{comment}[|end[comment]]
|endgroup

\def\@comment{\let\do\@makeother \dospecials\catcode`\^^M=10\def\par{}}

\def\begincomment{\@comment\@xcomment}

\makeatother

\newenvironment{comment}{\begincomment}{}

mcken@grip.cis.upenn.edu (Raymond McKendall) (04/11/90)

I've seen this in several places:

command:

\long\def\comment#1{}

use:

\comment{ ignored text
 ignored text
 ignored text
 .
 .
 .
 ignored text
}


R.McKendall
GRASP Lab
University of Pennsylvania
mcken@grip.cis.upenn.edu

halldors@paul.rutgers.edu (Magnus M Halldorsson) (04/11/90)

The following simple macro will do it (thanks to Martin Carroll):

\newcommand{\comment}[1]{}

Magnus

smithda@cpsvax.cps.msu.edu (J. Daniel Smith) (04/11/90)

In article <7147@cps3xx.UUCP> smithda@cpsvax.cps.msu.edu (J. Daniel Smith) writes:
>Has anyone written a "comment" environment for LaTeX?  The text
>between "\begin{comment}" and "\end{comment}" would not be typeset by
>LaTeX. 
Well, I did some hacking on my own and came up with a set of macros to
do what I wanted.  I'm not sure about all the \catcode stuff, but my
intent was to make the argument as small as possible by turning most
of the characters into comment characters.  I tried this with the
entire latex.tex file between \begin{comment} and \end{comment} and it
worked ok (i.e. nothing was printed).  Without the \catcode stuff I
overflowed TeX's memory.  

   Dan
------
%
% J. Daniel Smith
% 7 April 1990
%
% comment.sty
%
% All text between \begin{comment} and \end{comment} is ignored by
% LaTeX.  Modified from the verbatim macros of LaTeX.
%
\typeout{Document Style option `comment' <7 Apr 90>.}
%
\catcode`@=11
%
\def\c@tend{\catcode`@=14\catcode``=14}
\def\c@mmentcat{
        \let\c@=\catcode
	\c@`!=14 \c@`"=14 \c@`\#=14
	\c@`\$=14 \c@`\&=14 \c@`'=14 \c@`(=14
	\c@`)=14 \c@`*=14 \c@`+=14 \c@`,=14 \c@`-=14
	\c@`.=14 \c@`/=14 \c@`0=14 \c@`1=14 \c@`2=14
	\c@`3=14 \c@`4=14 \c@`5=14 \c@`6=14 \c@`7=14
	\c@`8=14 \c@`9=14 \c@`:=14 \c@`;=14 \c@`<=14
	\c@`==14 \c@`>=14 \c@`?=14 \c@`@=14 \c@`A=14
	\c@`B=14 \c@`C=14 \c@`D=14 \c@`E=14 \c@`F=14
	\c@`G=14 \c@`H=14 \c@`I=14 \c@`J=14 \c@`K=14
	\c@`L=14 \c@`M=14 \c@`N=14 \c@`O=14 \c@`P=14
	\c@`Q=14 \c@`R=14 \c@`S=14 \c@`T=14 \c@`U=14
	\c@`V=14 \c@`W=14 \c@`X=14 \c@`Y=14 \c@`Z=14
	\c@`[=14 \c@`]=14 \c@`^=14 \c@`_=14
	\c@`a=14 \c@`f=14 \c@`g=14 \c@`h=14 \c@`i=14
	\c@`j=14 \c@`k=14 
	\c@`q=14 \c@`s=14
	\c@`u=14 \c@`v=14 \c@`w=14 \c@`x=14
	\c@`y=14 \c@`z=14 \c@`|=14
	\c@`~=14 \c@` =14\c@tend}
%
\begingroup \catcode `|=0 \catcode `[= 1
\catcode`]=2 \catcode `\{=12 \catcode `\}=12
\catcode`\\=12 |long|gdef|@xcomment#1\end{comment}[|end[comment]]
|endgroup

\def\@comment{\let\do\@makeother \dospecials\c@mmentcat}

\newenvironment{comment}{\@comment\@xcomment}{}
%
\catcode`@=12
%
=========================================================================
J. Daniel Smith                      Internet: smithda@cpsvax.cps.msu.edu
Michigan State University              BITNET: smithdan@msuegr
East Lansing, Michigan                 Usenet: uunet!frith!smithda

All such expressions as sqrt(-1), sqrt(-2)... are neither nothing, nor
greater than nothing, nor less than nothing, which necessarily
constitutes them imaginary or impossible.
                         - L. Euler
=========================================================================

wtho@cgch.uucp (Tom Hofmann) (04/12/90)

In article <7147@cps3xx.UUCP> smithda@cpsvax.cps.msu.edu (J. Daniel Smith) writes:
|Has anyone written a "comment" environment for LaTeX?  The text
|between "\begin{comment}" and "\end{comment}" would not be typeset by
|LaTeX. 

Some time ago, I wrote an environment which allows to "switch" the
included text on and off.  Here it is:

--------- cut here -----------------------------------------------------

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% File "annotation.sty" (by Tom Hofmann, E-mail: wtho@cgch.UUCP)
% 1989-10-30
% 
% This File contains the definition of a LaTeX environment "annotation"
% which allows to alternatively print or suppress parts of the document.
%
%
% Usage:
%
%    - Declare "annotation" as documentstyle option or include this file
%      by "\input{annotation.sty}"
%    - Embed annotations in "\begin{annotation}" and "\end{annotation}"
%    - To print the document including the annotations write "\printnotes"
%      before the first annotation. Alternatively, write "\suppressnotes"
%      to print without annotations.
%    - The default setting is "\printnotes".
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


% (1) Definition of the environment "annotation" when notes are
%     to be printed.

\def\printnotes{\def\annotation{}}	% "\endannotation" can be missing

% (2) Definition of the environment "annotation" when notes are not
%     to be printed.

%     Make '{' and '}' "other characters" and make '(' and ')'
%     "begingroup" and "endgroup" resp.  Thus make it possible
%     to have "\end{annotation}" as part of a macro definition.

\begingroup\makeatletter		% since the catcodes of '{' and '}'
\catcode`{=12\relax\catcode`}=12\relax	% will change, use \begingroup and
\catcode`(=1\relax \catcode`)=2\relax	% \endgroup instead.

\gdef\suppressnotes(%

%     Make '{' and '}' searchable when expanding the macro by giving them
%     the same catcode in the subsequent text as in the macro definition.

	  \gdef\annotation(\catcode`{=12\relax\catcode`}=12\relax\@NOTE)

%     Skip text between "\begin{annotaion}" and "\end{annotation}"
%     (inclusive), but return an "\end{annotation}" command to LaTeX for
%     the correct environment handling (see below).

	  \long\gdef\@NOTE##1\end{annotation}(\@ENDNOTE))


\endgroup				% End of the enchantment.

%     Generate an environment-end command conformable to LaTeX.

{\makeatletter\gdef\@ENDNOTE{\end{annotation}}}

\printnotes				% This is the default setting.

%%%%%%%% END OF FILE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

rjc@aipna.ed.ac.uk (Richard Caley) (04/12/90)

In article <7147@cps3xx.UUCP> smithda@cpsvax.cps.msu.edu (J. Daniel Smith) writes:
>Has anyone written a "comment" environment for LaTeX?  The text
>between "\begin{comment}" and "\end{comment}" would not be typeset by
>LaTeX. 

I use the following, it is probably not the best way to do it, seems to
work. Basically it sets the comment in italics in narrow margins for
drafts but ignores it for polished versions. It decides you a producing
a draft  if you have the overfull marker set, the draft style option
does this.

% comments - there are either ignored or set as a 'setcomment'
% depending on whether the draft option was selected.

\ifdim \overfullrule =0pt
       \def\comment{\@swallowall}
	\else\def\comment{\setcomment}
\fi
\ifdim \overfullrule =0pt
       \def\endcomment{\@endswallowall}
	\else\def\endcomment{\endsetcomment}
\fi

\newsavebox{\@rubishbin}
\newenvironment{@swallow}{\setbox\@rubishbin\vbox\bgroup}{\egroup}

\newenvironment{setcomment}{\list{}{\advance\leftmargin 5em
				\rightmargin\leftmargin}\item[] \em}{\endlist}

wargaski@ils.nwu.edu (Robert E. Wargaski Jr.) (04/13/90)

Perhaps I am missing the point on this, folks, but why not just use the
friendly
percent (%) sign?

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Robert E. Wargaski Jr.		    |	This is stupid. -- Vila
wargaski@ils.nwu.edu		    |	When did that ever stop us. -- Avon
NU Distributed Systems Services	    |	. . . #include <disclaimer.h> . . .