Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Is there a special formatting to add comments to code? I mean I want to show comments in pseudocode that I write 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.

share|improve this question

migrated from stackoverflow.com Nov 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
add comment

4 Answers

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

From http://www.rasmusen.org/x/2007/09/07/comments-in-latex/

share|improve this answer
    
"want to show comments in pseudocode that I write in LaTeX.." –  aioobe Nov 21 '11 at 12:14
    
Actually this is not the answer I was looking for. 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. –  fireant Nov 21 '11 at 12:15
add comment

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:

enter image description here

\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:

enter image description here

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

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.