I am writing some multi-line equations in R Markdown - LaTeX, using auto-numbering and \begin{align}. Here's a working the example:
我正在使用自动编号和\ begin {align}在R Markdown - LaTeX中编写一些多线方程。这是一个工作示例:
---
title: "test"
output: html_document
---
(@eq01) $$
\begin{align}
y = x^2 \\
y = x^3 \\
y = \sqrt[2]{x}
\end{align}
$$
This works great when the output is html_document. Here's the result:
当输出为html_document时,这很有用。这是结果:
But when I change the output document to pdf:
但是当我将输出文档更改为pdf时:
output: pdf_document
I get the following error (I am using RStudio latest Version 0.98.1056):
我收到以下错误(我正在使用RStudio最新版本0.98.1056):
I've been trying to read the documentation as suggested in the error message, but I do not seem to get a handle on it. I've checked Stack Overflow and Google and although there are some related posts/questions (for example here, here, here), none of them solve the problem (or apply to my problem).
我一直在尝试按照错误消息中的建议阅读文档,但我似乎没有得到它的处理。我已经检查了Stack Overflow和谷歌,虽然有一些相关的帖子/问题(例如这里,这里,这里),但没有一个解决问题(或适用于我的问题)。
I've also tried to tweak everything. The most evident solution would be to get rid of the \begin{align} environment,
我也尝试过调整一切。最明显的解决方案是摆脱\ begin {align}环境,
(@eq01) $$
y = x^2 \\
y = x^3 \\
y = \sqrt[2]{x}
$$
but it does not work for two reasons. First, the html version does not work as nicely because the auto-numbering does not appear centered in the multi-line equation, but rather on the first line (and I don't like it like that).
但它有两个原因无效。首先,html版本不能很好地工作,因为自动编号不会出现在多线方程的中心,而是出现在第一行(我不喜欢它)。
Second, although the pdf version in this case does compile and produce the pdf, it does not recognize that it is a multi-line equation (it's like it does not recognize the new line command \).
其次,尽管这种情况下的pdf版本确实编译并生成了pdf,但它并不认识到它是一个多线方程(就像它不能识别新的线命令一样)。
Any ideas are really appreciated. I've been struggling with this for a while and I cannot find a solution. I kinda love R Markdown because it really integrates the analysis with writing and communicating in a single tool (rather than using many different tools going back and forth). However, it seems there is still a long way to go before we can write one single source file and that it renders appropriately in several different output formats.
任何想法都非常感谢。我一直在努力解决这个问题,我无法找到解决方案。我喜欢R Markdown,因为它真正将分析与写作和通信集成在一个工具中(而不是使用许多不同的工具来回)。但是,在我们编写单个源文件并且它以几种不同的输出格式正确呈现之前,似乎还有很长的路要走。
1 个解决方案
#1
37
I was receiving the same error when trying to send an aligned block to PDF. Try changing the following:
尝试将对齐的块发送到PDF时,我收到了同样的错误。尝试更改以下内容:
$$
\begin{align}
y = x^2 \\
y = x^3 \\
y = \sqrt[2]{x}
\end{align}
$$
to the following:
以下内容:
$$
\begin{aligned}
y = x^2 \\
y = x^3 \\
y = \sqrt[2]{x}
\end{aligned}
$$
\begin{align}
is a self-contained math environment, whereas \begin{aligned}
needs to be placed inside an existing math environment. Since Rmd delineates math sections with $$...$$
, it seems like \begin{align}
was trying to start a second math environment within the first and causing problems.
\ begin {align}是一个独立的数学环境,而\ begin {aligned}需要放在现有的数学环境中。由于Rmd用$$ ... $$描述数学部分,似乎\ begin {align}试图在第一个数学环境中启动第二个数学环境并导致问题。
#1
37
I was receiving the same error when trying to send an aligned block to PDF. Try changing the following:
尝试将对齐的块发送到PDF时,我收到了同样的错误。尝试更改以下内容:
$$
\begin{align}
y = x^2 \\
y = x^3 \\
y = \sqrt[2]{x}
\end{align}
$$
to the following:
以下内容:
$$
\begin{aligned}
y = x^2 \\
y = x^3 \\
y = \sqrt[2]{x}
\end{aligned}
$$
\begin{align}
is a self-contained math environment, whereas \begin{aligned}
needs to be placed inside an existing math environment. Since Rmd delineates math sections with $$...$$
, it seems like \begin{align}
was trying to start a second math environment within the first and causing problems.
\ begin {align}是一个独立的数学环境,而\ begin {aligned}需要放在现有的数学环境中。由于Rmd用$$ ... $$描述数学部分,似乎\ begin {align}试图在第一个数学环境中启动第二个数学环境并导致问题。