[Tex/LaTex] Hiding code comments in listings

listings

I'm using listings package and \lstinputstring command to insert code from a file. Is it possible to hide code comments in inserted code? I'm using a language in which # starts a comment and it lasts until the end of line. I tried to do this with escapeinside option, but I think I don't understand how it works.

Best Answer

I'd just cheat, and specify commentstyle=\color{white}. This is even used in the manual :-) It does have the defect that if you print on non-white paper you'll see it, but that's usually not happening. Of course, if you have a non-white background, just use the background color instead.


Edit: For block comments, you can also use morecomment=[is]{/*}{*/}, where the i makes the comment completely invisible; however, this doesn't work for single-line comments, instead deleting all of the source code after the first single-line comment it finds.

Related Question