TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to make inline comments in LaTeX that do not extend until the end of the line?

The actual problem I'm trying to solve is vim's annoying highlighting of the non-curly end-bracket here:




share|improve this question
VIM does not highlight ) in any way for me. Also note that your definition introduces three spaces, which will appear when the command is used. Add % at line ends to remove the spaces. Finally, how about trying titlesec for this task? – Andrey Vihrov Mar 6 '11 at 10:47
Wouldn't \renewcommand...{%( fix your paren problem? – Ulrich Schwarz Mar 6 '11 at 10:51
@Andrey: I added a picture. Thanks for the % tip; I didn't think it would work because of the indentation. I'll look inteo titlesec. – Tim N Mar 6 '11 at 10:55
@Ulrich: For some reason, it does not. I figured that vim is smart enough to understand that it is commented out. – Tim N Mar 6 '11 at 10:55
up vote 10 down vote accepted

You could create a command, which gobbles its argument, such as in the comment here: Control command arguments:


If you just wish to gobble a character, name it so and use it like

Text \commentchar()

which results in Text ).

Another way, shown by Joseph on LaTeX-Community.org is defining an active character for that, such as in this minimal example:

Text |ignored|Text

You have to take care of the spacing (blanks before and after) and possible side effects. This environment-way is fine, though again vim might unserstand that it's commented out, unlinke the \commentchar way.

share|improve this answer
Thanks, this is exactly what I was looking for. What does the asterisk in your \commentchar definition do? – Tim N Mar 6 '11 at 11:06
@Tim It defines a macro that is not \long, meaning that TeX will fail with an error if the paragraph ends while reading the argument. – Andrey Vihrov Mar 6 '11 at 11:27

Your Answer


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.