Skip to content

Commit

Permalink
Merge pull request #4 from SciViews/displayMode
Browse files Browse the repository at this point in the history
Argument display=FALSE to transform_mathjax() - inline/display equations
  • Loading branch information
davidgohel authored Jul 12, 2023
2 parents cf3a4c2 + 35bd17c commit 12f5656
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: equatags
Type: Package
Title: Equations to 'XML'
Version: 0.2.0
Version: 0.2.1
Authors@R: c(
person("David", "Gohel", role = c("aut", "cre"),
email = "david.gohel@ardata.fr"),
Expand All @@ -16,6 +16,6 @@ BugReports: https://github.com/ardata-fr/equatags/issues
License: MIT + file LICENSE
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.0
RoxygenNote: 7.2.3
Depends: R (>= 4.0.0)
Imports: xml2, xslt, tools, katex
8 changes: 6 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# equatags 0.2.1

\*.add a display= argument to transform_mathjax() to allow generating display or inline equations. It is set to FALSE by default (inline equation). This changes the behaviour that was previously to generate display equations only.

# equatags 0.2.0

* drop the node.js dependency in favor of package katex.
- drop the node.js dependency in favor of package katex.

# equatags 0.1.1

* use tools::R_user_dir instead of rappdirs::user_data_dir as it's a condition to keep the package on CRAN ("This is using ^~/.local/share/equatags , prohibited by the CRAN policy. Please replace the use of rappdirs by the allowed procedure documented there.")
- use tools::R_user_dir instead of rappdirs::user_data_dir as it's a condition to keep the package on CRAN ("This is using \^\~/.local/share/equatags , prohibited by the CRAN policy. Please replace the use of rappdirs by the allowed procedure documented there.")
7 changes: 5 additions & 2 deletions R/write_mathjax.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ xml_header <- "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
#' of 'MathJax' equations.
#' @param x MathJax equations
#' @param to output format, one of 'html' or 'mml'
#' @param display should the equation be in display (`TRUE`) or inline mode
#' (`FALSE`, by default)
#' @return a character vector that contains 'html' or 'mml'
#' codes corresponding to the equations.
#' @examples
Expand All @@ -31,7 +33,7 @@ xml_header <- "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
#' cat(z, sep = "\n\n")
#' @importFrom xml2 read_xml xml_children
#' @importFrom katex katex_mathml katex_html
transform_mathjax <- function(x, to = "html"){
transform_mathjax <- function(x, to = "html", display = FALSE){

if(length(x) < 1) return(character(0))
to <- match.arg(to, choices = c("html", "mml", "svg"), several.ok = FALSE)
Expand All @@ -43,7 +45,8 @@ transform_mathjax <- function(x, to = "html"){
info <- gsub("<span class=\"katex\">", "", info, fixed = TRUE)
info <- vapply(info, mml_to_ooml, FUN.VALUE = character(1L), USE.NAMES = FALSE)
} else {
info <- vapply(x, katex_html, "", preview = FALSE, include_css = TRUE)
info <- vapply(x, katex_html, "", preview = FALSE, include_css = TRUE,
displayMode = display)
names(info) <- NULL
}

Expand Down
5 changes: 4 additions & 1 deletion man/transform_mathjax.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 12f5656

Please sign in to comment.