rmd revealjs Latex test

Fan Wang

Feb 5, 2020

Overview

See more from Fan’s Tex4Econ

We will test out writing equations in RMD + revealjs

Defining NEWCOMMAND

  • This is from \vara+2: \(\mathrm{Var}+2\)
  • This is from \varb+2: \(\mathrm{\alpha + \beta}+2\)
  • This is from \varc+2: \( \frac{a + b}{c + d} \times \exp\left( x \right) = y +2\)
\newcommand{\vara}{\mathrm{Var}}
\newcommand{\varb}{\mathrm{\alpha + \beta}}
\newcommand{\varc}{
  \frac{a + b}{c + d} \times \exp\left( x \right) = y
}

Equations

Inline Equation

Here is some text that is in red, in between the b symbols mean put this text in bold but this text is not bold

This is smaller italisized text, font size 50 percent.

  • Regular sized Equation: \(1+2=3\)
  • Smaller Equation: \(1+2=3\)

Display Equation

\[ \begin{equation} \label{eq:targetcost} Z\left(\tau,\delta\right) = \sum\limits_{ \substack{ \mathrm{cohort} \\ \in{\left\{70,72,74,76\right\}}} } \left\{\delta\cdot \int_{\epsilon} \int_{Y_{min}}^{F_{Y}^{-1}\left(\tau\right)} \int_{X} N\Big( \substack{ Y,X,\epsilon; \\ \delta, \Gamma_{\mathrm{cohort}} } \Big)f\left(X|Y\right)f\left(Y\right)f\left(\epsilon\right)\mathrm{d}X\mathrm{d}Y\mathrm{d}\epsilon\right\} \end{equation} \]

Equations Space Saving

The paper latex file already contains various newcommands pre-defined, want to share those latex files with RMD.

New Command Define First

Define long newcommand in RMD and show equation multiple times.

Equation defined as new command with different zoom:

\[ \begin{equation} Z\left(\tau,\delta\right) = \sum\limits_{ \substack{ \mathrm{cohort} \\ \in{\left\{70,72,74,76\right\}}} } \left\{\delta\cdot \int_{\epsilon} \int_{Y_{min}}^{F_{Y}^{-1}\left(\tau\right)} \int_{X} N\Big( \substack{ Y,X,\epsilon; \\ \delta, \Gamma_{\mathrm{cohort}} } \Big)f\left(X|Y\right)f\left(Y\right)f\left(\epsilon\right)\mathrm{d}X\mathrm{d}Y\mathrm{d}\epsilon\right\} \end{equation} \] \[ \begin{equation} Z\left(\tau,\delta\right) = \sum\limits_{ \substack{ \mathrm{cohort} \\ \in{\left\{70,72,74,76\right\}}} } \left\{\delta\cdot \int_{\epsilon} \int_{Y_{min}}^{F_{Y}^{-1}\left(\tau\right)} \int_{X} N\Big( \substack{ Y,X,\epsilon; \\ \delta, \Gamma_{\mathrm{cohort}} } \Big)f\left(X|Y\right)f\left(Y\right)f\left(\epsilon\right)\mathrm{d}X\mathrm{d}Y\mathrm{d}\epsilon\right\} \end{equation} \] \[ \begin{equation} Z\left(\tau,\delta\right) = \sum\limits_{ \substack{ \mathrm{cohort} \\ \in{\left\{70,72,74,76\right\}}} } \left\{\delta\cdot \int_{\epsilon} \int_{Y_{min}}^{F_{Y}^{-1}\left(\tau\right)} \int_{X} N\Big( \substack{ Y,X,\epsilon; \\ \delta, \Gamma_{\mathrm{cohort}} } \Big)f\left(X|Y\right)f\left(Y\right)f\left(\epsilon\right)\mathrm{d}X\mathrm{d}Y\mathrm{d}\epsilon\right\} \end{equation} \] \[ \begin{equation} Z\left(\tau,\delta\right) = \sum\limits_{ \substack{ \mathrm{cohort} \\ \in{\left\{70,72,74,76\right\}}} } \left\{\delta\cdot \int_{\epsilon} \int_{Y_{min}}^{F_{Y}^{-1}\left(\tau\right)} \int_{X} N\Big( \substack{ Y,X,\epsilon; \\ \delta, \Gamma_{\mathrm{cohort}} } \Big)f\left(X|Y\right)f\left(Y\right)f\left(\epsilon\right)\mathrm{d}X\mathrm{d}Y\mathrm{d}\epsilon\right\} \end{equation} \] \[ \begin{equation} Z\left(\tau,\delta\right) = \sum\limits_{ \substack{ \mathrm{cohort} \\ \in{\left\{70,72,74,76\right\}}} } \left\{\delta\cdot \int_{\epsilon} \int_{Y_{min}}^{F_{Y}^{-1}\left(\tau\right)} \int_{X} N\Big( \substack{ Y,X,\epsilon; \\ \delta, \Gamma_{\mathrm{cohort}} } \Big)f\left(X|Y\right)f\left(Y\right)f\left(\epsilon\right)\mathrm{d}X\mathrm{d}Y\mathrm{d}\epsilon\right\} \end{equation} \]

Include Equations and Symbols Defined Elsewhere

Reuse tex preamble from paper, load as child, and clean comments.

# This loads the tex preamble with predefined formula, reuseable symbols etc. 
test_tex_define_out = knitr::knit_child('test_tex_define.tex')
# Delete all comment lines, which starts with percent, and end with carriage return
# This deletes all but the last line
test_tex_define_out = gsub("\\%.*?\\\n", "", test_tex_define_out)
# Delete last comment if on final line
test_tex_define_out = gsub("\\\n%.*","", test_tex_define_out)

\[\text{from external file: } \alpha + \beta\] \[\text{from external file: } \sigma_{i=1}^{N} X_i\] \[ \begin{equation} \text{EXTERNAL: } Z\left(\tau,\delta\right) = \sum\limits_{ \substack{ \mathrm{cohort} \\ \in{\left\{70,72,74,76\right\}}} } \left\{\delta\cdot \int_{\epsilon} \int_{Y_{min}}^{F_{Y}^{-1}\left(\tau\right)} \int_{X} N\Big( \substack{ Y,X,\epsilon; \\ \delta, \Gamma_{\mathrm{cohort}} } \Big)f\left(X|Y\right)f\left(Y\right)f\left(\epsilon\right)\mathrm{d}X\mathrm{d}Y\mathrm{d}\epsilon\right\} \end{equation} \]