Repository navigation
Description
System details
RStudio Edition : Desktop
RStudio Version : 1.4.869
OS Version : Windows 10 x64 (build 18363)
R Version : 4.0.2 (2020-06-22)
Steps to reproduce the problem
Creating a simple rmd file on source editor mode
---
title: "Generate number and reference equation"
output:
bookdown::html_document2
---
Sample equation from [Here](https://bookdown.org/yihui/bookdown/markdown-extensions-by-bookdown.html#equations)
\begin{equation}
f\left(k\right) = \binom{n}{k} p^k\left(1-p\right)^{n-k}
(\#eq:binom)
\end{equation}
As, we can see on equation \@ref(eq:binom) above..Describe the problem in detail
Now, when I first switch to visual rmarkdown editor, everything is fine. The code is as it is. Generate the same thing too.
The problem occurs when I switch back to source editor mode and switch again to visual mode.
Even when the code still the same, the output becomes an error in label and reference.
Notice the label number is disappear become label text, so the reference is in ??.
Then when I switch back to source editor mode, the code is changing (adding more backlash)
---
title: "Generate number and reference equation"
output:
bookdown::html_document2
---
Sample equation from [Here](https://bookdown.org/yihui/bookdown/markdown-extensions-by-bookdown.html#equations)
\begin{equation}
f\\left(k\\right) = \\binom{n}{k} p\^k\\left(1-p\\right)\^{n-k}
(\\\#eq:binom)
\\end{equation}
As, we can see on equation \@ref(eq:binom) above..And it seems broke after that. I can't generate an equation with number and reference anymore in visual mode.
I try to switch back again to editor mode, fixing the equation, and generate it. It works. But when I switched again to visual mode, generate it. It won't work.
Describe the behavior you expected
The equation number and reference still persist even when we switch back and forth from visual and source editor mode.
- I have read the guide for submitting good bug reports.
- I have installed the latest version of RStudio, and confirmed that the issue still persists.
- If I am reporting a RStudio crash, I have included a diagnostics report.
- I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.


Activity
[-]Switching back and forth from visual and editor mode makes number and reference equation broke.[/-][+]Switching back and forth from visual and editor mode makes number and reference equation broke. [bug] [/+][-]Switching back and forth from visual and editor mode makes number and reference equation broke. [bug] [/-][+]Switching back and forth from visual and editor mode makes number and reference equation broke.[/+]jjallaire commentedon Oct 19, 2020
Fixed via 0a04f35 (will appear in the next daily build, anything >= 1.4.950)
The issue was that pandoc was treating a multi-line
\begin{equation}block as a single raw inline token embedded in a paragraph. Since the editor doesn't have the concept of newlines embedded in a raw-inline mark, the mark was broken after the first line (and subsequently escaped when round-tripping).The fix is to treat a multi-line raw inline as a raw text block.
@irpanch Your code will now work correctly, however note that you might want to convert to using the
$...$or$$...$$syntax for LaTeX equations, as then pandoc and the visual editor will "know" that it's math and do inline preview, etc.It's possible I've misunderstood the use case / desired outcome here as I'm not myself a LaTeX math user -- in that case pls elucidate and we'll find the right fix.
cc @skeydan and @cderv Does this fix the issues you were seeing? (note that this fix won't appear until the next daily build)
@adamconroy Saw that you had self-assigned this. Ping me if you want to discuss the fix here and any alternatives you may have been considering.
adamconroy commentedon Oct 19, 2020
Verified as of commit 0a04f35 that multiline equations are now treated as raw blocks.
skeydan commentedon Oct 20, 2020
thanks @jjallaire - it's fixed!
setgree commentedon Mar 28, 2024
Hi there, I am encountering a similar issue when trying to reference R objects inline. Here's what I have (line 533 of this document)
switch to visual, and then back to source, and now I have
Note the extra slashes.
Shall I open a new issue? It looks like the same issue as this one
(I also get a lot of little red dot characters when I switch back and forth where there used to be spaces)
ronblum commentedon Mar 29, 2024
@setgree Thank you for the info! Yeah, can you please open a new issue for it? Thanks!