June 29th, 2022

RichEdit Autoformatting

Murray Sargent
Principal Software Engineer

RichEdit and Word have had the most elaborate autoformatting ever since Office 2007, namely math formula auto-buildup. A UnicodeMath expression builds up into OfficeMath as soon as it is unambiguous. Word and other programs have also had less ambitious autoformatting since late in the last century. Such functionality includes auto conversion of some simple numeric fractions to composed Unicode numeric fractions, e.g., 1/2 to ½, ordinal superscripts, e.g., 1st to 1st, double dash to long dash, e.g., a--b to a—b, smart quotes, e.g., "word" to “word”, and automatic bulleted/numbered lists. Such autoformatting is available in recent builds of RichEdit since it’s needed for the Office Modern Comments facility. Word and RichEdit have also had autoURL and auto table conversion for many years. The post RichEdit Emoticon Shortcuts – Math in Office (microsoft.com) describes the RichEdit option to convert common emoticon shortcuts to emoji.

Word also supports converting _…_ to italicize the text in the “…” and *…* to bold the text in the “…”. These and some of the other autoformatting notations are reminiscent of Markdown which was invented to enter popular HTML constructs easily in a readable notation. That’s the same rationale that’s behind UnicodeMath for entering math equations and expressions. So, maybe RichEdit should have a Markdown editor option that includes UnicodeMath 😊.

RichEdit’s conversion of simple numeric fractions to Unicode fractions is described in the post Function to get Unicode Fractions – Math in Office (microsoft.com). It supports the whole Unicode fraction repertoire, ↉ ½ ⅓ ¼ ⅕ ⅙ ⅐ ⅛ ⅑ ⅒ ⅔ ⅖ ¾ ⅗ ⅜ ⅘ ⅚ ⅞, whereas Word only handles ½ ⅓ ¼ and ¾. You can create arbitrary numeric fractions using the Unicode superscript and subscript digits along with the U+2044 fraction slash. For example, ⁴⁵⁶⁄₇₈₉₀. Admittedly it’s not great typography, but it works. To enter such characters, it’s handy to have the Alt+x hot key. You can also enter ⅟₁₆, ⅟₃₂, ⅟₆₄, ⅟₁₂₈, and ⅟₂₅₆, where I use ⅟ (U+215F) for the numerator and fraction slash.

To enable RichEdit autoformatting options, send the message EM_SETAUTOFORMAT with wparam = acflgAutoFormat and lparam = 0. The acflgAutoFormat flag can be combined with other flags to disable autoformatting options. The flags and messages are defined by

     acflgAutoFormat = 1
     acflgNoSmartQuotes = 2
     acflgNoSuperscript = 128
     acflgNoEmDash = 256
     acflgNoFraction = 1024
     acflgNoBulletedLists = 8192
     acflgNoNumberedLists = 16384
     EM_GETAUTOFORMAT = WM_USER + 392
     EM_SETAUTOFORMAT = WM_USER + 393

For the time being, also send EM_SETMSOAUTOCORRECT (WM_USER + 391) with wparam = 1 and lparam = 0. This message enables the RichEdit integration of the shared MSO autocorrect facility. As such, the current RichEdit autoformatting code requires MSO to be loaded, even though the autoformatting code doesn’t use it.

Author

Murray Sargent
Principal Software Engineer

Yale BS, MS, PhD in theoretical physics. Worked 22 years in laser theory & applications first at Bell Labs and then Professor of Optical Sciences, University of Arizona. Worked on technical word processing, writing the first math display program (1969) and the technical word processor PS (1980s). Developed the SST debugger we used to get Windows 2.0 running in protected mode thereby eliminating the 640KB DOS barrier (1988). Have more than 100 refereed publications, 3 laser-physics books, 4 PC books, 163 posts on Math in Office blog. Joined Microsoft Research in 1992. Since 1994 have been in Microsoft Office working mostly on RichEdit and OfficeMath. Member of Unicode Technical Committee (1994—) and MathML Working Group (1999—).

0 comments

Discussion are closed.

Feedback