Power-using the new front end

Getting the most from your shiny new CD

John Fultz

Wolfram Research, Inc.

Things I'm not going to discuss

Print[Style[Grid[{
{Row[{"• Just how does ",Style[Manipulate,"Input","StandardForm"]," work?"}], "Stick around...", "Lou D’Andria"},
{"• Let me edit graphics!", "10am", "Chris Carlson, Chris Hill"},
{"• Demos! Demos! Demos!", "11am", "Jeff Bryant"}
}, Dividers->True, Spacings->{Automatic, {1.2, {.6}, 1.2}}],"DefinitionBox3Col", FontFamily->"Times",20]]

Things I'm not going to discuss

Print[Style[Grid[{
{Row[{"• Just how does ",Style[Manipulate,"Input","StandardForm"]," work?"}], "Stick around...", "Lou D’Andria"},
{"• Let me edit graphics!", "10am", "Chris Carlson, Chris Hill"},
{"• Demos! Demos! Demos!", "11am", "Jeff Bryant"},
{"• Friday the 13th"}
}, Dividers->True, Spacings->{Automatic, {1.2, {.6}, 1.2}}],"DefinitionBox3Col", FontFamily->"Times",20]]

A few themes

Writing code

Managing documents

Improving the interface

Your suggestions

Writing code — Syntax coloring

A few typical examples

System variables

Plo

Plot

String and comments

f["Mathematica 6" (* the discussion topic *)]

Local variables

f[x_]:=x

Module[{x}, x]

Plot[x, {x, 0, 1}]

Table[(x^2)y, {x, 0, 1}]

And even a few tricky scoping issues, which Why the Coloring might help to explain

expr /. {f[x_]:>x, g[x_]->x}

Module[{x=1}, Module[{x=2}, x]; x]

Writing code — Syntax coloring

Seeking out bad code, or staying out the red

Sometimes code is just wrong

Plot[Sin[x], {x, 0, 2π}, Plotrange->All]

Log[180,000, 3]

Writing code — Syntax coloring

Seeking out bad code, or staying out the red

Sometimes code is just wrong...

Plot[Sin[x], {x, 0, 2π}, Plotrange->All]

Log[180,000, 3]

...or just appears wrong...

If[x=1,x++]

Plot[Sin[x], {x, 0, 2π}];

Table[Dynamic[var], {var, 10}]

...which is why you can tweak it in the Preferences dialog.

Writing code — Syntax coloring

What if I could color anything I wanted to?

Priority #1

min = Min[data];

data = {5, 3, 9};
min = Min[data];

line=Line[{{0,0},{1,1}}];

log = Log[x];

Writing code — Syntax coloring

More than static syntax analysis – getting the kernel involved

Note that syntax coloring is far more sophisticated than just checking a database of syntaxes. We know...

...when a function is defined

myGoodFunction[x_]:=x+1

myGoodFunction[5]

mygoodFunction[5]

...when there's a shadowing conflict

{Global`whichContext, System`whichContext, whichContext};

Remove[Global`whichContext]

...and even what context a symbol is in

SetOptions[$FrontEnd, AutoStyleOptions->{"SymbolContextStyles"->{"Context1`"->{Green}, "Context2`"->{24}}}]

{Context1`purpleSymbol, Context2`bigSymbol};

$ContextPath=Join[$ContextPath, {"Context1`", "Context2`"}];

{purpleSymbol, bigSymbol}

Writing code — Suppressing outputs and errors

Range[(10^(5]))

Dynamic[{maybeGood, maybeBad}]

maybeGood:=1
maybeBad:=1/0

maybeBad:=0

Graphics[{Line[{{0,0},{1,1}}], Line[{{0.3,0.7}, {0.5, a}}]}, AspectRatio->b]

Writing code — Better alternatives to Input[]

Simple message and choice dialogs

Module[{x=True},While[x, Pause[3];
x = ChoiceDialog["Keep waiting?", {"Yes"->True, "No"->False}]];
MessageDialog["Finally finished!"]
];

Input[] is no longer limited to one-dimensional text

Input[]

More constructs available for you to roll your own

Writing code — Editing packages

How it used to be done

Writing code — Editing packages

A small improvement — The Code style

Named style that's an initialization cell

Replaces SmallText style as Alt+8/Command+8

Acts more like a plain text editor

Writing code — Editing packages

A larger improvement — the package editor

Managing documents — Stylesheets

How do you modify stylesheets?

Now we provide an interface which makes these tasks easier

Managing documents — Stylesheets

Stylesheets now fully implement inheritance

Forward compatibility will now rarely be an issue

More powerful tools are in the pipeline

Managing documents — Provenance

Provenance — determining the history of a document

Mathematica 6 has the beginnings of a provenance feature

Managing documents — Working with other file types

Document-level formats...right from the Open/Save dialog

Direct FE support for many image formats, too

And super-easy to add more

Example

MathLink`CallFrontEnd[AddFileBrowserFilterPacket["Open",
{Item["ZIP Files",
(NotebookClose[#2];NotebookPut/@Import[#1, {"Files",Import[#1]}])&,
"zip","*.zip",
MenuEvaluator->Automatic]}]]

#1 - filename argument
#2 - notebook object to create, save, or insert into
See plenty of examples in CommonFrontEndInit.tr in the Mathematica layout

Improving the interface — Copy and paste

Copy As ▶ Input Text — What you evaluate is what you get

Copy As ▶ Plain Text — What you see is what you get

Examples

({{1, 2}, {3, 4}})

Interpretation[this,that]

Manipulate[Plot[Sin[a x], {x, 0, 2π}], {a, 1, 5}]

Improving the interface — Docked cells

Implement your own toolbars...

SetOptions[EvaluationNotebook[],
DockedCells->
Cell[BoxData[ToBoxes[
Row[{
PopupMenu[Dynamic[CurrentValue[ButtonNotebook[],Magnification]],
{1.->"100%",1.4->"140%", 2.1->"210%", Inherited->"Default"}], Button["Close toolbar", SetOptions[ButtonNotebook[],DockedCells->Inherited]]
}]
]], "DockedCell"]]

...or banners or anything else you want...

SetOptions[EvaluationNotebook[],
DockedCells->Cell["This presentation brought to you by Wolfram Research", "Subtitle","DockedCell"]]

SetOptions[EvaluationNotebook[], DockedCells->Inherited]

...just like what you've seen this entire talk.

Improving the interface — Cell groups

Reverse-closed groups

Manipulate[Expand[(((a+b))^c)], {c, 1, 50, 1}]

A few things I didn't mention

The debugger

Palettes upgraded with version 6 capabilities

Notebooks and cell groups which evaluate in guaranteed-unique contexts

Your suggestions

????