5

In the report created by rmarkdown and knitr packages I would like to create a 1 by 2 table, each of the cells of which will host a LaTeX equation. In the equations, individual elements must option for a custom color, producing something like:

enter image description here

Using html elements, which rmarkdown is supposed to recognize:

---
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>

When knitting html, the equation on the left errors: enter image description here

When knitting a PDF, the equation on the right errors:

! 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, when installing:

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

Question: How to

  1. Express equations so that they could go both into HTML and PDF
  2. Apply color to selected elements in LaTeX to match that of MathML?
  3. Place equations side by side, aligned horizontally to the left, and centered vertically

P.S.

Both equations were copy-pasted from MathType 6.8. In the equation on the left style="color:red" were added manually. Is there a way to preserve color when copy-pasting?

enter image description here

andrey
  • 2,029
  • 2
  • 18
  • 23
  • I doubt if MathML can be converted to PDF. Perhaps Pandoc is smarter than I imagined. BTW, inputenc is not an R package; it is a LaTeX package. The price of portability to multiple output formats is that you have to keep the document simple (i.e. pure Markdown syntax if possible). The time when you typed `
    ` in the markdown document, you are almost surely going one-way towards HTML and further away from LaTeX/PDF or any other formats. Keep this duck in mind: http://yihui.name/en/2013/10/markdown-or-latex/ :)
    – Yihui Xie Jul 06 '14 at 21:35
  • Thanks, @Yihui, that does clarify things a bit. As you said, nothing wrong with being greedy and markdown v2 makes it particularly tempting. It seems that pandoc equations are a bit more flexible and less verbose, so i'm probably will invest there. Thanks for the tip about the inputenc - it's been an ongoing struggle to figure out the relateness of pandoc, knitr, MiKTeX, LaTeX, and others, despite the outstanding job you guys are doing on documentations and tutorials. – andrey Jul 07 '14 at 13:06

0 Answers0