Problems rendering math in bookdown

I am experimenting with inline math using the rstudioaddin menu, which to me seems to be standard inline R Markdown math. I'm just running the bookdown-demo, but nothing seems to work.

Here is my code snippet (well, actually YiHui's):

title: "A Minimal Book Example"
author: "Yihui Xie"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
output: bookdown::gitbook
documentclass: book
bibliography: [book.bib, packages.bib]
biblio-style: apalike
link-citations: yes
github-repo: rstudio/bookdown-demo
description: "This is a minimal example of using the bookdown package to write a book. The output format for this example is bookdown::gitbook."

# Prerequisites

This is a _sample_ book written in **Markdown**. You can use $E=mc^2$ anything that Pandoc's Markdown supports, e.g., a math equation $a^2 + b^2 = c^2$.

This is what is generated, both with "knitr" and with "render":

This is a sample book written in Markdown . You can use (E=mc^2) anything that Pandoc’s Markdown supports, e.g., a math equation (a^2 + b^2 = c^2).

Everything else in the demo works well. I've similarly put together my own book, and formatting, rendering, citations, everything but the inline math seems to work.

I'd appreciate any suggestions on how I might resolve this. Thanks

1 Like


Math equation in html use Mathjax. Is the library loaded by your browser?

BTW, always check the html output with your "real" browser. The preview from RStudio sometimes fails.



Thank you jm-t for the quick response. This was my first inclination, but I'm using RStudio, and Mathjax is loded with the loading of RMarkdown (I have installed the latest from GitHub). Unfortunately, I don't seem to be able to get the math to work on html or pdf output.

I was curious whether I needed to install it on Ubuntu 18, but their seems not to be a copy in the repository (everything is on GitHub). I'm stumped at this point, though I'm not an expert as I am just transitioning to Ubuntu from OSX.

Any assistance would be greatly appreciated. Thanks, Chris

Hi Chris.

Mathjax is used for html rendering. Latex is used for the PDF rendering.

Mathjax is a js library required by the client browser. I think it has not part in the compilation. The library will interpret latex like syntax in the page body and displays picture generated by javascript.

Latex uses some package to render equation to PDF. This is done as compilation time. So it should fails at that moment. I am not a Latex expert and have limited experience with it so I might be wrong.

I can't help you much beyond that.


1 Like

Thanks jm_t. I still haven't figured out what the issue is with my machines. I have three different Ubuntu installations, and none of them seem to be able to render math, either inside R-Studio or in the generated HTML, PDF, etc. I may try a bookdown setup on OSX to see if I have any different results.



I've tried this on OS X with no problems, so the issue seems to be Ubuntu specific I would guess. YiHui Xie wrote his book around an OS X implementation of bookdown, so perhaps there is something installed automatically on OS X that is missing from Ubuntu.

I suspect there is something missing.

Hi JD:
Thank you for the heads up; but I did do an install of MathJax, and the test pages in the test subdirectory work properly (see attached). Do I need to somehow make the MathJax directory available to RStudio??



I was sure mathjax install was your problem. But I was surely wrong!

Have you tried opening the HTML document you generate using another computer? I suspect it will open just fine, but if it didn't that would tell you that the problem is with document creation, not document rendering.

Hi JD:

I rendered and then opened the HTML file on my iMac ... worked perfectly. Maybe I'll just run this on my Mac rather than Ubuntu, but would you have any idea why the Chrome browser wouldn't render this properly?




Sorry, I did just render this in Chrome on Ubuntu and it works. It seems that whatever RStudio is opening automatically doesn't render the math. I'll look around a bit further, but I would be happy to hear any of your suggestions.



glad you got it (mostly) worked out.

Ubuntu has its own mini-browser (who knew) which seems to be the default setup. I just deleted that, and Rstudio now forces Chrome to display HTML (properly). Thanks for your help, Chris


If your question's been answered (even if by you), would you mind choosing a solution? (See FAQ below for how).

Having questions checked as resolved makes it a bit easier to navigate the site visually and see which threads still need help.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.