Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a problem with \excludecomment from comment package and a \newcommand.

The following codes work good, which means, it can generate the desired pdf output.

\documentclass{article}

\usepackage{comment}
\excludecomment{dontshow}

\begin{document}
This is a test.

\begin{dontshow}
test test test
\end{dontshow}

\end{document}

However, if I add the following:

\newcommand{\noshow}[2]{#1=#2 \begin{dontshow}#2=#1\end{dontshow} #1=#2}
\noshow{abc}{def}

It generates an error:

(c:/texlive/2010/texmf-dist/tex/latex/comment/comment.sty
Excluding comment 'comment') Excluding comment 'dontshow' (./test.aux))
Runaway argument?
! File ended while scanning use of \next.
<inserted text> 
                \par 
<*> test.tex

? 

How can I use 'comment' in a \newcommand?

share|improve this question

1 Answer 1

up vote 7 down vote accepted

The environments of the comment package need to be on their own:

The opening and closing commands should appear on a line of their own. No starting spaces, nothing after it.

AFAIK they don't work in macros like yours because they skip everything verbatim. There you could use if-switches for most content (except for unbalanced if-switches).

\documentclass{article}

\newif\ifshow
%\showtrue
\showfalse

\usepackage{comment}
\ifshow
\includecomment{dontshow}
\else
\excludecomment{dontshow}
\fi

\newcommand{\noshow}[2]{#1=#2 \ifshow #2=#1 \fi #1=#2}

\begin{document}
This is a test.

\begin{dontshow}
test test test
\end{dontshow}

\noshow{abc}{def}

\end{document}
share|improve this answer
    
Thanks. From your codes, if I input \noshow{abc}{def}, that is same as: abc=def \begin{dontshow} def=abc\end{dontshow} abc=def ? I don't quite understand how \ifshow' connects to dontshow' environment. –  FEQ Feb 27 '11 at 18:01
    
The if-switches are not directly connected to the environments. The show name can be changed to a different name if you want. Both are getting coupled just after loading the package when the if-switch in- or excludes the dontshow environment. –  Martin Scharrer Feb 27 '11 at 18:05
    
Thanks a lot, Martin! –  FEQ Feb 27 '11 at 20:04
    
Thanks the hint about spaces and stuff after the begin/end command helped me fixiing my problem with the comment package –  tim Jan 15 at 18:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.