公式编号与 Rmarkdown 中的预览到 pdf? [英] Equation numbering with previews in Rmarkdown to pdf?

查看:48
本文介绍了公式编号与 Rmarkdown 中的预览到 pdf?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Rmarkdown 中,编织到 PDF,如果我写一个类似

In Rmarkdown, knitting to PDF, if I write an equation like

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

然后我在 PDF 输出中得到一个编号的方程.

then I get a numbered equation in the PDF output.

如果我写一个像

$$ y=x^3 $$

那么方程没有编号.我喜欢能够控制哪些方程有编号,哪些没有,所以有两种方法可以做到,其中一种产生编号,这是很好的.但是,我用 \begin{}....\end{} 编写的方程在 Rstudio 的编辑器中没有渲染预览,而用 $$ 编写的方程...$$ 确实得到渲染.有没有办法在不丢失预览的情况下获得编号?

Then the equation isn't numbered. I like being able to control which equations are numbered and which aren't, so having two ways to do it, one of which produces numbering, is good. But, the equations that I write with \begin{}....\end{} don't get a rendered preview in the editor in Rstudio, while the equations written with $$...$$ do get rendered. Is there some way to get the numbering without losing the previewing?

推荐答案

Pandoc 自动将您的 $$ 分隔符更改为 LaTeX 风格的 \[\],所以如果你重新定义它们,你可以获得编号的方程.例如:

Pandoc automatically changes your $$ delimiters to LaTeX-style \[ and \], so if you redefine those, you can get numbered equations. For example:

---
output: pdf_document
---

\renewcommand{\[}{\begin{equation}}
\renewcommand{\]}{\end{equation}}

This equation is numbered:

$$
x = y^2
$$

This one isn't:

$$
x = y^3 \nonumber
$$

如果您使用的模板不能转换为 \[\],您可以自己输入这些,但 RStudio 的预览效果与这些不同,只显示弹出窗口,而不是静态预览.

If you are using some template that doesn't do the conversion to \[ and \] you can enter those yourself, but RStudio does previewing differently with those, just showing popups, not a static preview.

编辑添加:如果您希望默认值保持未编号,我认为没有与已定义的 \nonumber 相反.你可以用一个 LaTeX 宏来做这件事,或者如果只有几个编号的方程,只需使用 \tag{number} 手动完成,例如

Edited to add: If you want the default to remain unnumbered, I don't think there's an inverse to \nonumber already defined. You could probably work out a LaTeX macro to do it, or if there are only a few numbered equations, just do them manually using \tag{number}, e.g.

---
output: pdf_document
---

This equation is fixed as equation (2):

$$
x = y^2 \tag{2}
$$

This one isn't:

$$
x = y^3
$$

也许其他人也会让您知道如何进行自动编号.

Maybe someone else will let you know how to do auto-numbering as well.

这篇关于公式编号与 Rmarkdown 中的预览到 pdf?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