Abhi-1U / texor

Converting 'LaTeX' 'R Journal' Articles into 'RJ-web-articles'
https://abhi-1u.github.io/texor/
Other
7 stars 2 forks source link

Mismanagement of KaTeX #92

Closed hturner closed 1 month ago

hturner commented 2 months ago

Currently running rnw_to_rmd creates a folder storing all the KaTeX Javascript and font files. These are embedded in the HTML when it is rendered, creating a large file, even though the HTML does not use KaTeX!

Example:

## copy source files for the {parallel} package vignette to a local folder
article_dir <- "rnw_to_rmd"
dir.create(article_dir)
file.copy(system.file(file.path("doc", "parallel.Rnw"), package = "parallel"),
          file.path(article_dir ,  "parallel.Rnw"))
download.file("https://svn.r-project.org/R/trunk/src/library/parallel/vignettes/parallel.bib",
              file.path(article_dir , "parallel.bib"))

## convert to Rmd
texor::rnw_to_rmd(normalizePath(file.path(article_dir,  "parallel.Rnw")),
  front_matter_type = "vignettes",
  clean_up = TRUE,
  autonumber_eq = TRUE,
  autonumber_sec = TRUE)

## render 
rmarkdown::render(file.path(article_dir, "parallel.Rmd"))
browseURL(normalizePath(file.path(article_dir, "parallel.html")))

The conversion works quite well, but produces an HTML file that is 1.6MB. Deleting all the KaTeX code from the HTML file reduces the files size to 92KB and makes not difference to the output.

The same is true if you update the YAML in the .Rmd to use use KaTeX:

output:
  bookdown::html_document2:
    base_format: rmarkdown::html_vignette
    number_sections: no
    math_method: "katex"

the only difference is that the math renders offline and the equation numbering/referencing doesn't work, as expected (see #90).

So we need to avoid copying/including all these unnecessary KaTeX files.

Abhi-1U commented 1 month ago

I have removed the mechanism to include katex library with the converted article in this commit (064ff8efa27c54d1b6f491da03824298bedb9ff7). Also added the math_method option for katex if autonumber_eq is FALSE, otherwise it would be mathjax as mentioned in #90