2

% starts an end-of-line comment in LaTeX. Is there any way I comment an entire paragraph without putting a % in front of each individual line?

Note: I write my LaTeX code in texmaker.

jub0bs
  • 58,916
Lost1
  • 325

3 Answers3

6

The verbatim package provides a comment environment for dealing with chunks of the input:

Sample output

\documentclass{article}

\usepackage{verbatim}

\begin{document}

Normal text that will be printed.

\begin{comment}
  Text and other input \( x^2 \) that will be ignored.

\section{Heading}
\label{sec:heading}

Even this heading.
\end{comment}

Further material that will be printed.

\end{document}
Andrew Swann
  • 95,762
  • didn't work after doing this, does it mean i don't have the package? would there be a compiling error if if i write \usepackage{verbatim}, but I don't actually have it? – Lost1 Jan 14 '14 at 13:43
  • @Lost1 verbatim is part the standard distributions. What error do you get? – Andrew Swann Jan 14 '14 at 13:47
  • 2
    I would not recommend using comment as it is really easy to miss that this is commented out (unless your editor is good a coloring the contents of the comment env). Most LaTeX friendly editors mark outcommented lines very visually and is thus prefered – daleif Jan 14 '14 at 13:47
  • texmaker highlights something in orange when it is a comment it does not recognise - this is exactly what happened. If i just add the package into the file, there is no error in compiling but it does not recognise the \begin{comment} command – Lost1 Jan 14 '14 at 13:54
  • Then please provide more information about your document, ie post a MWE – daleif Jan 14 '14 at 14:08
6

If the question is how to comment a block of text without manually adding a % at the beginning of each line, you can do the following in texmaker.

Mac OS

Select the block of text you want to comment and hit

Cmd + T to comment, and

Cmd + U to uncomment.

Windows/Linux (I think...)

Select the block of text you want to comment and hit

Ctrl + T to comment, and

Ctrl + U to uncomment.

jub0bs
  • 58,916
  • i tried ctrl+T for windows, didn't work, sorry. :( – Lost1 Jan 14 '14 at 14:03
  • @Lost1, you can see the actual shortcut in the Edit menu. – daleif Jan 14 '14 at 14:05
  • @Lost1 See http://tex.stackexchange.com/questions/91432/comment-many-lines – jub0bs Jan 14 '14 at 14:06
  • Just tested latest TM on windows, I cannot get Ctrl-t to react in my virtual Win7 either. You will have to choose comment from the Edit menu using the mouse. Might also be an idea to report this to the developers. (Though this may be an effect of the virtualizaition software I use) – daleif Jan 14 '14 at 14:11
  • @daleif I don't have a Windows machine. Perhaps you should report it to them (him, really). – jub0bs Jan 14 '14 at 14:13
1

There is a comment package for this exact functionality and more.

\documentclass{article}

\usepackage{comment}

\begin{document}

A

\begin{comment}

XYZ

\end{comment}

\end{document}
masu
  • 6,571