How to define environments for questions and answers











up vote
13
down vote

favorite
7












I wish to do a simple question and answer sheet for my students. I'd like to have something like this:



section{Differential Equations}

begin{questions}

begin{question}
... Question here ...
end{question}

begin{answer}
... Answer here ...
end{answer}

end{questions}


I wish to have the environment QUESTIONS to have counters like enumerate. That is, each begin{question} ... end{question} should behave just like item in



begin{question} 
item
end{question}


The begin{question} ... end{question} environment should take "normal" LaTeX commands.



If possible, I'd wish to have deferred printing to print the answers at the end of the document.



I first tried this



makeatletter
newtoksanswerscollect
newcounter{question}
setcounter{question}{0}
defthequestion{{bfseries{Question arabic{question}. }}\}

defanswer#1{%
protected@edefanswertmp{%
theanswerscollectvspace{.5baselineskip}noindentthequestion#1par}%
paranswerscollect=expandafter{answertmp}}
defprintanswers{theanswerscollectanswerscollect={}}
definitbox{answerscollect={parnoindent Answers:par}}

newcommand{question}[1]{stepcounter{question}parnoindentthequestion#1}
makeatother


but it's not behaving the way I'd love the results to be ...










share|improve this question
























  • Welcome to TeX.SX. Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Accepting and upvoting answers is the preferred way here to say "thank you" to users who helped you.
    – Claudio Fiandrino
    Apr 12 '13 at 12:52






  • 4




    Have you looked at the exam package? ctan.org/tex-archive/macros/latex/contrib/exam I guess the package answers too ctan.uib.no/macros/latex/contrib/answers/answers.pdf
    – N3buchadnezzar
    Apr 12 '13 at 12:53












  • @N3buchadnezzar I have tried a number of existing packages. They are cool, but do not actually give me the flexibility to do what I want!
    – Dorogz
    Apr 12 '13 at 13:10






  • 3




    I do not see anything in your question, making the answers package not valid. Please state what this package is missing =)
    – N3buchadnezzar
    Apr 12 '13 at 13:14










  • @N3buchadnezzar, I've looked at them and they are awkward to use. No lack of flexibility, mind you. But then again, I really don't see a simple(r) way to express the rather complex documents to be created... unless you leave the cozy LaTeX world and build a database with questions and answers, and splice the exam together from the result of a query.
    – vonbrand
    Apr 12 '13 at 13:49















up vote
13
down vote

favorite
7












I wish to do a simple question and answer sheet for my students. I'd like to have something like this:



section{Differential Equations}

begin{questions}

begin{question}
... Question here ...
end{question}

begin{answer}
... Answer here ...
end{answer}

end{questions}


I wish to have the environment QUESTIONS to have counters like enumerate. That is, each begin{question} ... end{question} should behave just like item in



begin{question} 
item
end{question}


The begin{question} ... end{question} environment should take "normal" LaTeX commands.



If possible, I'd wish to have deferred printing to print the answers at the end of the document.



I first tried this



makeatletter
newtoksanswerscollect
newcounter{question}
setcounter{question}{0}
defthequestion{{bfseries{Question arabic{question}. }}\}

defanswer#1{%
protected@edefanswertmp{%
theanswerscollectvspace{.5baselineskip}noindentthequestion#1par}%
paranswerscollect=expandafter{answertmp}}
defprintanswers{theanswerscollectanswerscollect={}}
definitbox{answerscollect={parnoindent Answers:par}}

newcommand{question}[1]{stepcounter{question}parnoindentthequestion#1}
makeatother


but it's not behaving the way I'd love the results to be ...










share|improve this question
























  • Welcome to TeX.SX. Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Accepting and upvoting answers is the preferred way here to say "thank you" to users who helped you.
    – Claudio Fiandrino
    Apr 12 '13 at 12:52






  • 4




    Have you looked at the exam package? ctan.org/tex-archive/macros/latex/contrib/exam I guess the package answers too ctan.uib.no/macros/latex/contrib/answers/answers.pdf
    – N3buchadnezzar
    Apr 12 '13 at 12:53












  • @N3buchadnezzar I have tried a number of existing packages. They are cool, but do not actually give me the flexibility to do what I want!
    – Dorogz
    Apr 12 '13 at 13:10






  • 3




    I do not see anything in your question, making the answers package not valid. Please state what this package is missing =)
    – N3buchadnezzar
    Apr 12 '13 at 13:14










  • @N3buchadnezzar, I've looked at them and they are awkward to use. No lack of flexibility, mind you. But then again, I really don't see a simple(r) way to express the rather complex documents to be created... unless you leave the cozy LaTeX world and build a database with questions and answers, and splice the exam together from the result of a query.
    – vonbrand
    Apr 12 '13 at 13:49













