yihui / xfun

Miscellaneous R functions
https://yihui.org/xfun/
Other
135 stars 28 forks source link

Support for LaTeX equation cases is needed #57

Open N0rbert opened 2 years ago

N0rbert commented 2 years ago

Below is the minimal reproducible example:

---
title: "Latex Cases"
output:
  bookdown::pdf_document2: default
  xaringan::moon_reader:
    lib_dir: libs
    nature:
      highlightStyle: github
      highlightLines: true
      countIncrementalSlides: false
---

\begin{equation}
\begin{cases}
\Delta_{0}=0,3\Delta_{1}+0,3\Delta_{0} \\ 
\Delta_{1}-5=0,2\Delta_{1}-0,2\Delta_{0}
\end{cases}
\end{equation}

It uses Cases inside Equation environment. Rendering is successful for PDF -

cases-pdf

but Xaringan does not render it

cases-xaringan

Details about system:

> xfun::session_info('xaringan')
R version 3.4.4 (2018-03-15)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.6 LTS, RStudio 1.4.1717

Locale:
  LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=ru_RU.UTF-8       
  LC_COLLATE=en_US.UTF-8     LC_MONETARY=ru_RU.UTF-8    LC_MESSAGES=en_US.UTF-8   
  LC_PAPER=ru_RU.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
  LC_TELEPHONE=C             LC_MEASUREMENT=ru_RU.UTF-8 LC_IDENTIFICATION=C       

Package version:
  base64enc_0.1.3  digest_0.6.28    evaluate_0.14    fastmap_1.1.0    glue_1.4.2      
  graphics_3.4.4   grDevices_3.4.4  highr_0.9        htmltools_0.5.2  httpuv_1.6.3    
  jquerylib_0.1.4  jsonlite_1.7.2   knitr_1.36       later_1.3.0      magrittr_2.0.1  
  methods_3.4.4    mime_0.12        promises_1.2.0.1 R6_2.5.1         Rcpp_1.0.7      
  rlang_0.4.11     rmarkdown_2.11   servr_0.23       stats_3.4.4      stringi_1.7.4   
  stringr_1.4.0    tinytex_0.34     tools_3.4.4      utils_3.4.4      xaringan_0.22.1 
  xfun_0.26        yaml_2.2.1      

By filing an issue to this repo, I promise that

I understand that my issue may be closed if I don't fulfill my promises.

gadenbuie commented 2 years ago

From https://slides.yihui.org/xaringan/#16

The source code of a LaTeX math expression must be in one line, unless it is inside a pair of double dollar signs, in which case the starting $$ must appear in the very beginning of a line, followed immediately by a non-space character, and the ending $$ must be at the end of a line, led by a non-space character;

That said, I think there may be an issue in xaringan, because putting the \begin{equation} ... \end{equation} all on one line didn't work for me as expected.

---
title: "Latex Cases"
output:
  xaringan::moon_reader:
    seal: false
---

**Doesn't work...**

\begin{equation}
\begin{cases}
\Delta_{0}=0,3\Delta_{1}+0,3\Delta_{0} \\ 
\Delta_{1}-5=0,2\Delta_{1}-0,2\Delta_{0}
\end{cases}
\end{equation}

$$\begin{equation}
\begin{cases}
\Delta_{0}=0,3\Delta_{1}+0,3\Delta_{0} \\ 
\Delta_{1}-5=0,2\Delta_{1}-0,2\Delta_{0}
\end{cases}
\end{equation}$$

**I thought this would work according to xaringan docs**

\begin{equation}\begin{cases}\Delta_{0}=0,3\Delta_{1}+0,3\Delta_{0} \\ \Delta_{1}-5=0,2\Delta_{1}-0,2\Delta_{0}\end{cases}\end{equation}

**This does work!**

$\begin{equation}\begin{cases}\Delta_{0}=0,3\Delta_{1}+0,3\Delta_{0} \\ \Delta_{1}-5=0,2\Delta_{1}-0,2\Delta_{0}\end{cases}\end{equation}$
image
yihui commented 2 years ago

This is the same bug as reported here: https://stackoverflow.com/q/67076613/559676 The bug was from here (nested math environments don't work): https://github.com/yihui/xfun/blob/ca981bf7873b679d58873921069214ab37e13047/R/markdown.R#L95-L101

The workaround is to join \begin{cases} and \end{cases} with other lines like this:

\begin{equation}
\begin{cases}\Delta_{0}=0,3\Delta_{1}+0,3\Delta_{0} \\ 
\Delta_{1}-5=0,2\Delta_{1}-0,2\Delta_{0}\end{cases}
\end{equation}