LaTeX users online

In total there are 5 users online :: 0 registered, 0 hidden and 5 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 5 guests

inline comment and uncomment

LaTeX Forum: Text Formatting

commentsAdd tags Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)

Postby gaudetteje on Sun Apr 4th, 2010

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 online LaTeX editor
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

Postby frabjous on Sun Apr 4th, 2010

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 online LaTeX editor
\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.
User avatar
frabjous
 
Posts: 2065
Joined: Fri Mar 6th, 2009
Location: Amherst, MA

Postby josephwright on Sun Apr 4th, 2010

You could use an active character (risky and untested):
Code: Select all  •  Open in online LaTeX editor
\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: 813
Joined: Tue Jul 1st, 2008

Postby gaudetteje on Mon Apr 5th, 2010

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

Postby aaronmswan on Wed Mar 9th, 2011

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 online LaTeX editor
\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

Postby stoiczek on Mon Jul 15th, 2013

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 online LaTeX editor
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


Topic Tags

comments

Return to Text Formatting

LaTeX users online

Users browsing this forum: No registered users and 5 guests