up vote
13
down vote

favorite
7









up vote
13
down vote

favorite
7






7





I wish to do a simple question and answer sheet for my students. I'd like to have something like this:



section{Differential Equations}

begin{questions}

begin{question}
... Question here ...
end{question}

begin{answer}
... Answer here ...
end{answer}

end{questions}


I wish to have the environment QUESTIONS to have counters like enumerate. That is, each begin{question} ... end{question} should behave just like item in



begin{question} 
item
end{question}


The begin{question} ... end{question} environment should take "normal" LaTeX commands.



If possible, I'd wish to have deferred printing to print the answers at the end of the document.



I first tried this



makeatletter
newtoksanswerscollect
newcounter{question}
setcounter{question}{0}
defthequestion{{bfseries{Question arabic{question}. }}\}

defanswer#1{%
protected@edefanswertmp{%
theanswerscollectvspace{.5baselineskip}noindentthequestion#1par}%
paranswerscollect=expandafter{answertmp}}
defprintanswers{theanswerscollectanswerscollect={}}
definitbox{answerscollect={parnoindent Answers:par}}

newcommand{question}[1]{stepcounter{question}parnoindentthequestion#1}
makeatother


but it's not behaving the way I'd love the results to be ...










share|improve this question















I wish to do a simple question and answer sheet for my students. I'd like to have something like this:



section{Differential Equations}

begin{questions}

begin{question}
... Question here ...
end{question}

begin{answer}
... Answer here ...
end{answer}

end{questions}


I wish to have the environment QUESTIONS to have counters like enumerate. That is, each begin{question} ... end{question} should behave just like item in



begin{question} 
item
end{question}


The begin{question} ... end{question} environment should take "normal" LaTeX commands.



If possible, I'd wish to have deferred printing to print the answers at the end of the document.



I first tried this



makeatletter
newtoksanswerscollect
newcounter{question}
setcounter{question}{0}
defthequestion{{bfseries{Question arabic{question}. }}\}

defanswer#1{%
protected@edefanswertmp{%
theanswerscollectvspace{.5baselineskip}noindentthequestion#1par}%
paranswerscollect=expandafter{answertmp}}
defprintanswers{theanswerscollectanswerscollect={}}
definitbox{answerscollect={parnoindent Answers:par}}

newcommand{question}[1]{stepcounter{question}parnoindentthequestion#1}
makeatother


but it's not behaving the way I'd love the results to be ...







lists environments






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 12 '13 at 12:51









Claudio Fiandrino

52k11152303




52k11152303










asked Apr 12 '13 at 12:50









Dorogz

73116




73116












  • Welcome to TeX.SX. Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Accepting and upvoting answers is the preferred way here to say "thank you" to users who helped you.
    – Claudio Fiandrino
    Apr 12 '13 at 12:52






  • 4




    Have you looked at the exam package? ctan.org/tex-archive/macros/latex/contrib/exam I guess the package answers too ctan.uib.no/macros/latex/contrib/answers/answers.pdf
    – N3buchadnezzar
    Apr 12 '13 at 12:53












  • @N3buchadnezzar I have tried a number of existing packages. They are cool, but do not actually give me the flexibility to do what I want!
    – Dorogz
    Apr 12 '13 at 13:10






  • 3




    I do not see anything in your question, making the answers package not valid. Please state what this package is missing =)
    – N3buchadnezzar
    Apr 12 '13 at 13:14










  • @N3buchadnezzar, I've looked at them and they are awkward to use. No lack of flexibility, mind you. But then again, I really don't see a simple(r) way to express the rather complex documents to be created... unless you leave the cozy LaTeX world and build a database with questions and answers, and splice the exam together from the result of a query.
    – vonbrand
    Apr 12 '13 at 13:49


















  • Welcome to TeX.SX. Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Accepting and upvoting answers is the preferred way here to say "thank you" to users who helped you.
    – Claudio Fiandrino
    Apr 12 '13 at 12:52






  • 4




    Have you looked at the exam package? ctan.org/tex-archive/macros/latex/contrib/exam I guess the package answers too ctan.uib.no/macros/latex/contrib/answers/answers.pdf
    – N3buchadnezzar
    Apr 12 '13 at 12:53












  • @N3buchadnezzar I have tried a number of existing packages. They are cool, but do not actually give me the flexibility to do what I want!
    – Dorogz
    Apr 12 '13 at 13:10






  • 3




    I do not see anything in your question, making the answers package not valid. Please state what this package is missing =)
    – N3buchadnezzar
    Apr 12 '13 at 13:14










  • @N3buchadnezzar, I've looked at them and they are awkward to use. No lack of flexibility, mind you. But then again, I really don't see a simple(r) way to express the rather complex documents to be created... unless you leave the cozy LaTeX world and build a database with questions and answers, and splice the exam together from the result of a query.
    – vonbrand
    Apr 12 '13 at 13:49
















