In LaTeX I can create conditionals in the following manner
\iftoggle{ebook}{
\newcommand{\textbreak}{\newline\hrule\newline}
}{
\newcommand{\textbreak}{\begin{center}\LARGE{$\Psi\quad\Psi\quad\Psi$}\end{center}}
}
Can I do the same while knitting R Markdown, depending on if the output, is say HTML or PDF.
Rendering. To transform your markdown file into an HTML, PDF, or Word document, click the “Knit” icon that appears above your file in the scripts editor. A drop down menu will let you select the type of output that you want. When you click the button, rmarkdown will duplicate your text in the new file format.
To knit in RStudio , click the Knit pull down button. You want to use the Knit HTML option for this lesson. When you click the Knit HTML button, a window will open in your console titled R Markdown. This pane shows the knitting progress.
If you just need to include a short command in your target format, then you could use raw elements for your target format:
`<br><hr><br>`{=html}
`\begin{center}\LARGE{$\Psi\quad\Psi\quad\Psi$}\end{center}`{=latex}
The first line will only be included in HTML formats (like epub), while the latter will be used when exporting to or via LaTeX.
For longer text, or if you don't want to write in the target format directly, I'd recommend using fenced divs in combination with a pandoc filter, e.g. a Lua filter; this works both with raw pandoc as well as with RMarkdown.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With