Imported Latex math/equation issues

Pressbooks Set up – Before you Begin

Choose the correct plugin:

  • MathJax comes standard with Pressbooks via eCampus. This isn’t a plugin, you don’t have to enable it.
    • MathJax may case issues in PDF export if spacing is added where it shouldn’t be.
  • QuickLatex is the plugin visible to you under Plugins. Use as a last resort, as MathJax is considered more accessible

Resources

Troubleshooting & Adjusting Imported Content

Equations appear correctly in webbook, but do not render in the PDF export

  • This is usually an issue introduced by extra spaces within the equation
  • Compare a similar equation that is working correctly to the one that isn’t, or use a latex generator on the web to recreate the equation

Excessive lines code for a simple equation

  • If an editor has copied & pasted code from an OER that is using MathJax, you may encounter excessive amounts of code for a basic equation/statement
  • Options to remediate:
    • Import the page from the source, rather than copying & pasting from a browser view
    • View the source code for the original page – it will contain the latex code rather than MathJax rendering of it
      • Locate the latex equation in the source code
      • Copy & paste that into the TEXT view of your documnet
      • Adjust the latex operators if necessary
View a sample of problematic copy & paste of equations

Equation needed: K2SO4(aq) + Ba(NO3)2 (aq) → BaSO4(s) + 2KNO3(aq)

MathJax code used to render this equation:

<span id="MathJax-Element-5-Frame" class="mjx-chtml MathJax_CHTML" style="color: #000000; line-height: 0; text-indent: 0px; text-align: left; text-transform: none; font-style: normal; font-weight: normal; font-size: 16.968px; letter-spacing: normal; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; margin: 0px; padding: 1px 0px;" role="presentation" data-mathml="&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;msup&gt;&lt;mtext&gt;Ba&lt;/mtext&gt;&lt;mrow class=&quot;MJX-TeXAtom-ORD&quot;&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;/mrow&gt;&lt;/msup&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;q&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;msup&gt;&lt;mrow class=&quot;MJX-TeXAtom-ORD&quot;&gt;&lt;msub&gt;&lt;mtext&gt;SO&lt;/mtext&gt;&lt;mn&gt;4&lt;/mn&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;mrow class=&quot;MJX-TeXAtom-ORD&quot;&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;/mrow&gt;&lt;/msup&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;q&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo stretchy=&quot;false&quot;&gt;→&lt;/mo&gt;&lt;msub&gt;&lt;mtext&gt;BaSO&lt;/mtext&gt;&lt;mn&gt;4&lt;/mn&gt;&lt;/msub&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;/math&gt;"><span id="MJXc-Node-124" class="mjx-math" aria-hidden="true"><span id="MJXc-Node-125" class="mjx-mrow"><span id="MJXc-Node-126" class="mjx-msubsup"><span class="mjx-base"><span id="MJXc-Node-127" class="mjx-mtext"><span class="mjx-char MJXc-TeX-main-R">K</span></span></span><span class="mjx-sup"><span id="MJXc-Node-128" class="mjx-texatom"><span id="MJXc-Node-129" class="mjx-mrow"><span id="MJXc-Node-130" class="mjx-mn"><span class="mjx-char MJXc-TeX-main-R"><sub>2</sub>SO<sub>4</sub></span></span></span></span></span></span><span id="MJXc-Node-132" class="mjx-mo"><span class="mjx-char MJXc-TeX-main-R">(</span></span><em><span id="MJXc-Node-133" class="mjx-mi"><span class="mjx-char MJXc-TeX-math-I">a</span></span><span id="MJXc-Node-134" class="mjx-mi"><span class="mjx-char MJXc-TeX-math-I">q</span></span></em><span id="MJXc-Node-135" class="mjx-mo"><span class="mjx-char MJXc-TeX-main-R">) + Ba(NO<sub>3</sub>)<sub>2</sub> (<em>aq</em>) </span></span><span id="MJXc-Node-151" class="mjx-mo MJXc-space3"><span class="mjx-char MJXc-TeX-main-R">→ </span></span><span id="MJXc-Node-152" class="mjx-msubsup MJXc-space3"><span class="mjx-base"><span id="MJXc-Node-153" class="mjx-mtext"><span class="mjx-char MJXc-TeX-main-R">BaSO</span></span></span><sub><span class="mjx-sub"><span id="MJXc-Node-154" class="mjx-mn"><span class="mjx-char MJXc-TeX-main-R">4</span></span></span></sub></span><span id="MJXc-Node-155" class="mjx-mo"><span class="mjx-char MJXc-TeX-main-R">(</span></span><em><span id="MJXc-Node-156" class="mjx-mi"><span class="mjx-char MJXc-TeX-math-I">s</span></span></em><span id="MJXc-Node-157" class="mjx-mo"><span class="mjx-char MJXc-TeX-main-R">) + 2KNO<sub>3</sub>(<em>aq</em>)</span></span></span></span></span>

