MathGroup Archive 2012

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: exercises: suppress printing of answers

  • To: mathgroup at
  • Subject: [mg124619] Re: exercises: suppress printing of answers
  • From: Alexei Boulbitch <Alexei.Boulbitch at>
  • Date: Fri, 27 Jan 2012 06:07:42 -0500 (EST)
  • Delivered-to:

Thanks for all the interesting suggestions.

More than one was usable, but I'd still

be interested in learning how to programmatically

close all subsections labelled with a specific tag.



Hi, Alain,

What about this?

Button["Get answer: Nr.1", CreateDocument[Column[{



     Style["This is some text with the answer to problem 1", 14],


    TextCell[Style["containing display formulas and plain text:", 14],



     Style["\!\(\*SubsuperscriptBox[\(\[Integral]\), \(a\), \(b\)]\)x\

\[DifferentialD]x=\!\(\*FractionBox[\(1\), \

\(2\)]\)(\!\(\*SuperscriptBox[\(b\), \

\(2\)]\)-\!\(\*SuperscriptBox[\(a\), \(2\)]\))", Italic, 22],


    TextCell[Style["This is some more text ", 14], "Output"],


     Style["\!\(\*SuperscriptBox[\(x\), \

\(2\)]\)+\!\(\*SuperscriptBox[\(y\), \

\(2\)]\)=\!\(\*SuperscriptBox[\(z\), \(2\)]\)", Italic, 22], "Output"],

    Button[Style["Close the window", 16, Blue], NotebookClose[]]

    }], WindowTitle -> "Problem 1: the answer",

  WindowSize -> {500, 500}]]

In the end of your notebook with the problems make a Section "Answers". Copy-paste the above code into any input cell of this Section. Enter the text of the answer you wish into the Text cells and any formula into the Expression cells. Add more Text and Expression cells, if necessary. Mark the cell with this code as the "Initialization cell" (Menu/Cell/Cell Properties/Initialization cell). Execute this cell. A button entitled "Get answer : Nr.1" will appear.  Copy-paste this button into the end of the text of your problem. Collapse the whole Section "Answers" around the Section cell, or close the cells with the answers (Menu/Cell/Cell Properties and uncheck "Open"), or the both. Save the notebook. Done. You will only need to execute any operation as soon as the notebook is first open. I use for these purposes the function DateString[] that I place in the very beginning of each notebook. The answers will appear only upon pressing the corresponding button. They will never be se
n in the pdf document.

Have fun, Alexei

Alexei BOULBITCH, Dr., habil.


ZAE Weiergewan,

11, rue Edmond Reuter,

L-5326 Contern, LUXEMBOURG

Office phone :  +352-2454-2566

Office fax:       +352-2454-3566

mobile phone:  +49 151 52 40 66 44

e-mail: alexei.boulbitch at<mailto:alexei.boulbitch at>

  • Prev by Date: Re: Probability
  • Next by Date: Re: Mathematica 8 + OS X + McAfee = trouble; help?
  • Previous by thread: Re: exercises: suppress printing of answers
  • Next by thread: Error(?) in FormatValues[MakeExpression]