Wednesday, 19 January 2011

Inline comments in LaTeX

I recently got some feedback on an article that I've submitted, and when I started including the reviewer's comments in the revised version, I started wondering if there is a way to make an "in-line" comment in LaTeX documents. I often use the percent sign, %, to comment out everything after a line, like this:

... and thus we see that these methods are equvivalent. % Or are they?

After some searching I found an interesting post on Eric Rasmussen's blog, and it seems that the easiest way to do this is to define a "macro" that doesn't do anything, in the document preamble:

\newcommand{\comment}[1]{}

and then I can make an inline comment using the \comment{} command, like this:

... these methods are equvalent. \comment{Or are they?} Luckily, it doesn't matter...

8 comments:

way4thesub said...

That is so very clever!

naught101 said...

You can also just

\usepackage[disable]{todonodes}

\todo{comment goes here}

Martin H. Skjelvareid said...

Thanks, naught101 - that's a nice way to do it! I've used the todonotes package a little bit, and it seems very useful.

Ryan J. Dillon said...

I saw somewhere else suggest the simple method of just using standing comments, as vim doesn't read line breaks unless there are two.

The first of two sentences.
%todo maybe I should add a third sentence
The second of two sentences.

Paulo Sérgio Medeiros said...

Nice trick.

aa said...

I was looking for online article to help me on my work and I’m glad I come across your site. I got some explanations that I didn’t expected. Keep posting!

www.n8fan.net

Egor Hans said...

the newcommand method works also inside of command arguments, while the comment between single line breaks does not
I'd rather use providecommand though, because according to the documentation Texlipse is showing me, a package exists which provides exactly that command with exactly that outcome

Leslie Lim said...

I have a great fun reading your blogs. Thank you to the blogger. Have a great day.

www.imarksweb.org

Post a Comment