Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkgdown 2.1.0 prevents \eqn{} and \deqn{} math rendering on function reference pages under Bootstrap 5 #2704

Open
nanxstats opened this issue Jul 8, 2024 · 14 comments
Labels
bug an unexpected problem or unintended behavior

Comments

@nanxstats
Copy link

Minimal reproducible example

#' Example
#'
#' @param x \eqn{f(x) > 0}: inline equation
#'
#' @details
#' Display equation:
#'
#' \deqn{y = \alpha + \beta X + \varepsilon}
#'
#' @export
f <- function(x) NULL

and set

template:
  bootstrap: 5

in _pkgdown.yml.

pkgdown 2.1.0 + Bootstrap 5

Expand screenshot Screenshot 2024-07-08 at 4 17 57 PM

pkgdown 2.0.9 + Bootstrap 5

Expand screenshot Screenshot 2024-07-08 at 4 20 27 PM
@hadley
Copy link
Member

hadley commented Jul 9, 2024

Hmmm, I wonder what's different between your example and https://pkgdown.r-lib.org/articles/test/rendering.html#math

...

Oh maybe because it's an example, and we don't seem to have a test for math rendering in examples :(

@cgiachalis
Copy link

cgiachalis commented Aug 8, 2024

@nanxstats Did you try setting the previous default, e.g. mathjax. That's solved my problem at least.

template:
  bootstrap: 5
  math-rendering: mathjax

@jayhesselberth
Copy link
Collaborator

Confirmed, setting math-rendering: mathjax fixes this issue.

We should try to figure out why mathml (which is now the default) doesn't work.

@cgiachalis
Copy link

Just to mention that the rendering is not what is used to be. I see different fonts as reported in #2739.

Right clicking on the equation -> About MathJax, I get the following:

Current version
Screenshot 2024-08-08 at 16-48-46 356247653-d3f2b46e-10

Before v2.1.0
Screenshot 2024-08-08 at 16-42-06 Diversification Ratio

@cgiachalis
Copy link

cgiachalis commented Aug 8, 2024

And the answer is here:
https://docs.mathjax.org/en/latest/upgrading/v2.html#not-yet-ported-to-version-3

The MathJax v3 output jax currently only support one font, the MathJax TeX fonts. Improved font support is an important goal for version 3, and this is one of the next features to be addressed. We will be rebuilding the fonts used for MathJax, and making additional web fonts available in a future release. We also plan to make the tools used for creating the necessary font data available for use in porting your own fonts for use with MathJax.

So by upgrading mathjax to v3.2.2, we don't get web TeX fonts..

@nanxstats
Copy link
Author

nanxstats commented Aug 8, 2024

This is how math rendering looks like using math-rendering: "mathjax" under pkgdown 2.1.0 (reproduced under both macOS and Windows):

Expand screenshot mathjax

Maybe it's because the MathJaX fonts are missing, from all the 404s in network requests:

Expand screenshot mathjax-fonts

Since it's tricky to side-load the MathJax fonts (originally defined in JS), my current workaround is to use the katex option and side-load the KaTeX fonts (also missing from pkgdown) using pkgdown/extra.css. Example: keaven/gsDesign#161

I'm not in a place to suggest anything on the font situation, but it would be very useful to have math rendering working again on function reference pages for all engine types.

@jayhesselberth
Copy link
Collaborator

@nanxstats Do you know if there is a CDN source for katex / Mathjax fonts? If so we could include them in the dependencies:

math_dependency <- function(pkg, call = caller_env()) {
math <- config_math_rendering(pkg)
if (math == "mathjax") {
cached_dependency(
name = "MathJax",
version = "3.2.2",
files = list(
list(
url = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-chtml.min.js",
integrity = "sha512-T8xxpazDtODy3WOP/c6hvQI2O9UPdARlDWE0CvH1Cfqc0TXZF6GZcEKL7tIR8VbfS/7s/J6C+VOqrD6hIo++vQ=="
)
)
)
} else if (math == "katex") {
cached_dependency(
name = "KaTex",
version = "0.16.10",
files = list(
list(
url = "https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js",
integrity = "sha384-hIoBPJpTUs74ddyc4bFZSM1TVlQDA60VBbJS0oA934VSz82sBx1X7kSx2ATBDIyd"
),
list(
url = "https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css",
integrity = "sha384-wcIxkf4k558AjM3Yz3BBFQUbk/zgIYC2R0QpeeYb+TwlBVMrlgLqwRjRtGZiK7ww"
)
)
)
} else {
NULL
}
}

We're probably not going to bundle math fonts in pkgdown itself.

@cgiachalis
Copy link

Indeed, katex option didn't work either out of the box.

Thanks for confirming @nanxstats .

@jayhesselberth
Copy link
Collaborator

jayhesselberth commented Aug 8, 2024

Would we expect inclusion of these fonts from cdnjs to have an effect? These could be added to the mathjax dependencies. There are also SVG fonts, not sure which we'd need.

It's also a little puzzling why katex fonts aren't included in the dependencies we are already listing. I can't find a reference to need a separate katex font download.

@nanxstats
Copy link
Author

@jayhesselberth I will let the MathJax experts comment on what should be used.

For KaTeX, I think you can add these 60 fonts files as "cached dependency" (may not look pretty...). It didn't work before probably because the CSS file is cached locally and distributed with the pkgdown site. It contains relative font paths that are interpreted as the pkgdown site instead of the CDN site.

@jayhesselberth
Copy link
Collaborator

If we're going to need to include many external font dependencies for katex / mathjax, we may need to go back to the yaml format that was originally in #2249.

@louisaslett
Copy link

I've hit this issue just now, and felt it was a bit much work to include all the font files manually although that was a cool solution given above. My slightly hacky approach is just to remove the math-rendering: katex completely and inject the official KaTeX starter template headers directly, which uses the CDN for everything:

template:
  bootstrap: 5
  includes:
    in_header: |
      <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" integrity="sha384-nB0miv6/jRmo5UMMR1wu3Gz6NLsoTkbqJghGIsx//Rlm+ZU03BU6SQNC66uf4l5+" crossorigin="anonymous">
      <script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js" integrity="sha384-7zkQWkzuo3B5mTepMUcHkMB5jZaolc2xDwL6VFqjFALcbeS9Ggm/Yr2r3Dy4lfFg" crossorigin="anonymous"></script>
      <script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/auto-render.min.js" integrity="sha384-43gviWU0YVjaDtb/GhzOouOXtZMP/7XUzwPTstBeZFe/+rCMvRwr4yROQP43s0Xk" crossorigin="anonymous" onload="renderMathInElement(document.body);"></script>

I found this "just worked" for now thankfully, though it'd be really nice to have this fixed (ideally with option not to use CDN) so that the math-rendering: katex is all we need.

@MLopez-Ibanez
Copy link

A math-heavy example that used to work until recently: https://mlopez-ibanez.github.io/eaf/reference/igd.html

@jeffreyhanson
Copy link

jeffreyhanson commented Sep 30, 2024

Just in case this is useful or if anyone else runs into this issue, I noticed that using math-rendering: mathjax doesn't seem to entirely work for multi-line equations. For example, here's a multi-line equation and how it renders in Google Chrome for me.

#' \deqn{\mathit{Minimize} \space l \\
#' \mathit{subject \space to} \\
#' \sum_{i = 1}^{I} x_i r_{ij} + y_j \geq t_j \forall j \in J \\
#' l \geq \frac{y_j}{t_j} \forall j \in J \\
#' \sum_{i = 1}^{I} x_i c_i \leq B}{
#' Minimize l subject to
#' sum_i^I (xi * rij) + yj >= tj for all j in J &
#' l >= (yj / tj) for all j in J &
#' sum_i^I (xi * ci) <= B}

image

As we can see, all of the equations appear on the same line, instead of appearing on separate lines (per pkgdown 2.0.9).

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

8 participants