Welcome to TeX.SX. Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Accepting and upvoting answers is the preferred way here to say "thank you" to users who helped you.
– Claudio Fiandrino
Apr 12 '13 at 12:52




Welcome to TeX.SX. Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Accepting and upvoting answers is the preferred way here to say "thank you" to users who helped you.
– Claudio Fiandrino
Apr 12 '13 at 12:52




4




4




Have you looked at the exam package? ctan.org/tex-archive/macros/latex/contrib/exam I guess the package answers too ctan.uib.no/macros/latex/contrib/answers/answers.pdf
– N3buchadnezzar
Apr 12 '13 at 12:53






Have you looked at the exam package? ctan.org/tex-archive/macros/latex/contrib/exam I guess the package answers too ctan.uib.no/macros/latex/contrib/answers/answers.pdf
– N3buchadnezzar
Apr 12 '13 at 12:53














@N3buchadnezzar I have tried a number of existing packages. They are cool, but do not actually give me the flexibility to do what I want!
– Dorogz
Apr 12 '13 at 13:10




@N3buchadnezzar I have tried a number of existing packages. They are cool, but do not actually give me the flexibility to do what I want!
– Dorogz
Apr 12 '13 at 13:10




3




3




I do not see anything in your question, making the answers package not valid. Please state what this package is missing =)
– N3buchadnezzar
Apr 12 '13 at 13:14




I do not see anything in your question, making the answers package not valid. Please state what this package is missing =)
– N3buchadnezzar
Apr 12 '13 at 13:14












@N3buchadnezzar, I've looked at them and they are awkward to use. No lack of flexibility, mind you. But then again, I really don't see a simple(r) way to express the rather complex documents to be created... unless you leave the cozy LaTeX world and build a database with questions and answers, and splice the exam together from the result of a query.
– vonbrand
Apr 12 '13 at 13:49




@N3buchadnezzar, I've looked at them and they are awkward to use. No lack of flexibility, mind you. But then again, I really don't see a simple(r) way to express the rather complex documents to be created... unless you leave the cozy LaTeX world and build a database with questions and answers, and splice the exam together from the result of a query.
– vonbrand
Apr 12 '13 at 13:49










2 Answers
2






active

oldest

votes

















up vote
14
down vote



accepted










Simple use of exam package :



documentclass{exam}
%printanswers
begin{document}

section{Differential Equations}
begin{questions}
question ... Short question here ... answerline[Short answer]
question ... Question here ...

begin{solution}[.2in]
... Answer here ...
end{solution}

question Long descriptive question about everything

begin{solutionorlines}[2in]
Long descriptive answer is a long descriptive answer that is a long descriptive answer that is along descriptive answer that is along descriptive answer that is along descriptive answer that is a lie.
end{solutionorlines}

