I am aware of other comment options, but I want to define /* as opening for mulitiline comment and */ as closing.

Any ideas?

  • 2
    this is so far from standard tex syntax that any solution is going to be very fragile and only work if the document obeys lots of extra conditions. – David Carlisle Jun 24 '19 at 19:46

This might break other things (David points out that the braces in a comment must be balanced, for example and you can't have a % preceding the closing */ on the same line; also, other uses of / inside an argument will be trashed, for example a slash as part of an \includegraphics subdirectory filename).

This approach makes / active, which means it is now a macro name, and will absorb space after it, so if you use a / by itself, you may need to add {} following it, so that subsequent (desired) space is not suppressed.

I concur with David's strong recommendation NOT to use this approach, because of the gotchas!

Here is/* a comment that I want
to go on

and on

and on*/ something that I am testing.  But a normal /{} passes through.

enter image description here

  • 1
    but you can't comment out } or a % on the last line or ..... – David Carlisle Jun 24 '19 at 19:51
  • 2
    \includegraphics{images/hmm} might be interesting as well. (note these are not criticsms of your answer, just trying to persuade the OP not to use this syntax:-) – David Carlisle Jun 24 '19 at 19:54

One can setup a parser with pgf's parser module such that it gobbles any token, the only problem is we have to make / active, so it can't be used in filenames, TikZ or pgf options, etc.

Also it changes the catcode of % locally, such that they can appear inside of a C-comment, though this will fail if the input in already tokenized (so if it is already part of a macro).

Don't use this!


% we have to put this here, as the `/` would otherwise not work in the options
    \catcode`\*=12 % just to make sure `*` has the correct meaning

some /*comment that gobbles} %unbalanced{tokenlists*/ but a normal one /\ slips

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.