Xaringan: Valid latex fails to render, but correct preview is shown in RStudio

Created on 11 Sep 2020  Â·  3Comments  Â·  Source: yihui/xaringan

I am trying to include the formula for pooled standard deviation in my xaringan presentation, but somehow it fails.

This is the equation: $$s_p = sqrt{ frac{ s_{X_1}^2 + s_{X_2}^2}{2} }$$
It shows the correct preview in RStudio, and also renders correctly using a 'simple' RMarkdown document:

````r

title: "Untitled"
author: "Gerhard Burger"
date: "9/11/2020"

output: html_document

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)

## R Markdown

$$ s_p = \sqrt{ \frac{ s_{X_1}^2 + s_{X_2}^2}{2} } $$

````
![Screenshot 2020-09-11 022649](https://user-images.githubusercontent.com/907362/92831134-58684200-f3d6-11ea-8e13-d3aa3f64fbc6.png)


however in xaringan it fails:

````r
---
title: "Presentation Ninja"
subtitle: "âš”<br/>with xaringan"
author: "Yihui Xie"
institute: "RStudio, PBC"
date: "2016/12/12 (updated: `r Sys.Date()`)"
output:
  xaringan::moon_reader:
    lib_dir: libs
    nature:
      highlightStyle: github
      highlightLines: true
      countIncrementalSlides: false
---


```{r setup, include=FALSE}
options(htmltools.dir.version = FALSE)

Xaringan test

Fails:

$$ s_p = sqrt{ frac{ s_{X_1}^2 + s_{X_2}^2}{2} } $$

but this works (without the subscripts for $X$)

$$ s_p = sqrt{ frac{ s_X^2 + s_X^2}{2} } $$

Minimal example that fails:

$$ s_{X_1} + s_{X_2} $$

But somehow single works:

$$ s_{X_1} $$
````
Screenshot 2020-09-11 022945

Do you have any idea what is going on?

My xfun::session_info():

R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19041), RStudio 1.3.1073

Locale:
  LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
  LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
  LC_TIME=English_United States.1252    
system code page: 65001

Package version:
  assertthat_0.2.1   backports_1.1.9    base64enc_0.1.3    BH_1.72.0.3        callr_3.4.4       
  cli_2.0.2          colorspace_1.4-1   compiler_4.0.2     crayon_1.3.4       desc_1.2.0        
  digest_0.6.25      dplyr_1.0.2        ellipsis_0.3.1     evaluate_0.14      fansi_0.4.1       
  farver_2.0.3       generics_0.0.2     ggplot2_3.3.2      glue_1.4.2         graphics_4.0.2    
  grDevices_4.0.2    grid_4.0.2         gtable_0.3.0       highr_0.8          htmltools_0.5.0   
  httpuv_1.5.4       isoband_0.2.2      jsonlite_1.7.1     knitr_1.29.5       labeling_0.3      
  later_1.1.0.1      lattice_0.20.41    lifecycle_0.2.0    magrittr_1.5       markdown_1.1      
  MASS_7.3.53        Matrix_1.2.18      memoise_1.1.0      methods_4.0.2      mgcv_1.8.33       
  mime_0.9           munsell_0.5.0      nlme_3.1.149       pacman_0.5.1       pillar_1.4.6      
  pkgbuild_1.1.0     pkgconfig_2.0.3    pkgload_1.1.0      praise_1.0.0       prettyunits_1.1.1 
  processx_3.4.4     promises_1.1.1     ps_1.3.4           purrr_0.3.4        R6_2.4.1          
  RColorBrewer_1.1.2 Rcpp_1.0.5         remotes_2.2.0      rlang_0.4.7        rmarkdown_2.3     
  rprojroot_1.3.2    rstudioapi_0.11    scales_1.1.1       servr_0.18         splines_4.0.2     
  stats_4.0.2        stringi_1.5.3      stringr_1.4.0      testthat_2.3.2     tibble_3.0.3      
  tidyselect_1.1.0   tinytex_0.25       tools_4.0.2        utf8_1.1.4         utils_4.0.2       
  vctrs_0.3.4        viridisLite_0.3.0  withr_2.2.0        xaringan_0.16      xfun_0.17         
  yaml_2.2.1        

By filing an issue to this repo, I promise that

  • [x] I have fully read the issue guide at https://yihui.org/issue/.
  • [x] I have provided the necessary information about my issue.

    • If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.

    • If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included xfun::session_info('xaringan'). I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: remotes::install_github('yihui/xaringan').

    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.

  • [x] I have learned the Github Markdown syntax, and formatted my issue correctly.

I understand that my issue may be closed if I don't fulfill my promises.

Most helpful comment

By the way, the markdown parser used by xaringan (markedjs) is different from the one used by R Markdown (pandoc) and this is a documented limitation of how LaTeX math expressions are handled in xaringan to work around limitations of markedjs.

All 3 comments

Have you tried removing the spaces between the expression and the $$? That seems to do the trick for me.

## Xaringan test

Fails:

$$s_p = \sqrt{ \frac{ s_{X_1}^2 + s_{X_2}^2}{2} }$$

but this works (without the subscripts for $X$)

$$s_p = \sqrt{ \frac{ s_X^2 + s_X^2}{2} }$$

Minimal example that fails:

$$s_{X_1} + s_{X_2}$$

But somehow single works:

$$s_{X_1}$$

image

By the way, the markdown parser used by xaringan (markedjs) is different from the one used by R Markdown (pandoc) and this is a documented limitation of how LaTeX math expressions are handled in xaringan to work around limitations of markedjs.

Thanks for your quick reply, that works perfectly!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

royfrancis picture royfrancis  Â·  4Comments

richardohrvall picture richardohrvall  Â·  3Comments

grawil picture grawil  Â·  4Comments

DavisVaughan picture DavisVaughan  Â·  3Comments

tcgriffith picture tcgriffith  Â·  4Comments