Presentations with Mathematica

Tools, tips, and tricks to improve your Mathematica presentations

Paul Wellin

Wolfram Research

wellin@wolfram.com

CellPrint[TextCell[
Row[{
Dynamic[Style[DateString[],FontFamily->"Helvetica"],UpdateInterval->1],
Style["  (GMT: "],$TimeZone,")"}],"Subsubsection",ShowStringCharacters->False,CellMargins->{{60,Inherited},{Inherited,Inherited}}]]

(GMT: -5.`)

Overview

In this brief tutorial, we will provide concrete examples to help you create quality presentations using Mathematica notebooks. Specifically, we will focus on the following:

Inline formulas

Auto-numbering

Interactive elements: hyperlinks, buttons, and other dynamic elements

Stylesheets: separating document formatting from content

Slideshows

Tips and tricks

Inline Formulas

You can include typeset input in text cells.

The result of (∑_(k=1)^∞)(1/(k^4)) is ((π^4)/90).

Use Ctrl[9] to start an inline cell and Ctrl[0] to end an inline cell. (You can also use the corresponding menu commands in the Typesetting submenu of the Insert menu.)

Alternately, enter Mathematica input in your text cell and then use Evaluate in Place from the Evaluate menu. For example, ∫(1/(1-(x^3)))dx=□.

Auto-Numbered Objects

To create your own auto-numbering objects such as sections or equations, select Automatic Numbering from the Insert menu. Be sure to select the correct counter from the pulldown menu.

You can reset counters by setting the cell option, CounterAssignments; e.g., CounterAssignments->{{"Section", 8}}. This is most easily done using the Option Inspector, although experienced users often just unformat the relevant cell and insert the option manually.

. Introduction

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Pellentesque enim dolor, euismod sit amet, rutrum nec, fermentum id, risus. Mauris auctor nunc ac nisl. Nunc non turpis a dolor porta tristique. Nam accumsan massa scelerisque sapien.

Plot[Sinc[x],{x,-2π,2π}]

. Main results

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Pellentesque enim dolor, euismod sit amet, rutrum nec, fermentum id, risus. Mauris auctor nunc ac nisl. Nunc non turpis a dolor porta tristique. Nam accumsan massa scelerisque sapien.

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Pellentesque enim dolor, euismod sit amet, rutrum nec, fermentum id, risus. Mauris auctor nunc ac nisl. Nunc non turpis a dolor porta tristique. Nam accumsan massa scelerisque sapien.

. Conclusion

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Pellentesque enim dolor, euismod sit amet, rutrum nec, fermentum id, risus. Mauris auctor nunc ac nisl. Nunc non turpis a dolor porta tristique. Nam accumsan massa scelerisque sapien.

Hyperlinks

Mathematica provides a mechanism for linking to other documents and objects within a document through the use of hyperlinks. For example, clicking this hyperlink to Wolfram Research will cause your web browser to open to http://www.wolfram.com.

There are several ways to create hyperlinks in your notebooks. Perhaps the simplest is to use Hyperlink.

For example, this creates a hyperlink to www.wolfram.com.

Hyperlink["http://www.wolfram.com"]

You can add a label that will display instead of the explicit URL by giving Hyperlink two arguments.

Hyperlink["Wolfram Research","http://www.wolfram.com"]

The label of your button or hyperlink need not be text. Really, it can be anything!

Hyperlink[Plot[Sinc[x],{x,-2π,2π}],"http://demonstrations.wolfram.com"]

Sometimes you will find yourself needing to create a hyperlink in the middle of a text cell similar to the Wolfram Research link above. To do this:

Highlight the word or phrase you wish to turn into a hyperlink.

From the Insert menu, select Hyperlink (alternately, right-click).

In the Create Hyperlink dialog box that appears, type in (or paste from your browser) the URL; click OK.

Note that you could also link to other Mathematica notebooks by browsing to a specific notebook on your computer from the Create Hyperlink dialog.

Links within a notebook

Suppose you have some references at the end of your notebook that you would like to link to.

Create a cell tag for the target

Create a hyperlink where you wish to jump to your target

In the hyperlink dialog, in the section "Destination within notebook", click the "Cells with the tag" radiobutton and select your cell tag. Click OK.

After clicking your link and going to its target, you can go back by using the "HyperlinkGoBack" token. On Windows, the key event is Alt+Left; on a Mac, it is ⌘+[ or ⌘-⌥+Left.

CreateDocument[
Cell[Import[FileNameJoin[{$InstallationDirectory,"SystemFiles","FrontEnd","TextResources","Windows","KeyEventTranslations.tr"}],"Text"],"Input"]]

Linking to the Documentation Center

Linking to items in the Documentation Center requires creating a hyperlink of a certain style. It is easiest to simply highlight a symbol and right-click to bring up the context menu with Make Hyperlink. Type in paclet:ref/Plot say and click OK.

Buttons

Buttons provide an alternate interface to Mathematica. Instead of typing in a function name together with its arguments and using proper syntax and then pressing ⇧-⌤ to evaluate, you simply click a button and an action happens automatically.

For example, this button displays the current date when pressed.

Button["Today's date",Print[DateString[]]]

Alternatively, you could create a PasteButton that will paste the expression when the button is clicked.

PasteButton["Today's date",DateString[]]

Here is a button to create a new notebook in the front end.

Button["New Document",
CreateDocument[{
Cell["Demo Notebook","Title"],
Cell["This is some sample text", "Text"]
},Magnification->1.5,Background->LightYellow]]

Another kind of button object creates popup windows. These could be useful if you want someone to click a button and have a small window appear with a message.

This creates a button with a help message.

PopupWindow["Help","Make sure to enclose function arguments with square brackets, not parentheses."]

Hints/Solutions buttons

Open sample notebook

Create Solution Button Palette

Documentation link buttons

Here is a basic button that you can use as a template for creating links to the symbol pages.

Button["Make Reference Link",
tgtStr=NotebookRead[InputNotebook[]];NotebookWrite[InputNotebook[],Cell[BoxData[ButtonBox[tgtStr,BaseStyle->"Link",ButtonData->StringJoin["paclet:ref/",tgtStr]]],"InlineFormula"]]]

Try creating a link to the Plot function or Integrate by selecting/highlighting the function name in this text cell and then clicking the button.

The following button could be used to create links to guide pages.

Button["Make Guide Page Link",
tgtStr=NotebookRead[InputNotebook[]];NotebookWrite[InputNotebook[],ButtonBox[tgtStr,BaseStyle->"Link",ButtonData->StringJoin["paclet:guide/",tgtStr]]]]

Try creating a link to the guide page for InteractiveManipulation.

Palettes

Here we create a palette consisting of a grid of buttons that paste in various Greek characters.

CreatePalette[Grid[{
{PasteButton[α],PasteButton[β],PasteButton[γ]},
{PasteButton[Α],PasteButton[Β],PasteButton[Γ]}
}],Magnification->2.0]

Example: notebook opener from directory

Get names of all notebooks that meet some criteria, in this case, all WEG seminar notebooks in a certain directory.

lis=FileNames["S0*.nb"|"S1*.nb"|"S2*.nb",FileNameJoin[{$BaseDirectory,"Applications"}],2];
MapIndexed[Flatten@{#1,#2}&,lis]

Pick only those we want in the palette.

files=Map[FileNameDrop[#,4]&,Part[lis,{1,3,4,5,6,7,8,9,11,13,14,15,16,18,19,21}]];
TableForm[files]

Make labels for buttons.

labels=Map[FileNameTake[#,1]&,files]

Create formatted palette.

CreatePalette[Grid[
MapThread[{Button[Style[#1,FontSize->11,FontColor->GrayLevel[.9]],NotebookOpen[FileNameJoin[{$BaseDirectory,"Applications",#2}]],Appearance->"Palette",Alignment->Center,Background-> RGBColor[.2,.2,.2],ImageMargins->1]}&,{labels,files}],
Spacings->{1,.15},Background->RGBColor[.4,.4,.6]],Magnification->1.5,WindowTitle->"Open WEG Seminars"]

Slideshows

Tips

Switching to full screen

Pagedown

Docked cells

Spacer cells at bottom

Tips & Tricks

Hiding code

pts={{1,5},{2,0},{3,2},{4,5},{5,4},{6,4},{7,3},{8,1}};
Manipulate[
Show[Graphics[{
{Point[p],Green,Line[p]}}],
ParametricPlot[BSplineFunction[p][t],{t,0,1}]],
{{p,pts},Locator},
Initialization:>{pts={{1,5},{2,3},{3,2},{4,5},{5,4},{6,4},{7,3}}}]

Using the ShowGroupOpener icon

Useful for hiding material and then exposing when you are ready. To create:

either copy existing cell that uses it and then change its style, or

open the Option Inspector (⇧-Ctrl+O) and set the option ShowGroupOpener->True

set ShowGroupOpener->True in your stylesheet to make it apply to all cells of a certain stye

Using initialization cells and groups

Needs["StatisticalPlots`"]

ParetoPlot[RandomInteger[4,{16}]]

SaveDefinitions

Here is some code to create a hypocycloid curve and animate it inside a Manipulate.

hypocycloid[{a_,b_},θ_]:={(a-b)Cos[θ]+b Cos[θ ((a-b)/b)],(a-b)Sin[θ]-b Sin[θ ((a-b)/b)]}

Manipulate[
Show[
ParametricPlot[hypocycloid[{1,b/a},t],{t,-0.001,i},PlotStyle->Red,Axes->None],
Graphics[{
{Blue,Circle[{0,0},1]},
{Red,PointSize[.025],Point[hypocycloid[{1,b/a},i]]},
{PointSize[.015],Point[RotationMatrix[i-π/2].{0,1-b/a}]},
{Circle[RotationMatrix[i-π/2].{0,1-b/a},b/a]},
{Thickness[.0065],Line[{RotationMatrix[i-π/2].{0,1-b/a},Hypocycloid[{1,b/a},i]}]}
}],PlotRange->All],
{i,0+.001,12π,.1},{a,{3,4,5,6,7,8},Setter},{b,{1,2,3,4,5},Setter}]

If you were to start a new kernel session, the correct output above would not appear as the front end does not know about the definition for hypocycloid. By setting the option SaveDefinitions, your definitions will be saved with the output.

Hypocycloid[{a_,b_},θ_]:={(a-b)Cos[θ]+b Cos[θ ((a-b)/b)],(a-b)Sin[θ]-b Sin[θ ((a-b)/b)]}

Manipulate[
Show[
ParametricPlot[Hypocycloid[{1,b/a},t],{t,-0.001,i},PlotStyle->Red,Axes->None],
Graphics[{
{Blue,Circle[{0,0},1]},
{Red,PointSize[.025],Point[Hypocycloid[{1,b/a},i]]},
{PointSize[.015],Point[RotationMatrix[i-π/2].{0,1-b/a}]},
{Circle[RotationMatrix[i-π/2].{0,1-b/a},b/a]},
{Thickness[.0065],Line[{RotationMatrix[i-π/2].{0,1-b/a},Hypocycloid[{1,b/a},i]}]}
}],PlotRange->All],
{i,0+.001,12π,.1},{a,{3,4,5,6,7,8},Setter},{b,{1,2,3,4,5},Setter},
SaveDefinitions->True]

Alternatively, you could use the Initialization option but this would require you to evaluate the Manipulate. This construct simply makes these definitions evaluate before displaying the output of Manipulate.

Manipulate[
Show[
ParametricPlot[Hypocycloid[{1,b/a},t],{t,-0.001,i},PlotStyle->Red,Axes->None],
Graphics[{
{Blue,Circle[{0,0},1]},
{Red,PointSize[.025],Point[Hypocycloid[{1,b/a},i]]},
{PointSize[.015],Point[RotationMatrix[i-π/2].{0,1-b/a}]},
{Circle[RotationMatrix[i-π/2].{0,1-b/a},b/a]},
{Thickness[.0065],Line[{RotationMatrix[i-π/2].{0,1-b/a},Hypocycloid[{1,b/a},i]}]}
}],PlotRange->All],
{i,0+.001,12π,.1},{a,{3,4,5,6,7,8},Setter},{b,{1,2,3,4,5},Setter},
Initialization:>{
Hypocycloid[{a_,b_},θ_]:={(a-b)Cos[θ]+b Cos[θ ((a-b)/b)],(a-b)Sin[θ]-b Sin[θ ((a-b)/b)]}
}]

Embedding stylesheets

The problem: send someone a notebook that has a nonstandard or a modified stylesheet.

Sample notebook

Resources

Other resources are available:

Tutorial: Notebooks as Documents

How to | Create a Slide Show

Screencasts: Notebooks and Documents