3

I use package answers for putting answers or hints to problems at the end of a document. I wonder if it is possible to use the environment for solutions inside a command. But the straightforward way:

\documentclass[11pt,a4paper]{article}
\usepackage{amsthm}
\usepackage{answers}

\newtheorem{problem}{Problem}
\Newassociation{sol}{Sol}{solutions}
\newcommand{\shortsol}[1]{\begin{sol} #1\end{sol}}

\begin{document}    
    \Opensolutionfile{solutions}
    
    \begin{problem}
    This is problem.
    \shortsol{42}
    \end{problem}
        
    \Closesolutionfile{solutions}
    
    \section*{Solutions}
    \input{solutions}
\end{document}

leads to the error:

Runaway argument?
! File ended while scanning use of \next.
<inserted text>
                \par

I would appreciate if someone tells me if such a thing is possible. (I am trying to use solutions environments inside commands mainly for compatibility reasons. I have some other documents where the problems are written using commands, e. g. \problem{Statement}{Result is 42}.)

3
  • Can you show some output. How you want to see it. Apr 6, 2021 at 9:21
  • Basically you can't have sol in the argument to a command, because it needs to do verbatim-like business.
    – egreg
    Apr 6, 2021 at 10:01
  • Thank you. I wanted to have the result same as if I would write \begin{sol}42\end{sol} instead of \shortsol{42} and that works for me.
    – Dodo4247
    Apr 8, 2021 at 9:08

0

You must log in to answer this question.

Browse other questions tagged .