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:
title: "Untitled"
author: "Gerhard Burger"
date: "9/11/2020"
```{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} } $$
````

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)
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} $$
````

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
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').I understand that my issue may be closed if I don't fulfill my promises.
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}$$

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!
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.