Skip to main content

LaTeX support

If you already have LaTeX code bits inside your texts, the MathType Integrations will show you the actual formulas, and MathType will allow you to edit them in WYSIWYG mode.

小心

LaTeX is disabled in the MathType integration for Moodle if Moodle's TeX Filter is enabled. This is to avoid conflicts.

Using MathType to create, edit, and render LaTeX

  • New equations:

    • If you type LaTeX equations between 2 sets of double dollar signs – $$…$$ – in your HTML editor and you save the page, you will get a page with the math rendered as a readable equation. This behavior means the MathType integration is installed and works behind the scenes to manage the LaTeX.

    • If you want to use MathType to create the LaTeX, place the insertion point between 2 sets of double dollar signs – $$…$$ – then click the toolbar icon to open MathType you can create the equation graphically within MathType When you close MathType to insert the equation, MathType will insert LaTeX into the page.

  • Editing existing equations: When you re-edit the page, you will see the $${LaTeX}$$ again (that is, not the word LaTeX, but the LaTeX code for the equation). Thus, during editing you see LaTeX, and when displaying the rendered page, you see the image of the formula.

    • To edit the equation, click inside the LaTeX code and either edit the LaTeX directly or click the toolbar icon to open MathType then edit it in MathType

Example

Imagine in your course there is a line like this:

Since $$\psi=-\frac{1}{\varphi}$$, this formula can also be written as

After installing the MathType plugin, students will see:

using_latex1.png

Instructors who edit the page in the regular text editor, will once again see this:

using_latex2.png

If the instructor clicks inside the $$…$$ marks, then clicks the MathType icon to edit the expression, he or she will see:

using_latex3.png

After saving the edited equation from MathType this is the instructor view:

using_latex4.png

Alternatively, the instructor could have simply typed +\pi directly into the editor, without opening MathType Either way, after publishing the page, this is what the student will see:

using_latex5.png

So users see formulas and editors see LaTeX most of the time. Editors can edit visually a formula if they want.

This is a great feature, but please be aware that:

  • You must disable any other plugins that render LaTeX. For example, both Moodle and WordPress come with another TeX filter by default. You must choose which one you want; you cannot use both.

  • You cannot copy LaTeX documents directly to the application's editor. As a minimum, you must convert all single $ to double $$, and previously all double $$ to a centered paragraph. This is the standard format for embedded LaTeX, and most plugins expect this.

  • Not all LaTeX is supported. There are dozens of LaTeX commands, many of them dealing text formatting and unrelated to math. Therefore, MathType doesn't support these. Technically, we support the LaTeX instructions which have a MathML equivalent.

LaTeX is manipulated as MathML

Above, we describe the user experience, but what is important to note is that formulas are stored and displayed using MathML.

When the author or editor submits the content in the HTML editor (generally when previewing or publishing the page or module), MathType Integrations will search all $$ and convert the LaTeX into MathML. During this process, the plugin stores the MathML and the original LaTeX text written by the author. Thus, when displaying formulas the MathML conversion takes place.

diagram.png

LaTeX is stored inside MathML using the <semantics> and <annotation> elements. Using a simple example, the fraction 12<math data-element="math"><semantics data-element="semantics"><mrow data-element="mrow"><mfrac data-element="mfrac"><mn data-element="mn">1</mn><mn data-element="mn">2</mn></mfrac></mrow><annotation data-element="annotation" data-attr-encoding="LaTeX"> \frac12</annotation></semantics></math>, we have this MathML code block:

<math xmlns="http://www.w3.org/1998/Math/MathML">
   <semantics>
      <mfrac><mn>1</mn><mn>2</mn></mfrac>
      <annotation encoding="LaTeX">\frac12</annotation>
   </semantics>
</math>

When the HTML editor has been opened again, the stored LaTeX is recovered from the <semantics> tag and is displayed in the HTML editor area for further editing. What it is important to note is that this works even when the LaTeX cannot be converted into MathML. In that case, it is possible to edit the erroneous LaTeX to fix any potential error.

Supported LaTeX

The supported LaTeX is dependent on how well it can be translated from/to MathML. The limits are due to the following facts:

  • Some formulas have no MathML equivalent.

  • LaTeX is an extensible language with many non-official packages. To add to the difficulty, consider that it is possible in LaTeX to define custom characters and other adjustments.

  • On our website, you can see some examples of the current LaTeX supported.

  • These are the LaTeX commands that MathType supports

Disable this feature

It is possible to use LaTeX in our integrations as described on this page. Formulas by default are stored in the database as MathML with a LaTeX annotation, but you can control this behavior with the wiriseditorparselatex variable.

  • If set to true, LaTeX is parsed (i.e. stored in the database) as MathML with a LaTeX annotation.

    Example: 1+21+2 will be parsed/stored as:

    <html><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mn>1</mn><mo>+</mo><mn>2</mn><annotation encoding="LaTeX">1+2</annotation></semantics></math></html></html>

    MathType will render this MathML as a formula image.

  • If set to false, LaTeX is NOT parsed (i.e. stored in the database) as MathML.

    Example: 1+21+2 will be parsed/stored as:

    $$1+2$$

MathType will not render this LaTeX code as a formula image; a LaTeX renderer should be used.