Escaped underscores in math mode not displayed correctly
pkgdown does not seem to display escaped underscores in math equations correctly: In this "Details" section, it is displayed as \_ (at nterms\_max), but it should be displayed as _. The HTML help within RStudio and also the PDF display underscores correctly.
According to the suggestions here, I also tried \char`_ and \detokenize{}, but neither helped.
I tried \mathrm{nterms\_max} from https://github.com/mathjax/MathJax/issues/1770 which seems to work

However even if it works for you it'd still be a quick fix and it'd be nice to understand why it is so. :sweat_smile:
(that screenshot is from a "test" pkgdown website)
Thanks! I'm not a TeX expert, but isn't \mathrm{} a different font family than typewriter font (in the screenshot, nterms_max also doesn't seem to be in typewriter font)?
And sorry—I should have mentioned directly in the first comment that I'd like to have nterms_max in typewriter font.
I have a explored a bit more but am stuck.
I thought it might help to add Pandoc conversion from LaTeX to HTML to https://github.com/r-lib/pkgdown/blob/c354aa7e5ea1f9936692494c28c89e5bdd31fc68/R/rd-html.R#L117 (so very specific to the equation tag) with the mathjax option.
as_html.tag_eqn <- function(x, ...) {
latex_rep <- x[[1]]
mathjaxify(sprintf("$%s$", latex_rep))
}
mathjaxify <- function(tex) {
input <- withr::local_tempfile(fileext = ".tex")
output <- withr::local_tempfile(fileext = ".html")
write_lines(tex, input)
pandoc::pandoc_convert(
file = input,
args = "--mathjax",
to = "html",
from = "latex",
output = output
)
paste(read_lines(output), collapse = "\n")
}
However doing so I entered backslash hell a bit like in https://github.com/STAT545-UBC/Discussion/issues/394
The reason why I thought it might help to add the Pandoc parsing of LaTeX earlier is that it's what happens for articles, and maybe soon for the README #2263
I'll leave this aside now, sorry to not be of more help. :sweat_smile:
No problem, thanks for investigating this! I think for now, I'll leave it as-is.
Given that https://github.com/mathjax/MathJax/issues/1770 suggests it's a pkgdown limitation, there's a workaround (via \mathm{}, albeit imperfect), and it doesn't seem to affect too many people, I think it's unlikely this will ever rise to the top of our to do list. So I'm going to close it, but the issue is still indexed by google, so if other people hit it, they'll be able to find it, and we can consider reopen it if it turns out to be a common problem. Thanks for reporting and I'm sorry we couldn't help more 😞.