Actual HTML code needed:

K<sub>2</sub>SO<sub>4</sub>(<em>aq</em>) + Ba(NO<sub>3</sub>)<sub>2</sub> (<em>aq</em>) → BaSO<sub>4</sub>(s) + 2KNO<sub>3</sub>(<em>aq</em>)

Latex equivalent:

$latex K_{2}SO_{4}(aq) + Ba(NO_{3})_{2} (aq) → BaSO_{4}(s) + 2KNO_{3}(aq)$

Reduce the font size of a latex equation

Wrap the equation in a command to change the font size, by adding code as highlighted below:

  • $latex {\scriptsize \text{formal charge} = \# \;\text{valence shell electrons (free atom)} \; – \;\# \;\text{lone pair electrons}\; – \frac{1}{2} \# \;\text{bonding electrons} \scriptsize} $
  • List of options & commands at: LaTeX font size (not all tested/working)
    • Confirmed working: normalsize, scriptsize

Missing harpoons or long arrows

The command for leftrightharpoons or longarrow needs to appear twice for each line in an array. The second time it’s added, it does not have curly brackets, just a slash and the term where you want it to appear – usually after an &.

See missing arrows code snippets
Screenshot source: 18.5 Batteries and Fuel Cells In Enhanced Introductory College Chemistry, license tba.

Alignment of Equations

To align an array of equations at a particular point in the line (eg: a particular operator), you need to surround the part you want to centre with & part &.

See alignment example code

 

Screenshot source: “13.2 Equilibrium Constants” In General Chemistry 1 & 2 by Rice University, a derivative of Chemistry (Open Stax) by Paul Flowers, Klaus Theopold, Richard Langley & William R. Robinson and is licensed under CC BY 4.0. ​Access for free at Chemistry (OpenStax)
In the Latex code, the operator “ampersand” is used to indicate what elements should line up. It looks like & K_c &  in the code snippet (below), and occurs on each line of the array. There are spaces between the ampersand and the letters, and the result is the first equation in the image above – each line is aligned by the Kc. 
Screenshot source: “13.2 Equilibrium Constants” In General Chemistry 1 & 2 by Rice University, a derivative of Chemistry (Open Stax) by Paul Flowers, Klaus Theopold, Richard Langley & William R. Robinson and is licensed under CC BY 4.0. ​Access for free at Chemistry (OpenStax)

Troubleshooting Latex display – Using $ to indicate a dollar amount

In this version of Latex, the $ symbol is used to signify math content/equations. If you look in the Pressbooks version of this activity, the $ symbol being used to indicate dollars/cost per gallon is causing the Latex to break. To fix this issue, enter the dollar amounts as:

\$3.80

The \ before the $ symbol tells Pressbooks to read it as a symbol, not as an equation. Latex uses / to indicate it’s starting an equation.

Save the file, reload your preview and your issue should be fixed (until the next $ appears).

See screenshots/examples of $ issues
Exercise from “1.6 Mathematical Treatment of Measurement Results, In Chemistry 2e (Open Stax) by Paul Flowers, Klaus Theopold, Richard Langley & William R. Robinson is licensed under CC BY 4.0

What it should look like:

Exercise from “1.6 Mathematical Treatment of Measurement Results, In Chemistry 2e (Open Stax) by Paul Flowers, Klaus Theopold, Richard Langley & William R. Robinson is licensed under CC BY 4.0

Attribution

Except where otherwise noted, “Imported Latex math/equation issues” by Jen Booth is licensed under CC BY-NC 4.0.

Media Attributions

License

Share This Book