Mathematica Notebook Technology
File Extension and MIME type
Mathematica notebooks are structured interactive documents that can contain text, graphics, sound, calculations,
typeset expressions, and user interface elements. Notebooks have the file extension .nb. Files of this type
are automatically associated with Mathematica on systems in which Mathematica is installed. For more
information on Mathematica, including trial downloads, go to the Mathematica website. To view the complete
documentation for Mathematica on the web, go to the
Wolfram Mathematica Documentation Center.
Mathematica Player notebooks are a specially created subset of Mathematica notebooks to be used with
Mathematica Player. (Mathematica Player notebooks also work in Mathematica.) Mathematica Player is a freely downloadable notebook
player. Mathematica Player notebooks are "signed" versions of Mathematica notebooks;
the format specifications for these two file types are essentially the same.
.nb

file extension for Mathematica notebooks

.nbp

file extension for Mathematica Player notebooks

File extensions for notebooks.
The MIME type for both Mathematica notebooks and Mathematica Player notebooks is application/mathematica.
Altering this can effectively change the application in which notebook files are opened. It is possible to configure your web browser
to automatically launch notebook files in Mathematica by associating Mathematica with this MIME type.
application/mathematica

MIME type for Mathematica and Mathematica Player notebooks

MIME type for notebooks.
File Format and Specifications
Mathematica notebooks contain only printable, 7bit ASCII characters and are viewable and largely humanreadable
in any
text editor. One can determine the version of Mathematica that created a notebook by opening the notebook in a
text
editor and finding the line near the top that reads, for instance:
(* CreatedBy='Mathematica 7.0' *)
The notebook file format is a crossplatform format, meaning that a Mathematica installation on any supported
platform
can read and display a notebook that has been created on any other Mathematica installation on any other
platform. A list of supported platforms is available.
Newline Characters
Different platforms use several different conventions for newline characters: CR (Mac OS 9 and earlier), LF (Mac OS X
and Unix/Linux), and CR+LF (Windows). All of these conventions are supported in Mathematica notebooks;
Mathematica interprets any of these newline conventions in the same way.
Caching Mechanism
Mathematica uses a file outline cache in notebook files for incremental loading. The cache is
automatically generated by Mathematica when a notebook is saved, and is stored in the file inside
Mathematica code comments to
prevent the notebook expression from being altered. Mathematica code comments are delimited by (* and *).
Cache information is denoted in a notebook by lines such as the following, at the beginning and end of the
file.
(* Internal Cache Information *)
If you edit a notebook file outside Mathematica, such as in a text editor, Mathematica might attempt to
use invalid cache data. To prevent this, if you edit a notebook outside Mathematica, be sure to delete the line
near the beginning of the file that specifies the CacheID.
(*CacheID: xxx*)
Alternatively, you can choose to omit the file outline cache by changing the value of the PrivateNotebookOptions> {"FileOutlineCache"} option.
Format Conversions and File Transfer
Mathematica can convert notebooks to many formats. A complete list of formats is available.
Conversion to Plain Text
To convert a Mathematica notebook to plain text, open the notebook in Mathematica, choose File > Save As,
and select
Plain Text from the dropdown menu. This can be useful for making a notebook available to a document indexer, for
example. Plain text conversion is scriptable using the builtin Mathematica function Export.
Conversion to Other Formats
Mathematica notebooks can be converted to many other formats, such as HTML and PDF. To do this, open the
notebook in Mathematica, choose File > Save As, and use the dropdown menu to view the various formats
available. Conversions to other formats are also scriptable using the builtin Mathematica function Export.
Binary File Transfer
Since Mathematica interprets newline conventions from all supported platforms the same way, transferring
notebooks via binary file transfer has no effect on the notebook.
File Transfer as ASCII Text
Since Mathematica notebooks are ASCII text files, they can be transferred directly via email attachment, via FTP
in text mode, or using any application that transfers data in text mode.
Security
Mathematica includes dynamic interactivity features that allow Mathematica code to be evaluated immediately upon opening a notebook or as sections of the notebook are incrementally loaded. Mathematica includes security systems that advise the user when such an evaluation is about to take place for the first time in a given notebook and allow the user to intervene and prevent any dynamic evaluations in that notebook.
Security options are defined in the front end as suboptions of the NotebookSecurityOptions option. The "TrustedPath" and "UntrustedPath" suboptions define paths for notebook files in which dynamic evaluations should always be considered trusted or a security risk. The default "TrustedPath" option contains directories used directly by Mathematica, including the installation directory and directories where applications are typically installed. The "UntrustedPath" option contains, by default, directories that are typically used for email attachments and web downloads. The "TrustByDefault" option determines the behavior for any notebook file which is opened from a path not listed in "TrustedPath" or "UntrustedPath".
By default, "TrustByDefault" is set to Automatic, which indicates that the front end should scan Dynamic code for symbols that are potentially dangerous, such as those that can lead to file system operations. Any dynamic evaluation containing dangerous symbols is interrupted, and the user prompted.
"TrustByDefault" can also be set to True, which causes the Mathematica to trust all dynamic code without flagging the user, or False, which causes Mathematica to prompt the user when evaluating any dynamic code, even if the code appears to contain no dangerous symbols.
Because the notebook file format is plain text, it is mostly humanreadable. However, there are ways to obfuscate the
code in notebook files by using inline compression in Mathematica. If malicious code is hidden in an initialization
cell, it is possible that Mathematica will evaluate the cell immediately when the notebook is opened. To avoid this
potential issue, it is highly recommended that users set the Mathematica front end option InitializationCellEvaluation to False or Automatic and the option GlobalInitializationCellWarning to True when opening notebooks from untrusted sources.
Sample Notebook File
Download a sample notebook.
Download a sample Mathematica Player
notebook.
Further Information
For more information on notebooks and Mathematicacompatible applications, contact Wolfram Research:
web: http://www.wolfram.com
email: info@wolfram.com
phone: +12173980700 (U.S.)
For more information about Mathematica, including trial downloads, go to the
Mathematica website.
To download the free notebook player, visit the Mathematica Player website.
