着色LaTeX方程放在rmarkdown表中

时间:2014-07-05 23:17:44

标签: r latex knitr mathml r-markdown

在由rmarkdownknitr包创建的报告中,我想创建一个1乘2的表,其中每个单元将承载一个LaTeX方程。在等式中,单个元素必须是自定义颜色的选项,产生类似:

enter image description here

使用hmarkdown应该识别的html元素:

---
output:
  pdf_document: default
  html_document:
    mathjax: "http://example.com/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
---

### Two formulas side by side
<div style="width:900px">

<div style="width:450px">
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
 <semantics>
  <mrow>
   <msub style="color:red">
    <mi>y</mi>
    <mrow>
     <mi>t</mi><mi>i</mi></mrow>
   </msub>
   <mo>=</mo><msub>
    <mi>&#x03B2;</mi>
    <mn>0</mn>
   </msub>
   <mo>+</mo><msub style="color:red">
    <mi>&#x03B5;</mi>
    <mrow>
     <mi>t</mi><mi>i</mi></mrow>
   </msub>
   </mrow>
  </annotation>
 </semantics>
</math>

</div>

<div style="width:450px">
$$ 
{y_{ti}} = {\beta _0} + {\beta _1}Tim{e_t} + {\varepsilon _{ti}}
$$
</div>

</div>

编织html时,左边的等式错误: enter image description here

编织PDF时,右边错误的等式:

! Package inputenc Error: Unicode char \u8:β not set up for use with LaTeX.

See the inputenc package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.59  y ti = β

Try running pandoc with --latex-engine=xelatex.
pandoc.exe: Error producing PDF from TeX source
Error: pandoc document conversion failed with error 43

Howerver,安装时:

package ‘inputenc’ is not available (for R version 3.1.0)

问题:如何

  1. 表达方程式,以便它们可以同时用于HTML和PDF
  2. 将颜色应用于LaTeX中的选定元素以匹配MathML?
  3. 并排放置方程式,水平向左对齐,垂直居中
  4. P.S。

    这两个方程都是从MathType 6.8复制粘贴的。左边的等式style="color:red"是手动添加的。有没有办法在复制粘贴时保留颜色?

    enter image description here

0 个答案:

没有答案