davidgohel / flextable

table farming
https://ardata-fr.github.io/flextable-book/
544 stars 78 forks source link

Mathematical fonts are being ignored #622

Open PaulRegular opened 2 months ago

PaulRegular commented 2 months ago

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.

davidgohel commented 2 months ago

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.

PaulRegular commented 2 months ago

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{})