Equation Numbering Prototype


When writing the Math in Office 2010 post back in July, I could just imagine the disappointment various people would have when they discovered no mention of equation numbering. After getting math into PowerPoint, equation numbering had been the most often requested feature. Since PowerPoint 2010 now has the math facility, equation numbering has risen to the top of the wish list. Note that there is a way to display and manage equation numbering in Word as described in the work of Dong Yu. To get a feel for a native numbering facility, I implemented a prototype in RichEdit that interfaces to the underlying Page/TableServices (PTS) math handler’s equation numbering facility. This post describes that approach. It may not be the one we ship someday, but it does work pretty well. First I describe how equation numbers are represented in the file format and in memory and then consider equation number management.


 


The file format is one area a new feature has to consider. It would be nice not to change the file format for equation numbers, since it makes backward compatibility just that much harder to deal with. For example, it would be very convenient if equation numbers from a future version of Word would display reasonably well in Word 2010 or Word 2007, admittedly with small modifications to those versions. So I examined the nooks and crannies of the Office math format, OMML, for a math object that could be used to contain an equation number.


 


Lurking in that object space is a “no-op” phantom. To understand what this object is and why no one is likely to have used it, we need to know what a phantom object is. The phantom is characterized by five Boolean flags: 1) zero ascent, 2) zero descent, 3) zero width, 4) show, and 5) transparent. You can read about it in the post on MathML and Ecma Math (OMML) and in Sec. 3.17 of the linear format paper. The “zero” flags are handy for suppressing any combination of three object dimensions. Such suppression is called “smashing” by Donald Knuth. You can “smash” the descent of a character with a descender like y so that it has the same size as one without a descender like x. To facilitate entering smashes, we have the control words \asmash, \dsmash, and \hsmash to smash the ascent, descent, and width, respectively, of the phantom argument. Smashes have the show flag on, since the idea is to show the argument, but give it one or more zero dimensions. If you have the show flag off, you have a true phantom, in that space is taken up by the argument, but nothing is displayed. The fifth flag, the transparent flag, means that the argument is treated by the surrounding environment as if no object were there. So an equals sign inside a transparent phantom has math spacing appropriate for an equal sign outside a math object, apart from changes imposed by smashing various dimensions.


 


A no-op phantom is one that displays its argument as if the phantom weren’t even there: the argument has its true dimensions and it is transparent. Since the no-op phantom doesn’t serve any purpose, we might as well give it one: house an equation number. That works for the file format. Now let’s see how it works for actual display in a document.


 


The PTS math handler which ships with Office 2007 and Office 2010 has a number of callbacks for equation numbers. We just need to answer the questions appropriately and presto; the equation number will be displayed accordingly. To make sophisticated choices such as placing the numbers on the left hand side of equations instead of the right hand side, one needs to have some document properties. Ignoring such generality for the moment, we tell the PTS math handler to display the equation number flushed to the right on the last line of an equation. An equation may take up several lines and the PTS math handler can center the equation number vertically, if desired. Secondly, we place the no-op phantom as if it were an equation itself directly following the equation to be numbered. As such the no-op phantom is the only thing inside a soft paragraph, separated from its equation by a Shift+Enter (ASCII VT character). The PTS callbacks needed to be generalized slightly to deal with this special kind of “equation”, but it’s straightforward.


 


The last thing to consider is how to manage equation numbers, namely insert, delete, and edit them. Section 3.21 of the linear format paper explains how to type in an equation number, namely enter the equation followed by a # (U+0023) followed by the desired equation number text and type a [Shift]+Enter. The numbers can be edited in place. But underneath one needs renumbering and synchronization with inline equation number references. Such management could be accessed via a context-menu or math-zone acetate drop down menu. Insert and Delete would work with a single click and edit would open a dialog with options such as whether to include chapter and section numbers and whether the resulting entries should be separated by periods or hyphens. Word would likely treat the equation numbers as bookmarks so that links to them would automatically show the current number. Alternatively, the insert/delete/edit command handler could update all inline no-op phantoms to agree with the corresponding no-op phantoms inside math paragraphs.


 


