TransWikia.com

Using answers environments inside commands

TeX - LaTeX Asked by Dodo4247 on April 7, 2021

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} #1end{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}.)

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP