Re: trouble with \comment and arguments to \newenvironment



"Bill" <wrising@xxxxxxxxxxxxxx> writes:
>I am confused about the behavior of LaTeX in the following situation.
>It's a bit simplified from what I'm working on, but I've narrowed it
>down the the presence of an optional argument:
>
>This environment works just fine (for block on/off selections of text):
>\newenvironment{answer}{%
>\ifanswer\ifansfont\begin{rmfamily}\fi\else\comment\fi%
>}%
>{%
>\ifanswer\ifansfont\end{rmfamily}\fi\else\endcomment\fi%
>}
>
>Replacing the first line with the following also works just fine, as
>long as I give an argument to each \begin{answer} in the document:
>
>\newenvironment{answer}[1]{% etc...
>
>It keeps working just fine when the first line is the following, once
>again, as long as I give an argument to each \begin{answer}:
>
>\newenvironment{answer}[1][0]{% etc...
>
>If, however, I actually treat the optional argument as optional, by
>having the last specification but a \begin{answer} with no ``optional''
>argument. They are the type of errors that one sees when using \comment
>incorrectly, namely Paragraph ended before \verbatim@ was complete.

i can't replicate that.

>My guess is that the problem comes from LaTeX needing to somehow
>evaluate the block twice when the optional argument is not specified,
>but this seems odd.

it doesn't need to evaluate things twice. look at the definitions of
the commands: they may seem odd, but there ain't no multiple pass.

>Does anyone know of a workaround? The actual environment I'm defining
>is much more complicated than what is given above --- the above is the
>simplest scenario where I could reproduce the error.

but it isn't a complete failing example. filling in a few gaps, i get
something that doesn't fail.

if you want help, you need to develop the above enough that the rest
of us can actually see you failure on our own machines.
--
Robin (http://www.tex.ac.uk/faq) Fairbairns, Cambridge
.



Relevant Pages

  • Re: Physicist James Van Allen Dies at 91
    ... entirely dependent on the environment. ... unmanned craft are overwhelmingly effective. ... encounter few surprises. ... presence, and crew support functions carry significant overhead. ...
    (sci.space.history)
  • Re: =?iso-8859-1?Q?=A350?= Fine for putting junk mail in bin
    ... When the rest of the world is obsessing over climate change and the ... environment, it does seem odd that no restrictions have yet been placed on ...
    (uk.politics.misc)
  • Re: the liver and the brain
    ... Are there any environmental factors whose presence or absence ... >disrupt or divert development? ... "external" factors derived from other cells in the neighborhood. ... the environment is everything outside the ...
    (sci.cognitive)
  • Re: When will this ng come to accept that Fortran needs to go "back to the future" ?
    ... that you support.If you take it to an environment that you haven't yet ... software testing probably couldn't code a line of software or recognize ... I was immediately struck, however, by the presence of some #ifdefs in ...
    (comp.lang.fortran)
  • Hash compression.
    ... The subject may sound a bit odd, but I need to compress SHA-1 output. ... Let's assume in my environment it will be safe to use less that 20 ...
    (sci.crypt)