MathML doesn’t have the concept of a math paragraph, but when embedded in a parent format, the math paragraph can be emulated fairly easily. Basically a math paragraph is just one or more math zones separated by soft paragraph breaks. So the equation number for a displayed MathML math zone (<math>…</math>) would follow the math zone. MathML has an <mphantom>, which suppresses the display of its argument, but keeps its size. Since we want to show equations numbers, <mphantom> isn’t useful for housing an equation number. <mpadded> has the other attributes of the OMML <phantom> except for transparent and if it just displays its argument with no changes, it could be used to house an equation number. In addition, it’s legal to add any attributes that one wants to a MathML element provided the attributes are in a private namespace, so one can be quite precise as far as a given family of implementations go. To be interoperable, MathML would have to add its own way of representing equation numbers, but hasn’t done so in MathML 2.0 or 3.0.


 


Comments (14)

  1. Paul says:

    I don’t understand how you will implement cross referencing of Equations if you break away from the sequence fields used for captioning in the rest of Word.

    While I really like the promotion of equation’s to first-class objects in Word, I’m enormously frustrated that simple equation numbering (as I’ve described here: http://www.blueleafsoftware.com/Resources/Writing/Save_time#Equations) is broken by restricting display equations to live alone on a line.

    It would be helpful if you could build equation formatting from styles. As it stands, bulk format seems to be defined as a new set of document properties. This means, for example, I can’t create styles for left justified and right justified math layout. Of course I can control the justification of equations by disabling [x] use the following settings for… But then I lose the centre as a group facility. It seems the math options in that dialog should be things like ‘when there’s a bunch of equations in adjacent paragraphs, make them line up at equals signs’ (though this should also be a style property, not a document property).

  2. Lary Stucker says:

    Just FYI, MathType does equation numbering and it works with all equation types: old Equation Editor, MathType, and Word 2007 OMML equations.

  3. MathML would have to add its own way of representing equation numbers,

    The way MathML2 (and so far, MathML3) represent equation numbers is

    to use a one-row mtable and use mlabeledtr see the section "Equation numbering" at the following (for mathml2 and 3 respectively)

    http://www.w3.org/TR/MathML2/chapter3.html#id.3.5.3.3

    http://www.w3.org/TR/MathML3/chapter3.html#id.3.5.3.3

    MathML doesn’t have any support for automatic numbering of equations throughout a document, as that depends heavily on the facility of the host document type.

  4. Nali says:

    Here is interesting alternative:  

    http://www.bakoma-tex.com/menu/download.php  

    But MS-Word is better 🙂

  5. Drvec says:

    Ok, great, equation numbering is at the top of the list. But how is it reasonable, supposing that the next release of Office comes out in 2013, that we should have to wait 13 odd years to have such a trivial feature implemented as default?

    I mean, people have been asking for this for 10 years!

    Remember that Mathtype is a paid-for upgrade, where Equation Editor doesn’t have this. And now that Word’s native equations have usurped the (at least) upgradeable EqEd module, I find myself searching for work-arounds to allow me to put MathType back into Office 2010 beta.

    How many PhDs and Masters will go through in 13 years being told by their supervisors to use Latex? I’ve been promoting Word to my colleagues all along, but this is becoming distressing. I was convinced after finding the MS Research macros for adding numbering to 2007 that it would become native in 2010, but now I’ve lost hope again.

    And for that matter, I tested the Tech Preview, and the anti-aliasing bug for animated vector objects in Powerpoint is still there! and the MathType people, I know, have been complaining about that since at least Office 2000. Yup, 10 years plus to get a rendering bug fixed that makes the only reasonable solution to the equation numbering issue unacceptable in a product of the same family. I’ve seen ugly, blocky equations  from MathType in so many PPTs in so many conferences.

    And lastly, let’s suppose we do finally get numbers with a bracket by 2013, then I’m guessing we’ll still have only the one atypical modern math font to choose from. We need a classical math font, like Latex or MathType please.

    Thanks if you beared with me through that haranguing.

  6. Drvec says:

    By the way, not to be mean or anything, but I just tested something else in the 2010 beta that I was hoping would be fixed after 2007 and unfortunately it seems to have remained unchanged: Integral signs still do not length with respect to the size of the integrand object.

    However the sum (cap sigma) sign does seem to enlarge. WHy one and not the other?

    Ps, slip equation numbering into 2010 before it ships and I’ll send you a box of chocolates. Promise! 😛

  7. MurrayS says:

    You can cause integrals to grow according to the integrand size by right clicking on the integral sign and choosing the "Stretch N-ary operator" option. This option isn’t on by default since it isn’t available in [La]TeX, a fact that indicates it isn’t used much in mathematical typography.

    I’d love to slip equation numbering into Office 2010 along with quite a few other cool things, but we have amazing test teams and they’d surely notice! Not to mention our developer code reviews would reveal such changes. It’s not like the old days when we could put things in at the last moment. For example, one weekend in the Spring of 1994, David Weise sneaked Unicode font support into Windows 95’s ExtTextOut and thank God he did! But those days are long gone especially with today’s security concerns.

  8. Nali says:

    Manual Equation Numbering works in Excel 2010, OneNote 2010 and also PowerPoint 2010 (Beta)!!!

    Your equation must be "Display" not "Inline"! In Display Equation you must crete an "Equation array" (  eqarray ) and inside the array type your equation (e.q. E=mc^2) – so you have    eqarray(E=mc^2). After buildup array and equation, you must return cursor back into the equation array (behind your equation, e.q. E=mc^2, but "inside" the equation array) and type  #  or keyword   eqno. After that cursor automatically move to the right side of math paragraph and you can type there some text or manual number for your equation! – so your equation is centered and the equation number is on the right side of paragraph 🙂  

    GOOD JOB FOR EXCEL, POWERPOINT AND ONENOTE!!!

    Unfortunatelly this manual equation numbering does not work in Word 2010 🙁   Now, equation buildup engine in Excel, PowerPoint and OneNote is better (more powerful) than equation buildup engine in Word 🙁

  9. Nali says:

    …and type  #  or keyword   eqno<space>….

  10. Nali says:

    I think that this way of equation numbering is good enough (even very good) for using in PowerPoint Presentation and OneNote 🙂

    Yes, I know that it is described in Section 3.21 of UTN#28 – I have known it for a long time, since I have used Word 2007 – but in Word 2007/2010 it does not work 🙁 And moreover I always tried this manual equation numbering without using "equation array structure" (only   eqno alone), but unsuccesfully. But now I was very surprised when I see, that it works in Excel/PowerPoint/OneNote when I use equation array! 🙂

    THANK  YOU  VERY  MUCH  FOR  THIS  NICE  AND  IMPORTANT  FEATURE!!! 🙂 It will be very useful in my school PowerPoint presentation.

    And I hope that one day you tell us step by step about all new  "math" things implemented in Word, Excel, PowerPoint and OneNote in this blog 🙂

    I look forward to the next version of Unicode Technical Note.

  11. Erik Esveld says:

    Just migrated from office 2003 to 2010.

    Thanks for finally coming up with a proper equation editor.

    What a shame however that it cannot be used in word 2010 since the equation cannot be numbered.

    Virtually all the scientific articles / reports / books that I have seen en worked use equation numbering.

    Thus I have to keep using mathtype….  Pity

    I would be a relief if Microsoft would spent a fraction of the MSoffice revenues to more people like MurrayS, so that the millions of technical and academic users are better served. Not just only proper equations, but also references, bibliography, decent graphs (you know those clear XY graphs, that you see in journals, the ones that scientists and engineers have used for ages but excel consequently fails to make) etc.

    I fully agree with Paul that numbering should be handled in the same way as other objects (captions) are sequentially numbered, which is not possible now due the omnipresent return behind the display equation. I only manage it to put the number in a separate text box, which hovers to right side of the equation, anchored to the line below. It kind of works, but is very tricky.

    Speaking of it, the 15 year old caption function in Word should be updated, so that it does a more decent job like the freedom to put the number at the (right) side of the object and to have it in brackets. Other weird thing, if you make a cross reference, you also get the (capitalized) label with the number, which is almost always unwanted. Example: "As can be seen in Figure 2 and Figure 3." should be "As can be seen in figure 2 and 3."

  12. davidacoder says:

    I briefly looked around in Word 2013 Consumer Preview and at least couldn't find anything equation numbering related. Please don't tell us that we have to wait until Word 2016??

  13. User 1 says:

    I installed the Preview of Office 2013, solely to check if there is quation numbering…i couldn't find anything either. Thats unfortunate.

  14. Nali says:

    It seems that this Preview of Office 2013 does not contain any improvements to math or to ordinary text. Some bugs were fixed (now the diferential dd can have upright style in Power Point), but some were not fixed yet (unicode subscripts turn to nested superscripts).

    In math, there are no equation numbering, no improvements to mathparagraph, no easy possiblity to use the sanserif letter in math zone, no mathzones in Publisher,…

    In ordinary text, there are no hanging punctuation, no improvements to line services, no true sub/superscript, no true smallcaps,…

    I have installed Office 2013 parallel to Office 2010. Maybe, it would be better to install Office 2013 on a clean PC.