# How do you add a comment to pseudocode in LaTeX?

this is code // this is comment part (the part that I want)


Edit: To be more clear, what I mean is in "algorithmic" syntax I write some pseudo code. However, I am not sure if there is a standard comment used in that context.

-

## migrated from stackoverflow.comNov 21 '11 at 15:06

This question came from our site for professional and enthusiast programmers.

Welcome to TeX.sx! Your question was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other, otherwise you won't be able to comment on or accept answers or edit your question. – Torbjørn T. Nov 21 '11 at 15:21
To clarify the question, please compose a small MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. – Peter Grill Nov 21 '11 at 17:57
Although this does not specifically address comments, if you are still trying to choose which package to use, an excellent summary is available at: print programs with its proper syntax – Peter Grill Nov 21 '11 at 18:33

Since you use the term algorithmic, I assume you're using the algorithms bundle (which provides the algorithmic package and environment). Then the \COMMENT{...} macro typesets a comment in pseudo-code:

\documentclass{article}
\usepackage{algorithmic}% http://ctan.org/pkg/algorithms
\begin{document}
\begin{algorithmic}[1]
\STATE this is code \COMMENT{this is a comment}
\end{algorithmic}
\end{document}​


If you're using the (more advanced) algorithmicx package (and use \usepackage{algpseudocode}, which also provides an algorithmic environment), then the \Comment{...} macro typesets a comment in pseudo-code:

\documentclass{article}
\usepackage{algpseudocode}% http://ctan.org/pkg/algorithmicx
\begin{document}
\begin{algorithmic}[1]
\State this is code \Comment{this is a comment}
\end{algorithmic}
\end{document}​


In both these environments/packages, you are able to modify the formatting (or typesetting) of the comment. Alternatively, you could create your own \comment{...} macro as well, based on the existing commenting macros.

-

I found next possibilities:

1. Tab characters seem to work even in flexible columns.

2. escapechar=\% in options will turn on escape to LaTeX. Then, using %\mbox[2in][r]{comment}% should work, too.

-