I’m trying to input a latex formula in my book. For that, I have to use the symbol & within the formula, but whenever I input &, Pressbooks converts it into `&`

. This is fine for regular text, but not within a latex formula. Is there any way to avoid this?

Example:

I write:

```
\[
\begin{aligned}
\dot x
&= blah blah
&= blah blah
\end{aligned}
\]
```

It gets converted into:

```
\[
\begin{aligned}
\dot x
&= blah blah
&= blah blah
\end{aligned}
\]
```

Thanks a lot,

Luis

There is an issue also with the automatic conversion of > into `>`

and < into `<`

within latex formulas. These conversions do not represent a problem when the book is read in HTML, but in the PDF version is all a mess.

Luis, good to hear from you again! A few questions–are you using our native MathJax rendering solution or the WP QuickLaTeX plugin? What happens if you use `[latex]`

and `[/latex]`

as your delimiters instead of `\[`

and `\]`

? Also, if you can point us to a specific (public) chapter where the bug is occurring for you and/or a PDF export so we can see this in its full context, that will also help us understand the issue more quickly.

Hi Steel! Thanks so much for your quick and helpful answer, as always.

Using `[latex]`

and `[/latex]`

allowed me to use the environment `\begin{aligned*}`

, and that solved the issue. Thanks so much. I thought that `\[`

and `\]`

were equivalent to `[latex]`

and `[/latex]`

, but apparently they’re not (e.g. using `\begin{aligned*}`

within `\[`

and `\]`

throws an error). If you can provide a link to understand the difference, that would be great, but no worries if not. I’ll just use `[latex]`

and `[/latex]`

from now on.

As for the pdf issue, I cannot really understand it yet. This chapter:

https://wisc.pb.unizin.org/agent-based-evolutionary-game-dynamics/chapter/1-4/

contains several latex formulas that display correctly in HTML but the pdf is messed up (if you can, please download the pdf and search for “style”). I am writing the same formulas in a test chapter, and they appear correctly in the pdf. I’ll let you know if I can provide a MWE.

Thanks so much!

Luis

We recently switched out our core latex rendering engine: https://pressbooks.com/2019/07/10/mathjax-now-available-on-pressbooksedu/. See https://guide.pressbooks.com/chapter/equations-and-formulas/ for a bit more on how to effectively use it. We haven’t yet added support for other delimiters (like `\[`

) but hope to do so sometime soonish. It looks, however, like you’re using the WP Quick LaTeX plugin in your book. Don’t know if this is why you’re able to define additional environments/packages, etc. or if you need it for other reasons, but that plugin offers a number of other settings that might help with your issue? https://wisc.pb.unizin.org/agent-based-evolutionary-game-dynamics/wp-admin/admin.php?page=quicklatex-settings

If you want to debug the PDF export issues or see the difference between our native MathJax renderer and the WP QuickLaTEX plugin, you may want to try disabling the plugin and see whether that fixes your issues?

The only reason I use the WP Quick LaTeX is because I already had many formulas typed using the syntax $ $, and these do not display as latex if I deactivate the plugin. I’ll look into the links that you sent me and decide whether to change all these equations to $latex $.

I disabled the plugin and, even though the HTML version did change a lot (e.g. all the $$ equations were not shown as latex), the PDF did not change. I’ll keep on investigating tomorrow, but I am now very puzzled, since I cannot replicate the PDF issue in a test chapter where I am just copying and pasting the offending formulas…

Hi Luis,

I’ve looked at the PDF and see exactly what you’re describing. Very strange. Not sure what might be causing this at first glance. I did notice that many (though not all) of the issues were for math equations inside of shortcodes (whether for textboxes or footnotes). Perhaps that’s part of the issue?

You’re very right. I thought that too, but the first equation that fails is not inside any other shortcode, as far as I can tell. Thanks so much for getting so involved, I really appreciate it.

1 Like

Hi Steel,

I managed to isolate the problem. It seems like it has to do with the presence of a link before the latex formula. To be specific, the following code is fine:

```
imitate-if-better
[latex]a_k(0) = \mathbb{P}(X_k = 0 \,|\, X_0=0.5) > 0[/latex] for any [latex]k \ge 50[/latex].
```

i.e., it displays in the pdf as:

But if I turn the initial sentence into a link:

```
<a href="https://wisc.pb.unizin.org/agent-based-evolutionary-game-dynamics/chapter/1-0/#imitate-if-better-protocol">imitate-if-better</a>
[latex]a_k(0) = \mathbb{P}(X_k = 0 \,|\, X_0=0.5) > 0[/latex] for any [latex]k \ge 50[/latex].
```

then the formula does not display correctly in the pdf:

Any ideas?

Thanks a lot,

Luis

Hi Luis,

Thanks for additional detective work. This sounds like a promising lead for us to debug further. If you’re willing, would you be able to write this up as an issue in our MathJax repo: https://github.com/pressbooks/pb-mathjax/issues? Something like your last post with brief description, links and screenshots would be perfect. Thanks!