2

In xsim I would like to combine a question environment with a solution environment. I am getting an error:

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! ! LaTeX error: "xparse/environment-already-defined" ! ! Environment 'solution' already defined! ! ! See the LaTeX3 documentation for further information. ! ! For immediate help type H .

I used to name my environments question/answer, but I'd like to use the name solution instead of answer --- everything else unchanged. Is it possible?

This is what works:

\documentclass{article}
\usepackage{xsim}
\DeclareExerciseType{question}{
  exercise-env = question,
  solution-env = answer, % would like to rename answer -> solution 
  exercise-name = Question,
  solution-name = Answer,
  exercise-template = default,
  solution-template = default
}
\xsimsetup{answer/print=true} % would like to rename answer -> solution 
\begin{document}
\begin{question}
My Question
\end{question}
\begin{answer}% would like to rename answer -> solution 
My Answer
\end{answer}% would like to rename answer -> solution 
\end{document}

This is what doesn't work, after renaming answer to solution:

\documentclass{article}
\usepackage{xsim}
\DeclareExerciseType{question}{
  exercise-env = question,
  solution-env = solution, % IF NAMED 'solution' throws an error!
  exercise-name = Question,
  solution-name = Answer,
  exercise-template = default,
  solution-template = default
}
\xsimsetup{solution/print=true}
\begin{document}
\begin{question}
My Question
\end{question}
\begin{solution}
My Answer
\end{solution}
\end{document}

EDIT short answer: solution is a reserved keyword of the xsim package. Can't use it. Thanks egreg.

3

The solution environment is predefined. Why don't you simply change the printed names?

\documentclass{article}
\usepackage{xsim}

\xsimsetup{
  exercise/name=Question,
  solution/print=true,
  solution/name=Answer,
}

\begin{document}
\begin{exercise}
My Question
\end{exercise}
\begin{solution}
My Answer
\end{solution}
\end{document}

enter image description here

  • egreg, my question really was about using the question and solution environments together, as in begin{question}, etc. and begin{solution}, etc.. Not about the name of the environment as it gets printed. Sorry about the confusion. My workaround was to use a name other than solution (my first choice word). Examples of alternatives hint, key, solutionX, mcSolution and solutions (with an s). You may want to add this to your answer or if you can hack xsim to allow setting solution-env=solution that would be best. Thanks again. – PatrickT Apr 24 '18 at 9:10
  • @PatrickT I tried undefining solution, but it doesn't work. Why is answer not good? – egreg Apr 24 '18 at 9:26
  • Thanks for your help egreg. I'm already using answer for an environment that could not easily map to the xsim syntax. I was basically looking for a synonym to answer and I thought solution was the simplest, but hadn't realize that it's a reserved keyword of the xsim package (does the manual mention that?). I'm now using mc/hint with xsim and keeping my old answer for my other environment. I have hundreds of questions/answers, so it would be time consuming to rewrite it all to fit xsim. It was basically a stupid question with a simple workaround. Thanks! – PatrickT Apr 24 '18 at 12:51
  • 1
    @PatrickT It might be a feature request: an option for not defining the default environments. It would be very easy to implement. – egreg Apr 24 '18 at 14:10
  • Oh why good idea, here: github.com/cgnieder/xsim/issues/31 – PatrickT Apr 24 '18 at 14:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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