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:
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>β</mi>
<mn>0</mn>
</msub>
<mo>+</mo><msub style="color:red">
<mi>ε</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:
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
- Express equations so that they could go both into HTML and PDF
- Apply color to selected elements in LaTeX to match that of MathML?
- 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?