NB (.nb)

Background & Context

    • Registered MIME types: application/mathematica, application/vnd.wolfram.mathematica
    • Wolfram System notebooks.
    • Native file format of the Wolfram System notebook interface.
    • Used for storing and exchanging Wolfram Language input and output and for the creation of interactive technical documents.
    • Used as a deployment format for interactive use in Wolfram Player.
    • ASCII format based on the Wolfram Language expression syntax.
    • Stores text, typeset expressions, graphics, animations, sounds, and other Wolfram Language input and output.
    • Supports interactive elements like hyperlinks, buttons, sliders, and other graphical user interface features.
    • Uses external or embedded stylesheets for specifying the appearance onscreen and in print.
    • Developed since 1988 by Wolfram Research.

Import & Export

  • Import["file.nb"] reads a Wolfram System notebook and returns it as a Notebook expression.
  • Export["file.nb",expr] exports a Notebook, Cell, or box expression, as well as arbitrary mathematical expressions, as a notebook.
  • Import["file.nb",elem] imports the specified element from a notebook.
  • Import["file.nb",{elem,suba,subb,}] imports a subelement.
  • Import["file.nb",{{elem1,elem2,}}] imports multiple elements.
  • The import format can be specified with Import["file","NB"] or Import["file",{"NB",elem,}].
  • Export["file.nb",expr,elem] creates a notebook by treating expr as specifying element elem.
  • Export["file.nb",{expr1,expr2,},{{elem1,elem2,}}] treats each expri as specifying the corresponding elemi.
  • Export["file.nb",expr,opt1->val1,] exports expr with the specified option elements taken to have the specified values.
  • Export["file.nb",{elem1->expr1,elem2->expr2,},"Rules"] uses rules to specify the elements to be exported.
  • See the following reference pages for full general information:
  • Import, Exportimport from or export to a file
    CloudImport, CloudExportimport from or export to a cloud object
    ImportString, ExportStringimport from or export to a string
    ImportByteArray, ExportByteArrayimport from or export to a byte array

Notebook Interface

  • In the notebook front end, Save and Save As can be used to save the current notebook to a file.

Import Elements

  • General Import elements:
  • "Elements" list of elements and options available in this file
    "Summary"summary of the file
    "Rules"list of rules for all available elements
  • Import elements:
  • "Cells"list of cell styles
    "Initialization"reads and evaluates all initialization cells, returning the results as a list
    "Notebook"notebook represented as a Notebook expression
    "NotebookObject"NotebookObject expression
    "Plaintext"plain text version of the notebook
  • Import by default uses the "Notebook" element for notebook files.
  • The following can be used to select cells based on cell style:
  • "Cells"list of cell styles
    "Cells",styleall cells of style style

Examples

open allclose all

Basic Examples  (1)

Find the notebook file:

Import the .nb file:

Export as a .nb file:

Scope  (2)

Show the Import elements available in a sample file:

Convert an arbitrary mathematical expression to the notebook format:

Import plain text contents from the previous output:

Import Elements  (5)

"Cells"  (1)

Enumerate all of the cell styles in a notebook:

Return all of the Cell expressions using the Text cell style:

"Elements"  (1)

Enumerate the available import elements:

"Notebook"  (1)

Import the notebook as a notebook expression:

"NotebookObject"  (1)

Import the notebook into a new window and return the resulting NotebookObject:

The resulting notebook object points to a new untitled window:

"Plaintext"  (1)

Import a notebook to a string containing the plain text and chop it to the first 100 characters: