### Who is online

In total there are 9 users online :: 0 registered, 0 hidden and 9 guests (based on users active over the past 5 minutes)
Most users ever online was 1327 on Tue Nov 05, 2013 7:11 pm

Users browsing this forum: No registered users and 9 guests

## inline comment and uncomment

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

Code: Select all  •  Open in writeLaTeX
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
gaudetteje

Posts: 2
Joined: Sun Apr 4th, 2010

### Re: inline comment and uncomment

Best I can think of off the topic of my head would be to define a command that doesn't do anything, e.g.:

Code: Select all  •  Open in writeLaTeX
\documentclass{article}\newcommand{\ignore}[1]{}\begin{document}This is my first sentence.\ignore{This is a hidden comment.} This second sentence should display.\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.

frabjous

Posts: 2065
Joined: Fri Mar 6th, 2009
Location: Amherst, MA

### Re: inline comment and uncomment

You could use an active character (risky and untested):
Code: Select all  •  Open in writeLaTeX
\catcode\|=\active\def|#1|{}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
josephwright
Site Moderator

Posts: 802
Joined: Tue Jul 1st, 2008

### Re: inline comment and uncomment

Thanks for the help! Both appear to be equally valid. I think the "best" one comes down to personal preference.
gaudetteje

Posts: 2
Joined: Sun Apr 4th, 2010

### Re: inline comment and uncomment

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.

Code: Select all  •  Open in writeLaTeX
\documentclass{article}\newcommand{\ignore}[2]{\hspace{0in}#2}\begin{document}Notice there is a space before \ignore{This is a hidden comment.} and after this comment.\end{document}
aaronmswan

Posts: 1
Joined: Wed Mar 9th, 2011

### Re: inline comment and uncomment

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:

Code: Select all  •  Open in writeLaTeX
This is my first sentence. %This is a hidden comment.This second sentence should display`

should do the trick.
stoiczek

Posts: 1
Joined: Mon Jul 15th, 2013