这是我的线性模型代码
model = lm(UCBRpk~ pksa + dist)
summary(model)equatiomatic::extract_eq(model,wrap = TRUE)equatiomatic::extract_eq(model, wrap = TRUE,use_coefs = TRUE)我在编织html和pdf时得到了等式,但在word中却不能。
这是我每次编织到word时常见的错误消息。
unexpected "&"
expecting "%", "\\label", "\\nonumber" or whitespace
[WARNING] Could not convert TeX math '
\begin{aligned}
\operatorname{\widehat{SCBRcp}} &= 43.34 + 3.53(\operatorname{cpa}_{\operatorname{10\%}}) + 2.68(\operatorname{cpa}_{\operatorname{2\%}}) + 4.67(\operatorname{cpa}_{\operatorname{4\%}})\ + \\
&\quad 8.9(\operatorname{cpa}_{\operatorname{6\%}}) + 6.24(\operatorname{cpa}_{\operatorname{8\%}}) + 3.15(\operatorname{dist}_{\operatorname{A2}}) - 1.81(\operatorname{dist}_{\operatorname{A3}})
\end{aligned}
', rendering as TeX:
d}发布于 2021-06-10 23:31:16
tldr;
似乎是equatiomatic的一个bug;我建议打开一个问题。
问题在于由\operatorname生成的LaTeX代码中的equatiomatic调用。我不知道罪魁祸首是否是MathJax (因为表达式本身是有效的LaTeX),但是一个更小的再现问题的示例如下:
---
title: "Untitled"
output: word_document
---
$$
\begin{aligned}
\operatorname{\widehat{x}} &= a + b\ + \\
&\quad c + d
\end{aligned}
$$在编织时会产生以下警告
[WARNING] Could not convert TeX math '
\begin{aligned}
\operatorname{\widehat{x}} &= a + b\ + \\
&\quad c + d
\end{aligned}
', rendering as TeX:
ligned}
^
unexpected "&"
expecting "%", "\\label", "\\nonumber" or whitespace我不熟悉equatiomatic,但我( LaTeX )认为,将这些方程转换为LaTeX应该使用\mathrm而不是\operatorname (关于这两者之间的区别的讨论和示例,请参见What's the difference between \mathrm and \operatorname?;除其他外,\operatorname将标点符号视为文本,\mathrm则将它们视为数学符号。也许--我在这里100%地推测--这就是为什么equatiomatic开发者决定使用\operatorname而不是\mathrm)。
如果我用\operatorname替换所有\mathrm调用,则示例表达式编译得很好。
---
title: "Untitled"
output: word_document
---
$$
\begin{aligned}
\mathrm{\widehat{SCBRcp}} &= 43.34 + 3.53(\mathrm{cpa}_{\mathrm{10\%}}) + 2.68(\mathrm{cpa}_{\mathrm{2\%}}) + 4.67(\mathrm{cpa}_{\mathrm{4\%}})\ + \\
&\quad 8.9(\mathrm{cpa}_{\mathrm{6\%}}) + 6.24(\mathrm{cpa}_{\mathrm{8\%}}) + 3.15(\mathrm{dist}_{\mathrm{A2}}) - 1.81(\mathrm{dist}_{\mathrm{A3}})
\end{aligned}
$$

长话短说,你能做什么?除了手动编辑equatiomatic的输出之外,我建议在equatiomatic GH site上打开一个问题,并在堆栈溢出时交叉链接到这个帖子。
https://stackoverflow.com/questions/67929281
复制相似问题