Message Boards Message Boards

5 Replies
0 Total Likes
View groups...
Share this post:

Getting equation numbers upon Exporting as HTML

Posted 9 years ago

Say I have a notebook that is using the Default.nb stylesheet and contains some cells with the "DisplayFormulaNumbered" style. Thus the notebook (attached) looks like the following:

enter image description here

Let's say that this notebook's NotebookObject is nb, then if I Export this notebook using Export in this form to get MathML rendering using MathJax (but my question that will follow is more general than this)

CreateDirectory[FileNameJoin[{$UserDocumentsDirectory, "TestHTML"}]];

Export[FileNameJoin[{$UserDocumentsDirectory, "TestHTML","test.html"}], 
 nb, "HTML", "MathOutput" -> "MathML", 
 "FullDocument" -> True, 
 "HeadElements" -> {"<script type='text/javascript' src=''></script>"}]

the resulting HTML page that is created formats quite nicely, but it does not contain the equation numbers that are on the right in the notebook version.

So... question. Is there a method to Export as HTML that creates the equation numbers?

If I have a Section Cell with an explicit CounterBox embedded in it (rather than coming from the cell style in the style sheet) that numbering appears, I believe (if I remember the results of that test... ;-) )

POSTED BY: David Reiss
5 Replies

Thank you Hans. I did report this as a bug to WRI and it is in their bugs database. So perhaps it will get handled at some point. I don't imagine that this is avery high priority bug though... so we'll see.

POSTED BY: David Reiss


I looked at your revised notebook a while ago. I did not post because the sections autonumbering is hard coded on export. So the reference to section 1, increments wrongly and is hard coded to "3". So there is no css to fix, so one would need to fix the HTML export "ConversionRules" for the Cell of style Section. I did not look any further. It would mean digging into Mathematica stylesheets and other functionality; have not done work this area of M in 10 years.

POSTED BY: Hans Michel

I have slightly updated the notebook attached to my first post.

It now contains two Sections with an explicitly included autonumbering object at the start of each. These both export properly to HTML.

In the second Section there is also a Section cell which has a reference autonumbering object which points to the first Section cell (which has a CellTag for this purpose). It works correctly in the notebook--it displays the number 1 -- but when exported as HTML it displays incorrectly: it displays as 3.

This is a picture of the new notebook:

enter image description here

POSTED BY: David Reiss

Thank you Hans!

One of these days I need to properly learn CSS... ;-)

I have edited Exported CSS files before, but my sophistication in this is just as a blind hacker.

So, this suggests that the support for the generation of the CSS code for cell styles with automatic numbering objects (and it seems for embedded counter objects in cells--I tried a simple example of this and it didn't work, though I need to do more testing) is lacking.

I will file a bug report on this...

POSTED BY: David Reiss

David: The Wolfram Language Export HTML with MathML will produce an Automatic CSS file in the "HTMLFiles"directory. Since the file you are exporting is called "test.html" the CSS file created will be called "test.css". With the setting you currently have you then just need to modify the CSS file in the following way to go off the "DisplayFormulaNumbered" class generated in the p element MathML wrapper:

<p class="DisplayFormulaNumbered">
  1. In the CSS file after html rule add a body rule to reset the counter variable we'll call equation

html { font-size: 12px; padding: 8px; } body { counter-reset: equation; }

  1. Find the .DisplayFormulaNumbered rule and add the following rule

    .DisplayFormulaNumbered { font-size: 14px; font-family: Arial; color: #333333; margin-left: 66px; padding: 8px; } /* equation counter */
    p.DisplayFormulaNumbered:after { content: "(" counter(equation) ")"; counter-increment: equation; font-size: 14px; font-family: Arial; color: #333333; display: block; float: right; margin-right: 10px; }

Depending on web browser this should work.

POSTED BY: Hans Michel
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract