Typefi provides a variety of event scripts for working with MathML.

For all MathML-enabled Typefi workflows, you must add core scripts to your workflow. The core scripts convert MathML content into text equations in Adobe InDesign.

In addition, you can add optional scripts that automatically format MathML equations. For example, scripts can automatically centre equations, prevent equations from sticking out from the bottom of a text frame, or horizontally align equations within a table cell.

See Deploying event scripts in a Typefi workflow for step-by-step instructions for adding event scripts.

## Overview

This table provides a summary of each MathML event script. Click the script to learn more about it.

Event script | Description |
---|---|

Adjust Spacing | Adjusts the spacing of equations. |

Align Equation | Looks for lines separated by soft returns, and if the first and the last characters are MathZones, it aligns the equations. |

Break Equation on Equals Sign | Breaks block equations on an equals sign. |

Centre Equation | Centres equations horizontally on a line. |

Check Equation at Foot of Frame | Prevents equations from sticking out from the bottom of a text frame. |

Check MathTools Status | Checks the status of a MathTools installation. |

Fix MathZone in Table | Horizontally centres and aligns equations within a table cell. |

Flush Equation Number Right | Moves the number in a numbered equation from underneath the equation to the right-side of the equation. |

Keep Punctuation with Equation | Prevents a break between punctuation marks directly following an equation and the equation itself. |

MathML Handler | Required. Installs the MathML handler so that MathML is passed through to the InDesign document. |

MathML to MathZone | Required when using movemen MathTools. Converts MathML to MathZones. |

MathType to MathZone | Converts MathType EPS equations to MathTools MathZones. |

Many MathML event scripts include one or more numbers in their names. If there is a number at the beginning, for example, *15MyScript.jsxbin, t*he number sets the order that scripts are run in Typefi Server. If the number is at the end, for example*, MyScript1.5.jsxbin*, the number refers to the version number. This article does not include the version number in event script names so that the information is version-agnostic.

Many MathML event scripts differentiate between *block* (sometimes referred to as *display* *equations*) and *inline* equations. Block equations are the only item in a paragraph, while inline equations are part of a larger paragraph. If you need a refresher on the differences between the two, see Same equation, different display.

## Core scripts

If your output includes MathML equations, you *must* include specific scripts in your Typefi workflow.

See Set up a MathML-enabled workflow for an example of a MathML-enabled workflow.

The core scripts you need depend on your input:

If your input is | You need these core scripts |
---|---|

MathML (via Content XML, the data format used by Typefi to encode content) | MathML Handler (MathMLHandler.jsxbin) and MathML to MathZone (10_MmlToMz.jsxbin) |

MathType EPS files | MathML Handler (MathMLHandler.jsxbin) and MathType to MathZone (10_MathTypeToMz.jsxbin) |

### MathML Handler

This script installs the MathML handler so that MathML is passed through to InDesign. *You must add the MathML Handler event script if your content contains MathML.*

To use the MmlToMz.jsxbin script, the MathML tags should not have the `mml`

namespace prefix attached: for example, the tags should look like `<mi>`

, and not `<mml:mi>`

.

Name |
MathMLHandler.jsxbin |

Event |
Document start |

Dependencies |
None |

### MathML to MathZone

This script looks for MathML strings, `((?s)<math>.+?</math>)`

, and converts these strings to MathZones. The script also checks whether MathTools is installed and whether its license is valid (and cancels the job if MathTools is not installed or if the license is invalid).

Name |
10_MmlToMz.jsxbin |

Event |
Spill end, must always be the first spill end script |

Dependencies |
None |

### MathType to MathZone

This script converts MathType EPS equations to MathTools MathZones.

Name |
10_MathTypeToMz.jsxbin |

Event |
Spill end, must always be the first spill end script |

Dependencies |
None |

## Optional scripts

Use these scripts to check if MathTools is installed, or to adjust the formatting of MathML equations.

### Check MathTools Status

Use this script to quickly check if MathTools is installed on Typefi Server. The script prints the following information in the log:

- Whether MathTools is installed, and
- If MathTools is installed, the version number and the license status (either
*Normal*or*Reader*).

The MathML to MathZone script also checks whether MathTools is installed and whether its license is valid (and cancels the job if MathTools is not installed or if the license is invalid).

Name |
MathToolsStatus.jsxbin |

Event |
Document start |

Dependencies |
None |

### Adjust Spacing

First, this script distinguishes between block and inline equations. An equation is considered a block equation if:

- The applied paragraph style's name contains
*equation*(case-insensitive).

Or

- The equation is up to 3 characters shorter than its parent paragraph. In theory, a block equation is one character shorter than its parent paragraph (the hard return), but in reality, we have to allow for some (messy) leading or a trailing space, and
- The equation's parent paragraph ends in a tab (or right-indent) followed by a number in parentheses.

If these conditions are not met, the script considers an equation to be inline.

Based on whether the equation is block or inline, the script does three things:

- Adjusts the spacing of paragraphs with block equations. If the equation's ascent is bigger than the applied paragraph style's ascent, the difference is added locally to the paragraph's spaceBefore property. Similarly, if the equation's descent is bigger than the applied paragraph style's descent, the difference is added locally to the paragraph's spaceAfter property.
- Sets a paragraph rule (0 pts, no colour) at the ascent of all equations and enables the
**Keep in frame**option. This ensures that if an equation ends up at the top of a text column, it won't stick out of it. InDesign does not currently have any built-in mechanisms that prevent the bottom of an equation from sticking out from the bottom of a text frame. To do so, use the Check Equations at Foot of Frame script. - In inline equations, this script inserts a rule (a graphicLine object) immediately before the MathZone and sizes it to the equation's height. It applies the object style
*mathZoneLeading*to the graphicLine and the character style*autoLeading*to the line's parent character. This ensures that tall-ish inline equations do not overlap with preceding and following lines of text, and prevents tall equations from sticking out of the top of the text frame when it's in the first line of the text frame.*autoLeading*does not apply when the paragraph text is aligned to the baseline grid.

Name |
15_DisplayEquationsSpacing.jsxbin |

Event |
Spill end, after the MathML to MathZone script and the Conditional Spacing script. Both scripts are numbered so that they automatically run in the right order. |

Dependencies |
- movemen plug-ins version 3.0.1_053 or later
- An InDesign object style called
*mathZoneLeading* - An InDesign character style called
*autoLeading*
You can download the InDesign snippet at the end of this article and copy-and-paste the object and character styles into your template. |

### Align Equation

This script looks for lines separated by soft returns. If the first and the last characters are MathZones, it aligns the equations.

Name |
AlignEquations.jsxbin |

Event |
Document end |

Dependencies |
In the InDesign template, disable Skip by leading (Preferences → Composition) |

### Break Equation on Equals Sign

If a block equation breaks to two lines, this script adds a paragraph break before the last equals sign (if there is one). The script targets only equals signs that are not part of a substructure; in other words, only if it has no baseline shift applied.

Name |
40_BreakEqnOnEqualSign.jsxbin |

Event |
Page end, before any other page balancing scripts |

Dependencies |
The first two letters of the used paragraph style should be eq (case-insensitive) or, the style name should contain equation or formula |

### Centre Equation

This script centres equations horizontally on a line.

In respect to block equations, InDesign's line and paragraph composers determine the last character of a paragraph based on the position of the last printable character. Consequently, centred and right-aligned paragraphs are never positioned correctly. So, this script adds a dot at the end of the paragraph and applies the character style *Hide* (created on the fly if necessary), which is a classic hiding style (0.1 pts type size, 1% horizontal scale).

Name |
17_EquationCentre.jsxbin |

Event |
Spill end |

Dependencies |
The script looks for instances of paragraph styles whose name starts with eq or disp-formula (case-insensitive) |

### Check Equation at Foot of Frame

This script prevents equations from sticking out from the bottom of a text frame. If the equation's descent is more than the applied paragraph style's descent, then the equation is forced to the next column.

Name |
CheckEquationsAtFootOfFrame.jsxbin |

Event |
Page end |

Dependencies |
The first two letters of the used paragraph style should be eq (case-insensitive) or the style name should contain equation or formula |

### Fix MathZone in Table

This script wraps equations in table cells in an inline frame using InDesign's top menu: **Math → Math Zone → Wrap MathZone(s) into inline Frame(s)**. Wrapping equations in inline frames allows for the correct horizontal alignment of equations which fall within a table cell.

Name |
FixMzInTable.jsxbin |

Event |
Page end, before any element extender scripts |

Dependencies |
MathZone equations within a table cell |

### Flush Equation Number Right

This script sets an equation number flush right if it is forced to a new line. When a numbered equation is almost as wide as the text measure, the equation number is placed below the equation, centred. Flush Equation Numbers to the Right fixes this by inserting a forced paragraph break and a flush-right tab before the number.

To illustrate:

Name |
EqnNumberFlushRight.jsxbin |

Event |
Document end |

Dependencies |
The first two letters of the name of the paragraph style should be eq (case-insensitive) |

### Keep Punctuation with Equation

This script keeps any punctuation marks that directly follow an equation with the equation so that a punctuation mark does not end up by itself on the next line.

Name |
11_MZnoBreak.jsxbin |

Event |
Spill end, after the MathML to MathZone script, Apply GREP script, or any other script that might alter the math |

Dependencies |
None |

## Comments

0 comments

Please sign in to leave a comment.