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

[FR] Options for equations #2157

Closed
ForceBru opened this issue Jun 3, 2021 · 5 comments
Closed

[FR] Options for equations #2157

ForceBru opened this issue Jun 3, 2021 · 5 comments
Labels
duplicate already another issue about this

Comments

@ForceBru
Copy link

ForceBru commented Jun 3, 2021

I found myself struggling to number equations and stumbled upon this post on Stack Overflow and was led to the corresponding chapter in "Authoring Books with R Markdown", which says that numbering equations can be done by putting them in the LaTeX equation environment:

\begin{equation} 
  x=y
\end{equation} 

The issue

The problem I see with this is that by using raw LaTeX, I seem to forego the very useful preview in RStudio:

preview

I don't get this when using raw LaTeX:

no_preview

I can't visualize the equation by looking at LaTeX code (which quickly gets messy), so the lack of preview means that I'll be writing LaTeX and recompiling the project all the time to check whether the math is correct.

If I try to surround the equation with the equation environment, like this:

$$
\begin{equation}
...
\end{equation}
$$

...it gets compiled to incorrect LaTeX (well, not incorrect, but that's not what I wanted):

\[
\begin{equation}
p(y|x) = q(y|x) \alpha = q(y|x) \min \left\{
  \frac{\pi(y)}{\pi(x)} \frac{q(x|y)}{q(y|x)}, 1
\right\}
\end{equation}
\]

I half-expected the \[\] environment to be entirely replaced by \begin{equation}\end{equation}, but I guess it makes sense that it wasn't.

A potential solution

You can provide arguments to code blocks:

```{r my_arg=TRUE, another_arg="something"}
```

Theorems use the same syntax.

So maybe it could be useful to introduce similar syntax for equations as well?

For instance, this:

$${environment="equation"}
\pi = 3
$$

...would generate this LaTeX:

\begin{equation}
\pi = 3
\end{equation}

Other options may include:

  • custom numbering (like tag=2), instead of writing \tag{the_tag})
  • labels (like label="my_label"), instead of (\#eq:binom)), where, according to the book, the eq: prefix is mandatory, which is weird: why have a mandatory prefix?
  • options specific to output formats other than LaTeX.
@cderv
Copy link
Collaborator

cderv commented Jun 3, 2021

I suppose you are using this for PDF output ?

I think this is related to the idea in rstudio/bookdown#959
The referencing mechanism is in bookdown currently so it would happen there.

Does the bookdown issue cover your idea ?

@ForceBru
Copy link
Author

ForceBru commented Jun 3, 2021

Indeed, the idea in that issue is pretty close to what I had in mind. I was thinking maybe standard Rmarkdown could support this, since it already supports options for code, so options for math would be logical to have. But if Bookdown is already working on similar features (like here, I think: rstudio/bookdown#940), I guess my request is pretty much a duplicate

@yihui
Copy link
Member

yihui commented Jun 3, 2021

The problem I see with this is that by using raw LaTeX, I seem to forego the very useful preview in RStudio:

Duplicate of rstudio/rstudio#5264

@cderv
Copy link
Collaborator

cderv commented Dec 23, 2021

As Yihui shared I think the underlying issue is a preview support for environment inside the RStudio IDE rstudio/rstudio#5264

Once that will be supported, it will be possible to have the preview.

Otherwise, support for numbering equation using a syntax like

$$
math
$$ {#eq:label}

is followed in rstudio/bookdown#959

I'll close this hear to keep our tracking board simpler. Thanks !

@cderv cderv closed this as completed Dec 23, 2021
@cderv cderv added the duplicate already another issue about this label Dec 23, 2021
@github-actions
Copy link

github-actions bot commented Jul 5, 2022

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate already another issue about this
Projects
None yet
Development

No branches or pull requests

3 participants