21

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?

1
13

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
0
6

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.