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
- Latex questions answered – BC Campus
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="<math xmlns="http://www.w3.org/1998/Math/MathML"><msup><mtext>Ba</mtext><mrow class="MJX-TeXAtom-ORD"><mn>2</mn><mo>+</mo></mrow></msup><mo stretchy="false">(</mo><mi>a</mi><mi>q</mi><mo stretchy="false">)</mo><mo>+</mo><msup><mrow class="MJX-TeXAtom-ORD"><msub><mtext>SO</mtext><mn>4</mn></msub></mrow><mrow class="MJX-TeXAtom-ORD"><mn>2</mn><mo>−</mo></mrow></msup><mo stretchy="false">(</mo><mi>a</mi><mi>q</mi><mo stretchy="false">)</mo><mo stretchy="false">→</mo><msub><mtext>BaSO</mtext><mn>4</mn></msub><mo stretchy="false">(</mo><mi>s</mi><mo stretchy="false">)</mo></math>"><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
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
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:
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
What it should look like:
Attribution
Except where otherwise noted, “Imported Latex math/equation issues” by Jen Booth is licensed under CC BY-NC 4.0.
Media Attributions
- missingarrows
- arrayalignment © Paul Flowers, Klaus Theopold, Richard Langley & William R. Robinson is licensed under a CC BY (Attribution) license
- code snippet with ampersand placement highlighted © Paul Flowers, Klaus Theopold, Richard Langley & William R. Robinson is licensed under a CC BY (Attribution) license
- latexissues © OpenStax is licensed under a CC BY (Attribution) license
- LatexinPB