Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for LaTeX equation cases is needed #57

Open
3 tasks done
N0rbert opened this issue Oct 14, 2021 · 2 comments
Open
3 tasks done

Support for LaTeX equation cases is needed #57

N0rbert opened this issue Oct 14, 2021 · 2 comments

Comments

@N0rbert
Copy link

N0rbert commented Oct 14, 2021

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 have fully read the issue guide at https://yihui.org/issue/.
  • I have provided the necessary information about my issue.
    • If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
    • If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included xfun::session_info('xaringan'). I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: remotes::install_github('yihui/xaringan').
    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.
  • I have learned the Github Markdown syntax, and formatted my issue correctly.

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

@N0rbert N0rbert changed the title Support for equation cases Support for LaTeX equation cases is needed Oct 14, 2021
@gadenbuie
Copy link

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
Copy link
Owner

yihui commented Oct 14, 2021

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):

xfun/R/markdown.R

Lines 95 to 101 in ca981bf

# equation environments (\begin and \end must be matched)
i1 = grep('^\\\\begin\\{[^}]+\\}$', x)
i2 = grep('^\\\\end\\{[^}]+\\}$', x)
if (length(i1) == length(i2)) {
x[i1] = paste0('`', x[i1])
x[i2] = paste0(x[i2], '`')
}

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}

@yihui yihui transferred this issue from yihui/xaringan Oct 14, 2021
yihui added a commit that referenced this issue Oct 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants