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

9 comments:

way4thesub said...

That is so very clever!

Anonymous 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

EHX 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

Unknown said...

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

www.imarksweb.org

eddyshaw9272711 said...

I’m impressed, I have to say. Actually not often do I encounter a weblog that’s each educative and entertaining, and let me let you know, you've gotten hit the nail on the head. Your thought is outstanding; the issue is one thing that not enough people are speaking intelligently about. I am very glad that I stumbled throughout this in my seek for something regarding this. online casinos for us players

Post a Comment