## LaTeX forum ⇒ Text Formatting ⇒ inline comment and uncomment

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
gaudetteje
Posts: 2
Joined: Sun Apr 04, 2010 3:01 pm

### inline comment and uncomment

Hi,

I have a paragraph of text and want to comment out only part of it. I could place a '%' to start the comment and then use a single <CR> after the end of the comment. Is there another way so that I don't need to place <CR>s after every comment? Below is an example of what I'm trying to do.

1. This is my first sentence. %This is a hidden comment.% This second sentence should display.

This code should display:
This is my first sentence. This second sentence should display.

Thanks,

-J

Tags:

frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am
Location: Amherst, MA
Best I can think of off the topic of my head would be to define a command that doesn't do anything, e.g.:

1. \documentclass{article}
2.
3. \newcommand{\ignore}[1]{}
4.
5. \begin{document}
6.
7. This is my first sentence.\ignore{This is a hidden comment.} This second sentence should display.
8.
9. \end{document}

Though you'll need to be careful with spaces. (E.g., don't put a space both before and after it.)

I think there are some better options, perhaps through the comment package, but I've never been able to make that package work as I wanted.

Perhaps someone else will be able to offer better advice.

josephwright
Site Moderator
Posts: 814
Joined: Tue Jul 01, 2008 2:19 pm
Contact:
You could use an active character (risky and untested):
1. \catcode`\|=\active
2. \def|#1|{}
3. Some text.|Invisible| Visible.

This will go wrong if you don't properly close the line ending, but things will recover at the end of a paragraph.
Joseph Wright

gaudetteje
Posts: 2
Joined: Sun Apr 04, 2010 3:01 pm
Thanks for the help! Both appear to be equally valid. I think the "best" one comes down to personal preference.

aaronmswan
Posts: 1
Joined: Wed Mar 09, 2011 6:58 pm
I'm somewhat new to Latex, but I think the following code makes a small improvement by ignoring white space after an inline command. It accepts the next non-whitespace character as a second argument and then displays it with no space in front of it.

1. \documentclass{article}
2.
3. \newcommand{\ignore}[2]{\hspace{0in}#2}
4.
5. \begin{document}
6.
7. Notice there is a space before \ignore{This is a hidden comment.} and after this comment.
8.
9. \end{document}

stoiczek
Posts: 1
Joined: Mon Jul 15, 2013 4:10 pm
Hi all,

On a slight note - do you really need to use such a complex solution? I may be wrong, but as far as I know, to create a new paragraph, you need to put an empty line. Thus solution like this:

1. This is my first sentence.
2. %This is a hidden comment.
3. This second sentence should display

should do the trick.