HTMLSave
Usage
Notes
Additional Information
Introduction Mathematica can translate notebooks, as well as cells, lists of cells, boxes, or other notebook elements into HTML. HTMLSave wraps the input in a notebook before conversion. Therefore, the output of HTMLSave is always a complete HTML document, and not merely a fragment of HTML. Invoking HTMLSave You may invoke HTMLSave from the File Save As Special menu command in the notebook front end. You may also invoke HTMLSave from the kernel if it is connected to a notebook front end. The front end converts typeset expressions or graphs to GIFs and provides document settings (such as style sheet information) to HTMLSave. HTMLSave Options When you invoke HTMLSave from the kernel, you may set the option ConversionOptions.
| options | values | meaning | | "MathOutput" | "GIF" (default) | converts all typeset expressions to GIFs | | "MathML" | converts all typeset expressions to MathML | | "DisplayForm" | converts all typeset expressions to ASCII approximations of their appearance | | "InputForm" | converts all typeset expressions to a linear ASCII representation, with no attempt to preserve the appearance of the typeset form | | "ConversionRules" | Automatic (default) | maps from style name to the markup equivalent of that style name in HTML, including both inline and block-level versions of the markup | | "HeadAttributes" | {attr1 value1, ... } | inserts value as attribute on <head> tag (<head attr1 = value1 ... >) | | "HeadElements" | {elem1, ... , elemn} | inserts value as subelement under the <head> tag (<head> elem1 ... elemn </head>) | | "CSS" | Automatic (default) | create a CSS style sheet from the Mathematica style sheet | | None | create no CSS style sheet or inline CSS styles | | "file.css" | use an existing style sheet | | "ConvertLinkedNotebooks" | False (default) | hyperlinks to notebooks become links to an unconverted notebook | | True | hyperlinks to notebooks become links to an HTML version of the notebook | | "MathMLOptions" | (options) | list of options to customize output of MathML; allows all of the options of XML`MathML`BoxesToMathML |
The option ConversionOptions for HTMLSave.HTMLSave Output The output produced by HTMLSave conforms to the XHTML 1.0 standard. The output consists of one or more HTML files and two directories, HTMLFiles and HTMLLinks. When using the Save As Special menu command, a dialog box appears for specifying the name of the file. When using the kernel, you name the output via the first argument to HTMLSave. If you do not provide an extension to the name given to the output (e.g., index.html), HTMLSave creates a directory by the name you provided. This directory then contains the HTML files and the HTMLFiles and HTMLLinks directories. HTMLSave writes out nearly all inline typeset expressions and many block-level typeset expressions as GIF files. There are two general exceptions: 1. Choosing XML (XHTML+MathML) from the File Save As Special submenu (or using the "MathOutput" "MathML" option from the kernel) writes out the expression marked up with MathML tags. 2. If a GridBox is the top level of a cell, an HTML table will be generated. Hyperlinks HTMLSave uses hyperlinks in your Mathematica notebook to generate HTML links and produce additional HTML documents. By default, a link to other notebooks is converted to HTML hyperlink to a noteook file. With the ConversionOption "ConvertLinkedNotebooks" True, if you have a link to a notebook called notebook2.nb in the notebook you are converting via HTMLSave, Mathematica converts the Mathematica hyperlink to an HTML hyperlink and converts the notebook notebook2.nb to HTML. There is one exception: links to online Mathematica documentation generate a link to documents.wolfram.com whenever possible. If it is not possible, then an empty hyperlink is generated. HTMLSave also generates hyperlinks from closed cell groups. The head cell of the group becomes the hyperlink, and the remainder of the group becomes a separate HTML document. Tables HTMLSave writes out top-level GridBoxes as tables. GridBoxes are counted as top level if they are in the topmost box or if they are wrapped in non-layout boxes, which are StyleBox, TagBox, and InterpretationBox. HTML tables are block-level elements, which means that they have an explicit break or return at both the beginning and end. Since HTML tables are never block-level elements, Mathematica inline GridBoxes cannot be rendered as tables and are saved as GIFs. Principles of Notebook Conversion HTML is a markup language rather than a document layout language. This means that it defines elements by their purpose in the document (e.g., title, list element, and so on) rather than their actual appearance (e.g., 14-point bold Palatino). You should always mark up elements according to their purpose. If you must add appearance tags, such as <b> and <font>, use them in addition to structural tags, such as <code> or <em>. For the difference between appearance and structural tags, consult any introductory HTML book. Here is a cell expression that uses the Subsubsection style.
Cell[TextData["Principles of Notebook Conversion"], "Subsubsection"]
This is the corresponding output written to the HTML file after conversion.
<h5>Principles of Notebook Conversion</h5>
The output does not explicitly specify the font choice or other aspects of its appearance. Subsubsection items in Mathematica under the default style sheet appear in 12-point bold Times with a small filled square cell dingbat, but different browsers will display a level 5 heading quite differently. For cells that contain two-dimensional typeset math expressions, HTMLSave generates a GIF. Selecting HTML/MathML from the File Save As Special menu (or using the "MathOutput" MathML option from the kernel) writes out the expression marked up with MathML tags. Here is a cell expression that uses the Text style and contains a TraditionalForm inline cell.
Cell[TextData[ "The Pythagorean theorem states that ", Cell[BoxData[ FormBox[ RowBox[ SuperscriptBox["c", "2"], "=", " ", RowBox[ SuperscriptBox["a", RowBox[ "2", " " ]], "+", " ", SuperscriptBox["b", "2"] ] ], TraditionalForm]]], "."
], "Text"]
This is what is written to the HTML output file using File Save As Special HTML.
<p class="Text"> The Pythagorean theorem states that <img src="HTMLFiles/inline1_gr_1.gif" border="0" alt="c^2 = a^2 + b^2" width="73" height="17" align="absmiddle" >. </p>
This is what is written to the HTML output file using File Save As Special XML (XHTML+MathML).
<p class="Text"> The Pythagorean theorem states that <math xmlns='http://www.w3.org/1998/Math/MathML' mathematica:form='TraditionalForm' xmlns:mathematica='http://www.wolfram.com/XML/'> <mrow> <msup> <mi>c</mi> <mn>2</mn> </msup> <mo </mo> <mtext> </mtext> <mrow> <msup> <mi>a</mi> <mrow> <mn>2</mn> <mtext> </mtext> </mrow> </msup> <mo>+</mo> <mtext> </mtext> <msup> <mi>b</mi> <mn>2</mn> </msup> </mrow> </mrow> </math>. </p>
Adjusting Output via Style Sheets The output of HTMLSave can be adjusted through ConversionRules, specifying which HTML tags, or nested tags, appear in the HTML document. Here is the general structure of ConversionRules.
ConversionRules ->
"HTML" ->  "inline beginning tags", "inline ending tags" ,
"block-level beginning tags", "block-level ending tags"  .
As you can see from the form of the ConversionRule, HTML draws a strong distinction between block-level elements and inline elements. It is important when you add ConversionRules to your style definition cells to include both the inline rule (the first set of tags) as well as the block-level rule (the second set of tags). The block-level rule should have an outermost tag that is block-level, such as <p> or <div>. The inline rule should never have an outermost tag that is block-level. Here is a style definition cell that contains a conversion rule for the InlineFormula style from the default style sheet.
Cell[StyleData["InlineFormula"], other cell options, ... , ConversionRules ->  "HTML" ->  "<b><code>", "</code></b>" , "<p><b><code>", "</code></b></p>"   ]
When HTMLSave converts an item in the InlineFormula style, it wraps the item in bold and code tags if the item is inline, and adds a paragraph tag if the item is block-level. Here is a cell expression in the InlineFormula style.
Cell[TextData["x = a + b"], "InlineFormula"]
Here is the appearance of the converted cell in the HTML output file.
<b><code>x = a + b</code></b>
Getting Updates to the Source Code Despite the large number of options for adjusting HTMLSave output via style sheet conversion rules, there may be circumstances where you need to make changes at a deeper level. Since HTMLSave is implemented as top-level Mathematica code, the source code is available in Mathematica package format. The package can be downloaded from the web at http://support.wolfram.com/mathematica/interface/export.
|