0

How do I include the following LaTeX {itemize} in my R Markdown? It simply doesn't work when I try and knitr the HTML.

---
title: "Untitled"
author: "March 2019"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

\[x = R + E\]
where:
\begin{itemize}
\item[R=] is Racoon
\item[E=] is Elephant
\end{itemize}
Display name
  • 4,153
  • 5
  • 27
  • 75
  • 1
    [This could help](https://stackoverflow.com/q/29656476/1315767) – Jilber Urbina Apr 26 '19 at 20:24
  • 3
    Why not using pure markdown syntax? Just use `*` for every new entry. https://www.rstudio.com/wp-content/uploads/2015/02/rmarkdown-cheatsheet.pdf – J_F Apr 26 '19 at 20:28

2 Answers2

3

Just use either + or - at the beginning of sentences which you wish to itemize, it works for both html and pdf output of Rmarkdown eg
use the statement in between '$' symbol
$+ this statement will be itemized in rmd$

1

R Markdown doesn't use LaTeX when producing HTML. The code you used would work if output was to pdf_document, but not to html_document.

If you really want the labelled list in HTML, you're going to have to insert HTML code, not LaTeX code. I don't know if there's anything visually equivalent to LaTeX's \item[R=], but you could do this, which is logically equivalent:

---
title: "Untitled"
author: "March 2019"
output: html_document

---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

\[x = R + E\]
where:

<dl>
<dt>R=</dt>
<dd>is Racoon</dd>
<dt>E=</dt> 
<dd>is Elephant</dd>
</dl>

This displays as

screenshot

Perhaps CSS could be crafted to make it visually equivalent.

Edited to add: And of course it is possible, and has been done. It's easy to follow https://stackoverflow.com/a/13371522/2554330, since R Markdown uses the Bootstrap framework. Just add a class to the first tag:

<dl class="dl-horizontal">
<dt>R=</dt>
<dd>is Racoon</dd>
<dt>E=</dt> 
<dd>is Elephant</dd>
</dl>

and it produces

another screenshot

If the styling is still not satisfactory, look at some of the other discussion related to https://stackoverflow.com/a/13371522/2554330.

user2554330
  • 37,248
  • 4
  • 43
  • 90