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 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?

share|improve this question
    
It is possible if you are using luaTeX. See tex.stackexchange.com/a/35017/323 –  Aditya Dec 23 '11 at 13:08
add comment

2 Answers 2

up vote 10 down vote accepted

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
share|improve this answer
    
Thanks for this solution. –  projetmbc Dec 25 '11 at 19:12
add comment

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.

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.