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.

Please correct my code as necessary. It is not compiling due to

! Package exercise Error: You don't respect the hierarchy of questions.

See the exercise package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.13 \begin{Question}W
                      hat is the symbol for copper?\end{Question}
? 

The code is as follows:

\documentclass[12pt]{article}
\usepackage[a4paper]{geometry}
\usepackage{mhchem}


\usepackage[lastexercise]{exercise}

\begin{document}
\section{Naming of Chemical Compounds - A ``DIY'' Tutorial}

\begin{Exercise}[title=DIY]\end{Exercise}
\begin{ExePart}Question 1\end{ExePart}
\begin{Question}What is the symbol for copper?\end{Question}
\begin{Answer}\ce{Cu}\end{Answer}

\end{document}

It could be that I've missed something but the documentation does not even provide an example of the package's usage.

share|improve this question
2  
I haven't seen the documentation (as the error suggests to do), but I'm supposing that the Exercise environment should probably end after the Answer environment... that would make more sense to me. Just a guess though... –  ℝaphink Jul 5 '11 at 8:22
    
I thought they should be nested at first too but that results in an error ! LaTeX Error: \begin{list} on input line 13 ended by \end{Question}. See the LaTeX manual or LaTeX Companion for explanation. Type H <return> for immediate help. ... l.13 ...at is the symbol for copper?\end{Question} ? Any ideas? –  ptrcao Jul 5 '11 at 8:28
1  
Just playing with it... the package doesn't seem very robust, and the doc doesn't really help... –  ℝaphink Jul 5 '11 at 8:31
1  
I agree, the documentation is really lacking in instructive value; at first it seemed polished and comprehensive but after reading for half an hour I'm not much wiser for it... Package authors are not doing justice to their packages if documention doesn't actually instruct in its usage, explicitly. –  ptrcao Jul 5 '11 at 8:54
add comment

3 Answers

up vote 6 down vote accepted

I managed to get it to work using the ExerciseList environment:

\documentclass[12pt]{article}
\usepackage[a4paper]{geometry}
\usepackage{mhchem}


\usepackage[lastexercise]{exercise}

\begin{document}
\section{Naming of Chemical Compounds - A ``DIY'' Tutorial}

\begin{ExerciseList}
  \Exercise[title=DIY]
  \ExePart{Question 1}
  \Question{What is the symbol for copper?}
  \Answer{\ce{Cu}}
\end{ExerciseList}

\end{document}

Use of \ExePart or redefinition of \QuestionNB

That said, you shouldn't need the \ExePart just to print "Question 1". It might be better to redefine \QuestionNB instead, like this:

\renewcommand{\QuestionNB}{Question~\arabic{Question}.\ }

Theorically, that should do what you want to achieve, although in practice, it's kind of a mess. I feel the reason is that the label is hardcoded in the package, and without a variable. This can however be "fixed" by resetting \QuestionIndent:

\setlength{\QuestionIndent}{7em}

So your example becomes:

\documentclass[12pt]{article}
\usepackage[a4paper]{geometry}
\usepackage{mhchem}


\usepackage[lastexercise]{exercise}

\begin{document}
\section{Naming of Chemical Compounds - A ``DIY'' Tutorial}

\renewcommand{\QuestionNB}{Question~\arabic{Question}.\ }
\setlength{\QuestionIndent}{7em}

\begin{ExerciseList}
  \Exercise[title=DIY]
  \Question{What is the symbol for copper?}
  \Answer{\ce{Cu}}
\end{ExerciseList}

\end{document}

which works for me (although I would personally find it nicer to put questions on the next line -- note: I'm not using the mhchem package):

exercise_example

After playing a bit with more Questions/Answers, I do think it's missing a linebreak somewhere:

more questions

I'm also not very sure of the spacing: answers end up being closer to the next question than to the question they relate to...

Exercise title

In fact, it seems the problem with the linebreak comes from the fact that you're using \Exercise[title=DIY] instead of simply \Exercise{DIY}, which defines the exercise name. When I change this:

\documentclass[12pt]{article}
\usepackage[a4paper]{geometry}
\usepackage{mhchem}


\usepackage[lastexercise]{exercise}

\begin{document}
\section{Naming of Chemical Compounds - A ``DIY'' Tutorial}

\renewcommand{\QuestionNB}{Question~\arabic{Question}.\ }
\setlength{\QuestionIndent}{7em}

\begin{ExerciseList}
  \Exercise{DIY}
  \Question{What is the symbol for copper?}
  \Answer{\ce{Cu}}
  \Question{What is the symbol for aluminum?}
  \Answer{\ce{Al}}
  \Question{What is the symbol for iron?}
  \Answer{\ce{Fe}}
\end{ExerciseList}

\end{document}

I get a linebreak:

proper_linebreaks

and it is not necessary anymore to redefine \QuestionIndent:

without redefining QuestionIndent

share|improve this answer
    
Great! :) Just one small problem: did you notice the Question counter isnt advancing; it's just staying on 1? Shouldn't it automatically advance? Do you know how to fix this? Thanks. :) –  ptrcao Jul 5 '11 at 9:36
add comment

\Question is a command, not environment. That's why you get the errors.

\documentclass[12pt]{article}
\usepackage[a4paper]{geometry}


\usepackage[lastexercise]{exercise}

\begin{document}
\section{Naming of Chemical Compounds - A ``DIY'' Tutorial}



\begin{Exercise}[title=DIY,label=E1]
\ExePart[name=simple]
\Question{What is the symbol for copper?}\label{Q1}
\Question{What is the symbol for oxygen?}\label{Q2}

\ExePart[name=difficult]
\Question{What 42?}
\end{Exercise}

\begin{Answer}[ref=E1]\ref{Q1}. Cu  \quad\ref{Q2}. O \end{Answer}
\end{document}
share|improve this answer
1  
Is there a way to have the answers immediately follow their respective questions, rather than appear all at once at the end? That is, so you get Q1, A1, Q2, A2, ... etc. –  ptrcao Jul 5 '11 at 13:30
add comment

Answers must be out of the list. This way, counters work fine.

\documentclass[12pt]{article}
\usepackage[a4paper]{geometry}


\usepackage[lastexercise, answerdelayed]{exercise}


\begin{document}
\section{Naming of Chemical Compounds - A ``DIY'' Tutorial}


\begin{ExerciseList}
  \Exercise[title=DIY, label=E1]
  \ExePart{Question 1}
  \Question{What is the symbol for copper?}
  \Question{What is the symbol for iron?}
  \ExePart{Question 1}
  \Question{What is the symbol for copper?}
  \Question{What is the symbol for iron?}

  \Exercise[title=DIY, label=E2]
  \ExePart{Question 1}
  \Question{What is the symbol for oxigen?}
  \Question{What is the symbol for hidrogen?}
  \ExePart{Question 1}
  \Question{What is the symbol for oxigen?}
  \Question{What is the symbol for hidrogen?}



\end{ExerciseList}



  \begin{Answer}[ref=E1]
  \ExePart{Question 1}
  \Question{Cu}
  \Question{Fe}     
  \ExePart{Question 1}
  \Question{Cu}
  \Question{Fe}     
  \end{Answer}

  \begin{Answer}[ref=E2]
  \ExePart{Question 1}
  \Question{O}
  \Question{H}      
  \ExePart{Question 1}
  \Question{O}
  \Question{H}      
  \end{Answer}


\paragraph*{ Solutions:}   Now, let's see te solutions
\shipoutAnswer 
\end{document}
share|improve this answer
add comment

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.