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 am using the answers package to build a series of exercises. The problem i have encountered is when going from

\item $ 5x^2-x \geq 0 $
\begin{sol}
$x \geq 1, x \leq 0$
\end{sol}

to

\uppg{$x<-2, x>2$}{$-9 < x < 9$}

Where uppg looks like

\newcommand{\uppg}[2]
{
\item  #1
\begin{sol}
\#2 
\end{sol}
}

I keep getting errors because it reads the \begin{sol} in uppg but ignores the \end{sol} and just keeps reading in the file until it realizes it's misstakes and throws an error. How can i resolve this?

share|improve this question
    
Welcome to TeX.sx! You don't have to sign with your name since it automatically appears in the lower right corner of your post. –  przemoc Jul 14 '11 at 8:59

2 Answers 2

If Joseph is right and it is verbatim-like approach then that is the problem

How \begin{verbatim} works. briefly and roughly.

  1. \begin{verbatim} is expanded to \verbatim.
  2. Then \verbatim sets category code of each special characters to 12. Now all chars is like digits or puncts.
  3. Then \verbatim sets font, parindent and calls \@xverbatim.
  4. \@xverbatim catches the end of verbatim using the following trick:

    \def\@xverbatim#1\end{#1\end}
    
  5. Then \end{verbatim} finishes work.

How newcommand{\uppg}[1]{\begin{verbatim}#1\end{verbatim}} works.

  1. \uppg{$x$} expands to \begin{verbatim}$x$\end{verbatim}}.
  2. Then \begin{verbatim} expands to \varbatim. \varbatim changes all categories and font.
  3. Then \verbatim calls \@xverbatim.
  4. \@xverbatim tries to catch your argument using the following trick:

    \def\@xverbatim#1\end{#1\end}
    

    but it is impossible because of \@xverbatim tries to catch \end where all letters (\,e,n,d) have the category 12 and 11. But in fact there are only \ec exsits.

  5. \@xverbatim is trying and trying to find \end where backslash (\) has category 12 but.... File ended while scanning use of \@xverbatim
share|improve this answer
    
Is there any was around this, to avoid having to repetedly add four lines of code for each assignment, instead of the above \newcommand approach? –  Mats Jul 14 '11 at 11:46

The answers package uses a verbatim-like approach to collect up material. As a result, you cannot hide the \end{sol} part inside a macro: it has to be in the source as written.

share|improve this answer

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.