11.07.2015 Views

webMathematica™ Wolfram - Wolfram Research

webMathematica™ Wolfram - Wolfram Research

webMathematica™ Wolfram - Wolfram Research

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

122 webMathematica User GuideOne format that is very easy to generate is Mathematica notebooks, and there are a number ofwebMathematica examples that work by returning Mathematica notebooks to the client. Oneexample is Content.jsp. Using Mathematica notebooks has the advantage that the documentcan be worked on further after reaching the client. A disadvantage is that it requires the clientto have access to an application that can read notebooks, such as Mathematica or MathematicaPlayer (http://www.wolfram.com/products/player/). Another alternative is to use PDF. This hasthe advantage that the vast majority of clients are set up to render PDF.Mathematica can now automatically convert notebook documents into PDF format. This sectionwill explore how to generate PDF documents from webMathematica.Generating a Mathematica NotebookA common way to do this involves using Mathematica commands for generating notebooks. Asample function is shown below (taken from the source used by Content.jsp).MakeNotebook[] :=Developer`UseFrontEnd[Module[ {nb, nbobj},nb = NotebookCreate[] ;NotebookWrite[ nb, Cell[ "A Dynamically Created Notebook","Title"]] ;NotebookWrite[ nb,Cell[ "Converted to " $$button, "Subtitle"]] ;NotebookWrite[ nb, Cell[ "The date is " ToString[ Date[]],"Text"]] ;nbobj = NotebookGet[ nb] ;NotebookClose[ nb] ;nbobj]]This sample shows how a notebook object is created with NotebookCreate, and then how thecontent is added with NotebookWrite. When the notebook is complete, a Mathematica expressionholding the notebook is obtained with NotebookGet and this is returned. In a real lifesituation, the document could contain graphics, more text, and some computations. The Mathematicadocumentation has much more information on the commands for generating notebooks.A major advantage of working with Mathematica notebooks like this is that they will take careof details such as font selection, graphics, and mathematics without the author having to bevery involved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!