flextable icon indicating copy to clipboard operation
flextable copied to clipboard

Mathematical fonts are being ignored

Open PaulRegular opened this issue 10 months ago • 2 comments

I'm not sure whether this is an equatags or flextable issue; however, mathematical fonts aside from mathnormal, mathrm and mathbf are not rendering:

eqs <- c(
  "3x^2 \\in R \\subset Q",
  "\\mathnormal{3x^2 \\in R \\subset Q}",
  "\\mathrm{3x^2 \\in R \\subset Q}",
  "\\mathbf{3x^2 \\in R \\subset Q}",
  "\\mathsf{3x^2 \\in R \\subset Q}",
  "\\mathtt{3x^2 \\in R \\subset Q}",
  "\\mathfrak{3x^2 \\in R \\subset Q}"
)
df <- data.frame(formula = eqs)
df


ft <- flextable(df)
ft <- compose(
  x = ft, j = "formula",
  value = as_paragraph(as_equation(formula, width = 2, height = .5))
)
ft <- align(ft, align = "center", part = "all")
ft <- width(ft, width = 2)
ft

image

I'm using flextable 0.9.4 and equatags 0.2.0.

PaulRegular avatar Apr 10 '24 12:04 PaulRegular

Don't worry, the two packages are closely interrelated.

Basically, you want to be able to change colors, fonts, etc in equations created with as_equation()? What do you mean by "Mathematical fonts".

We can try to reduce the limitations, but I'm not sure that some of them (especially those related to HTML) can be overcome.

davidgohel avatar Apr 12 '24 07:04 davidgohel

I am by no means well versed with latex equations (or math), but there are options to apply different styles: https://www.overleaf.com/learn/latex/Mathematical_fonts. These styles are sometimes applied to follow specific notation conventions. I also know little about how all of this is translated in the background, especially in an HTML context, but it looks like Rmarkdown applies the fonts via (I presume) pandoc and MathJax.

---
output: html_document
---

**Formula**

$3x^2 \in R \subset Q$  
$\mathrm{3x^2 \in R \subset Q}$  
$\mathbf{3x^2 \in R \subset Q}$  
$\mathsf{3x^2 \in R \subset Q}$  
$\mathtt{3x^2 \in R \subset Q}$  
$\mathfrak{3x^2 \in R \subset Q}$  
$\mathbb{3x^2 \in R \subset Q}$

image

(...though, it doesn't like \mathnormal{})

PaulRegular avatar Apr 12 '24 14:04 PaulRegular