question Draw an arrow showing north direction.

begin{solutionorbox}[2in]
$uparrow$
end{solutionorbox}

end{questions}

ifprintanswers
Stuff to appear only when answers textbf{are} being printed.
else
Stuff to appear only when answers textbf{are not} being printed.
fi

end{document}


Commenting and uncommenting printanswers yields in one of two following:



1)



Only questions



2)



Questions with answers



I don't see any lack of functionality compared to your example.






share|improve this answer



















  • 1




    At my department, we took exam.cls as a foundation for our own examination class, so that the cover page would always look the same, and it works very well. It is very flexible.
    – Benjamin McKay
    Oct 21 '13 at 15:20


















up vote
0
down vote













I am using begin{questions}...end{questions}. Output is like Q.1) Q.2) ...
I just want it like 1) 2) ... How to modify my code? Since I want to droppoints I need to use this question segment itself. So someone help me.





share








New contributor




Thasheela is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


















    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "85"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f108316%2fhow-to-define-environments-for-questions-and-answers%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    14
    down vote



    accepted










    Simple use of exam package :



    documentclass{exam}
    %printanswers
    begin{document}

    section{Differential Equations}
    begin{questions}
    question ... Short question here ... answerline[Short answer]
    question ... Question here ...

    begin{solution}[.2in]
    ... Answer here ...
    end{solution}

    question Long descriptive question about everything

    begin{solutionorlines}[2in]
    Long descriptive answer is a long descriptive answer that is a long descriptive answer that is along descriptive answer that is along descriptive answer that is along descriptive answer that is a lie.
    end{solutionorlines}

    question Draw an arrow showing north direction.

    begin{solutionorbox}[2in]
    $uparrow$
    end{solutionorbox}

    end{questions}

    ifprintanswers
    Stuff to appear only when answers textbf{are} being printed.
    else
    Stuff to appear only when answers textbf{are not} being printed.
    fi

    end{document}


    Commenting and uncommenting printanswers yields in one of two following:



    1)



    Only questions



    2)



    Questions with answers



    I don't see any lack of functionality compared to your example.






    share|improve this answer



















    • 1




      At my department, we took exam.cls as a foundation for our own examination class, so that the cover page would always look the same, and it works very well. It is very flexible.
      – Benjamin McKay
      Oct 21 '13 at 15:20















    up vote
    14
    down vote



    accepted










    Simple use of exam package :



    documentclass{exam}
    %printanswers
    begin{document}

    section{Differential Equations}
    begin{questions}
    question ... Short question here ... answerline[Short answer]
    question ... Question here ...

    begin{solution}[.2in]
    ... Answer here ...
    end{solution}

    question Long descriptive question about everything

    begin{solutionorlines}[2in]
    Long descriptive answer is a long descriptive answer that is a long descriptive answer that is along descriptive answer that is along descriptive answer that is along descriptive answer that is a lie.
    end{solutionorlines}

    question Draw an arrow showing north direction.

    begin{solutionorbox}[2in]
    $uparrow$
    end{solutionorbox}

    end{questions}

    ifprintanswers
    Stuff to appear only when answers textbf{are} being printed.
    else
    Stuff to appear only when answers textbf{are not} being printed.
    fi

    end{document}


    Commenting and uncommenting printanswers yields in one of two following:



    1)



    Only questions



    2)



    Questions with answers



    I don't see any lack of functionality compared to your example.






    share|improve this answer



















    • 1




      At my department, we took exam.cls as a foundation for our own examination class, so that the cover page would always look the same, and it works very well. It is very flexible.
      – Benjamin McKay
      Oct 21 '13 at 15:20













    up vote
    14
    down vote



    accepted







    up vote
    14
    down vote



    accepted






    Simple use of exam package :



    documentclass{exam}
    %printanswers
    begin{document}

    section{Differential Equations}
    begin{questions}
    question ... Short question here ... answerline[Short answer]
    question ... Question here ...

    begin{solution}[.2in]
    ... Answer here ...
    end{solution}

    question Long descriptive question about everything

    begin{solutionorlines}[2in]
    Long descriptive answer is a long descriptive answer that is a long descriptive answer that is along descriptive answer that is along descriptive answer that is along descriptive answer that is a lie.
    end{solutionorlines}

    question Draw an arrow showing north direction.

    begin{solutionorbox}[2in]
    $uparrow$
    end{solutionorbox}

    end{questions}

    ifprintanswers
    Stuff to appear only when answers textbf{are} being printed.
    else
    Stuff to appear only when answers textbf{are not} being printed.
    fi

    end{document}


    Commenting and uncommenting printanswers yields in one of two following:



    1)



    Only questions



    2)



    Questions with answers



    I don't see any lack of functionality compared to your example.






    share|improve this answer














    Simple use of exam package :



    documentclass{exam}
    %printanswers
    begin{document}

    section{Differential Equations}
    begin{questions}
    question ... Short question here ... answerline[Short answer]
    question ... Question here ...

    begin{solution}[.2in]
    ... Answer here ...
    end{solution}

    question Long descriptive question about everything

    begin{solutionorlines}[2in]
    Long descriptive answer is a long descriptive answer that is a long descriptive answer that is along descriptive answer that is along descriptive answer that is along descriptive answer that is a lie.
    end{solutionorlines}

    question Draw an arrow showing north direction.

    begin{solutionorbox}[2in]
    $uparrow$
    end{solutionorbox}

    end{questions}

    ifprintanswers
    Stuff to appear only when answers textbf{are} being printed.
    else
    Stuff to appear only when answers textbf{are not} being printed.
    fi

    end{document}


    Commenting and uncommenting printanswers yields in one of two following:



    1)



    Only questions



    2)



    Questions with answers



    I don't see any lack of functionality compared to your example.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jan 10 '14 at 8:59

























    answered Oct 21 '13 at 14:56









    Vairis

    641720




    641720








    • 1




      At my department, we took exam.cls as a foundation for our own examination class, so that the cover page would always look the same, and it works very well. It is very flexible.
      – Benjamin McKay
      Oct 21 '13 at 15:20














    • 1




      At my department, we took exam.cls as a foundation for our own examination class, so that the cover page would always look the same, and it works very well. It is very flexible.
      – Benjamin McKay
      Oct 21 '13 at 15:20








    1




    1




    At my department, we took exam.cls as a foundation for our own examination class, so that the cover page would always look the same, and it works very well. It is very flexible.
    – Benjamin McKay
    Oct 21 '13 at 15:20




    At my department, we took exam.cls as a foundation for our own examination class, so that the cover page would always look the same, and it works very well. It is very flexible.
    – Benjamin McKay
    Oct 21 '13 at 15:20










    up vote
    0
    down vote













    I am using begin{questions}...end{questions}. Output is like Q.1) Q.2) ...
    I just want it like 1) 2) ... How to modify my code? Since I want to droppoints I need to use this question segment itself. So someone help me.





    share








    New contributor




    Thasheela is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      up vote
      0
      down vote













      I am using begin{questions}...end{questions}. Output is like Q.1) Q.2) ...
      I just want it like 1) 2) ... How to modify my code? Since I want to droppoints I need to use this question segment itself. So someone help me.





      share








      New contributor




      Thasheela is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















        up vote
        0
        down vote










        up vote
        0
        down vote









        I am using begin{questions}...end{questions}. Output is like Q.1) Q.2) ...
        I just want it like 1) 2) ... How to modify my code? Since I want to droppoints I need to use this question segment itself. So someone help me.





        share








        New contributor




        Thasheela is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        I am using begin{questions}...end{questions}. Output is like Q.1) Q.2) ...
        I just want it like 1) 2) ... How to modify my code? Since I want to droppoints I need to use this question segment itself. So someone help me.






        share








        New contributor




        Thasheela is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.








        share


        share






        New contributor




        Thasheela is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        answered 8 mins ago









        Thasheela

        1




        1




        New contributor




        Thasheela is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.





        New contributor





        Thasheela is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.






        Thasheela is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f108316%2fhow-to-define-environments-for-questions-and-answers%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            サソリ

            広島県道265号伴広島線

            Accessing regular linux commands in Huawei's Dopra Linux