# Block comments with *% and %*

I know the package comment which allows to use :

\begin{comment}
Lines
to
comment
\end{comment}


This is not very friendly to use. I would like to have the following possibility:

*%
Lines
to
comment
%*


This is similar to the multiline version of comment in JavaScript, C or C++.

This kind of syntax is very useful because I could then use...

## Comment

*%
Lines
to
comment
%*


## No comment

%*%
Lines
to
comment
%*


Is there a way to use *% and %* instead of \begin{comment} and \end{comment} respectively?

-
It is possible if you are using luaTeX. See tex.stackexchange.com/a/35017/323 – Aditya Dec 23 '11 at 13:08

It is possible without LuaTeX, but not in a robust way. I used ~% and %~ instead of * because making * active would break commands which expect * to be of category code other (e.g., \section*{...} would not work anymore).

\begingroup
\catcode \@ = 11
\catcode \~ = 13
\catcode \% = 12
\protected\long\gdef\cmt@remove#1%~{\endgroup}
\ifdefined~
\global\let\cmt@old~
\else
\global\let\cmt@old\relax
\fi
\protected\gdef~{\begingroup\catcode%=12
\futurelet\next\cmt@}
\protected\gdef\cmt@
{\ifx%\next
\expandafter\cmt@remove
\else
\endgroup\expandafter\cmt@old
\fi}
\endgroup

-
Thanks for this solution. – projetmbc Dec 25 '11 at 19:12

In ConTeXt MkIV, you can do this with the normal comment environment (which is called hiding). The environment stop mark need not be on a line of its own. So, you can use:

\starttext
Normal
\starthiding
Hidden
%\stophiding
\stoptext


If you comment the line starting with \starthiding, the hidden content will be shown.

But if you want to include and exclude environments, it is better to define a new comment environment and use \includecomment and \excludecomment to change its behavior.

-