Writing Mathematics in Notebooks

MathNotebook Tutorial
Abstract.
How to write a mathematics paper in a Wolfram notebook: journal stylesheets, live referencing, and conversion between LaTeX source and native typeset math. Whether the mathematics is written as LaTeX or as built-in typeset math is your choice throughout — the palette only moves a selection from one to the other.
1
.

Getting Started

◼
  • After installing the paclet, restart the front end so that Palettes → MathNotebook and the stylesheet menu appear.
  • ◼
  • Apply a stylesheet first — this is the step to do before anything else. Document view → Apply stylesheet → PlainArticle on the palette, or Format → Stylesheet → MathNotebook; Default in that menu takes it back.
  • ◼
  • It is not optional. The twelve block environments are declared by the stylesheet, so on a notebook still using Default a Definition cell gets no name, no number and no indent, and a cross-reference to it renders 2.0 — the section counter increments and the theorem counter never does. That reads as a broken paclet and is a missing step.
  • ◼
  • PlainArticle is the one to start from: the notebook’s own typography with the paper structure added. The five journal templates below are for a submission, and an imported .tex picks its own sheet from its \documentclass.
  • ◼
  • Then Blocks → Front matter puts empty Title, Author and Abstract cells at the top of the document and leaves the cursor in the title — in that order, which is the order \maketitle needs them in. It is one of only two buttons that ignore the selection, the other being Reference. Write the body in Section and Text cells.
  • ◼
  • Every palette button acts on the notebook you were last editing, and on its current selection.
  • ◼
  • The journal stylesheets are light-only; applying one from the palette’s Document view group also sets the notebook to light mode, so printed and exported output matches the screen. Applying a sheet clears the two size overrides below it, the new sheet replacing them.
  • ◼
  • Update from cloud, in the palette's Setup group, asks the Wolfram Cloud which version is published and installs it only when it is newer than the one you have — so checking costs a line of text, not a download. It then rebuilds the front end menus and reopens the palette, which makes the new palette, stylesheets and tutorial live immediately.
  • ◼
  • It always says which of three things happened: updated, with the old and new version numbers; already current; or the cloud could not be reached. Kernel code from the new version loads after Evaluation → Quit Kernel — the button will not quit the kernel out from under your session.
  • ◼
  • A copy loaded from a development directory shadows anything installed from the cloud, so the button reports that and downloads nothing. The same check from code: UpdateMathNotebook[].
  • 2
    .

    Referencing

    ◼
  • Select a numbered cell — an equation, a theorem, a section, a numbered item — and press Copy reference, then paste into your text.
  • ◼
  • The pasted reference is a live button showing the current number, so reordering cells renumbers every reference to them.
  • ◼
  • Clicking a reference jumps to its target; ↑ Go back returns to where you clicked from.
  • ◼
  • Reference, in the Blocks group, adds a bibliography entry: it asks for a citation key and puts a tagged, labelled entry at the end of the bibliography — starting one, under a References heading, if the notebook has none yet. It goes there rather than at the cursor, unlike every other button in that group.
  • ◼
  • Insert citation then offers everything the notebook has tagged, literature entries and numbered blocks in two lists, with a filter field; picking one inserts a red bracketed link to it. Type a key the notebook does not have and it cites that instead, so a citation can be written before its target exists. To name a cell yourself, use Cell → Cell Tags.
  • ◼
  • A citation to a numbered environment shows its number instead of its tag: tag a theorem, cite it, and the citation reads Theorem 1.1 — renumbering itself when cells move, in the exported PDF as on screen. A tag no cell carries yet keeps its brackets, so a citation written before its target is still readable.
  • ◼
  • Tagging a Reference cell also labels it: the entry shows its tag in brackets in the margin, which is exactly what a citation to it reads, so the bibliography and the body agree without your typing either.
  • ◼
  • The Cell Tags dialog sets the tag and not the label, so after tagging an entry that way press Refresh labels — it labels every entry of the notebook at once, and clears the label of an entry whose tag you removed. From code, LabelReferences[].
  • ◼
  • Sort bibliography reorders the entries: by first citation, which is what BibTeX’s unsrt prints, by key, or by the entry text. Report uncited sorts nothing and answers the question a sort cannot — which entries nothing cites, and which citations point at no cell. Where the entries came from a .bib, the order shown is the notebook’s alone: that file and its style decide what the compiled paper prints.
  • ◼
  • The theorem below and the equation after it are practice targets: select either one and copy a reference to it.
  • Theorem
    2
    .
    1
    .
    The exponential map is surjective onto the unit circle.
    π
    e
    +1=0
    (
    1
    )
    3
    .

    Stylesheets

    ◼
  • Five templates: AMSArticle (amsart, Palatino), ArXivArticle (article, Latin Modern), SpringerJournal and RevTeXAPS (Times), and ComplexSystems, which is the journal's own page rather than a resemblance of one: a 306 pt column on a 432 × 648 sheet, with display mathematics flush left.
  • ◼
  • All five define the same style names, so switching between them is instant and changes nothing but the typography.
  • ◼
  • PlainArticle is a fifth sheet and not a template: it is the notebook's own typography with the paper structure added, and it is what an imported paper opens on when its \documentclass names no journal above.
  • ◼
  • Theorem, Lemma, Proposition, Corollary, Conjecture, Claim, Definition, Example, Construction, Remark, Question, and Observation share a single counter that resets at each section, exactly as in LaTeX; numbered equations count continuously through the document. ComplexSystems is the exception its journal makes: there each of the twelve counts on its own, with no section number in front of it.
  • ◼
  • Insert environments from the palette's Insert environment menu, or with the Proof, Equation, and Equation (n) buttons.
  • ◼
  • A block is not confined to one cell. Put an equation inside a definition and press Continue block to carry the prose on: the new cell repeats the block's own style, showing no second name and taking no second number, so it lines up with the prose above it instead of at the plain text margin 64 pt to its left. A Proof carried on this way keeps its QED square at the end, where it belongs.
  • ◼
  • Latin Modern and TeX Gyre are LaTeX fonts, not system fonts: press Install LaTeX fonts once to copy them out of a local TeX distribution (tug.org/texlive) into your user font directory, then restart the front end. They are installed for the whole machine, not inside Mathematica, so any application can use them.
  • 4
    .

    Reading and Writing Comfortably

    ◼
  • Each palette group folds: click its opener or its name to collapse it, so only the buttons you are using take up room. The palette remembers which groups are open across front end restarts.
  • ◼
  • The Document view group holds two sliders and a reset. Like every other palette control they act on the notebook you were last editing, so leave the palette open beside your paper and drag while you read it.
  • ◼
  • Text size sets the size of Text and scales the whole document with it — the title, the headings, the abstract, the theorem environments, proofs, bibliography entries, both kinds of list, and the mathematics: displayed equations, their numbers, inline mathematics and MaTeX cells alike — so the page keeps its proportions instead of one style growing alone.
  • ◼
  • Math size sizes the mathematics on its own, and only if you touch it. Leave it where it is and mathematics follows Text size; set it and it overrides that, which is what to reach for when a journal's equations want to be larger or smaller than the sheet makes them relative to the prose.
  • ◼
  • Both set real font sizes, so they reach the exported PDF. Format → Magnification is a different thing entirely — it zooms the screen and never changes print.
  • ◼
  • The settings are stored in the notebook itself, so they survive saving and reopening and travel with the file to a coauthor.
  • ◼
  • Reset view returns the notebook to its stylesheet’s own sizes; applying a stylesheet clears the overrides too, since the new sheet replaces them. The document keeps a private stylesheet of its own afterwards, which changes nothing you can see — every style is written at the sheet’s own size — but does mean Format → Stylesheet no longer shows the sheet ticked. That is deliberate: assigning a stylesheet by name onto a document that carries size overrides can leave the front end unable to print, so the paclet never does it.
  • ◼
  • MaTeX cells are images and cannot inherit a style, so either slider re-renders each of them through LaTeX at the new size, from the TeX the cell stores.
  • ◼
  • The same from code, on any notebook: SetDocumentFontSize[nb, 16], SetMathFontSize[nb, 16] — each takes Automatic to drop its own override — and ResetDocumentView[nb] to drop all of them. They work on a notebook still using Default too.
  • 5
    .

    Math Input Shortcuts

    ◼
  • Ctrl+9 inline math in text, Ctrl+0 exits.
  • ◼
  • Ctrl+/ fraction, Ctrl+2 square root.
  • ◼
  • Ctrl+^ superscript, Ctrl+_ subscript, Ctrl+% switches between them.
  • ◼
  • esc name esc enters symbols: a → α, el → ∈, -> → .
  • ◼
  • Cmd+Shift+E shows the cell expression (Ctrl+Shift+E on Windows).
  • 6
    .

    Working with Cells

    ◼
  • Click a cell bracket to select the cell; drag across brackets to select several; Delete removes them.
  • ◼
  • Ctrl+. extends the selection outward; repeat to reach the whole cell.
  • ◼
  • Cmd+1/4/5/7/9 restyle a cell: Title, Section, Subsection, Text, Input.
  • ◼
  • Cmd+9 on a fresh cell inserts an Input cell — the one to reach for when you replace an imported figure's Import with the code that draws it.
  • ◼
  • Cmd+Shift+D divides a cell at the cursor; Cmd+Shift+M merges selected cells.
  • ◼
  • Ctrl+G groups selected cells; Ctrl+Shift+G ungroups.
  • ◼
  • Double-click a group bracket to close or open the group; Cmd+Shift+{ and Cmd+Shift+} open and close all subgroups.
  • ◼
  • Double-click a closed group's remaining bracket to reopen it; use Cell → Delete All Output before sharing a notebook.
  • 7
    .

    LaTeX Conversion

    ◼
  • The Import & Export group is the route for a paper; the Selection group acts on the cells you have selected. Hover any button for a sentence on what it does.
  • ◼
  • Import .tex file… reads a whole paper into a new notebook: \section and the theorem-like environments the preamble declares become cells of the matching style, mathematics is typeset, \label becomes a cell tag, and \ref and \cite become live links. Anything it does not convert is carried verbatim, so what it cannot read it also does not damage.
  • ◼
  • The front matter comes with it: \title, \author and \date become Title, Author and Date cells you can edit — the edit reaches the .tex — and an abstract becomes Abstract cells, headed once however many paragraphs it runs to. \maketitle has no content of its own, so it stays as text beside \sloppy and \tableofcontents.
  • 8
    .

    MaTeX

    9
    .

    Best Practices

    10
    .

    Credits

    The referencing scheme and the MaTeX integration are originally due to Nik Murzin, github.com/sw1sh; this paclet packages and extends that work.
    [murzin]
    Nik Murzin, https://github.com/sw1sh
    [matex]
    Szabolcs Horvat, MaTeX: LaTeX labels in Mathematica, https://github.com/szhorvat/MaTeX
    [texlive]
    TeX Live, https://tug.org/texlive/ — on macOS, MacTeX, https://tug.org/mactex/
    [lm]
    Latin Modern, https://ctan.org/pkg/lm and TeX Gyre, https://ctan.org/pkg/tex-gyre