6

In a package, I have several vignettes that use mathematical notation, like:

This vignette illustrates the ideas behind solving systems of linear equations of the form $\mathbf{A x = b}$
where 

- $\mathbf{A}$ is an $m \times n$ matrix of coefficients for $m$ equations in $n$ unknowns
- $\mathbf{x}$ is an $n \times 1$ vector unknowns, $x_1, x_2, \dots x_n$
- $\mathbf{b}$ is an $m \times 1$ vector of constants, the "right-hand sides" of the equations

When I compile the vignette using R Studio (Ctrl+Shift+K), it renders properly in the HTML file, whether viewed in the R Studio viewer or the browser.

enter image description here

Yet, when the package is submitted to CRAN, and the vignettes are built there from the source package, the math is not rendered properly, but appears as markup,

enter image description here

Is there something I need to add to my YAML header so that vignettes built outside of R Studio will render mathematics properly? Currently, I use just a standard header:

---
title: "Solving Linear Equations"
author: "Me"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Solving Linear Equations}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

The generated pandoc command from R Studio is

"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS linear-equations.utf8.md --to html --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output pandoc8141d044063.html --smart --email-obfuscation none --self-contained --standalone --section-divs --template "C:\R\R-3.2.5\library\rmarkdown\rmd\h\default.html" --css "C:\R\R-3.2.5\library\rmarkdown\rmarkdown\templates\html_vignette\resources\vignette.css" --mathjax --variable "mathjax-url:https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" --highlight-style pygments 

Perhaps I need to add a YAML option corresponding to --self-contained or --standalone ?

Keshan Nageswaran
  • 8,060
  • 3
  • 28
  • 45
user101089
  • 3,756
  • 1
  • 26
  • 53
  • CRAN does not rebuild your vignettes (unless they changed it in the past few weeks), and the vignettes displayed on CRAN are just what you submitted in your source package. Please at least provide a link to the problematic vignette. – Yihui Xie Oct 05 '16 at 20:59
  • I have the same problem with `devtools::install_github(...., build_vignettes=TRUE)`. Here is the vignette: https://github.com/stla/expansions/tree/master/vignettes (cc @Yihui). – Stéphane Laurent Jan 01 '17 at 04:21
  • Note from the future: cdn.mathjax.org is nearing its end-of-life, check https://www.mathjax.org/cdn-shutting-down/ for migration tips. – Peter Krautzberger Apr 11 '17 at 15:45
  • Now they are using a different endpoint: `` – Andry Jan 29 '20 at 21:23

1 Answers1

1

Posting years later in case another user has the same question. I noticed the same issues rendering equations in my vignettes---not on CRAN, just locally hosted packages. Ctrl + Shift + K rendered fine, but viewing with vignette() in the RStudio Help panel renders the equations badly.

I think this is just an issue that the Help panel doesn't render the HTML completely. If I view the packaged vignette in a browser, e.g. using RShowDoc(), then the equations are fine. So maybe users should be directed to RShowDoc() more often than vignette().

A Bev
  • 21
  • 1