Create bracketed text in R markdown (in a bulleted list)

Viewed 271

In normal Markdown I could bracket the word "purple" by simply putting brackets around the word, like this [purple]. This also works in R Markdown.

However I have a unique R Markdown situation. Let's describe it:

  1. I've got the word "Purple" bracketed in a bulleted list.
  2. I've also got a heading below titled "Purple".
---
title: "Untitled"
output: html_document
---

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

<!-- Line 10 is directly below this. This is line 9. -->
* [Purple] blue red  

* \[Purple\] blue red  

** \\[Purple\\] blue red  

### Purple

Purple blue red.

purple

As a consequence:

  1. R Markdown links my bracketed [purple] to it's heading further down in the document.

Instead of linking the word "purple" to it's heading below, how do I instead get the following at line #10 of this R Markdown document (without any linking at all):

  • [Purple] blue red

My attempts at escaping seem to generate LaTeX output and I also assume this all might be an issue in normal Markdown, not just R Markdown (just a guess).

2 Answers

Escape either [ or ], but not both, because if you escape both, it happens to be the syntax for inline math expressions, and if you escape neither, it happens to be the syntax for linking to section headings.

---
title: "Untitled"
output: html_document
---

* [Purple\] blue red  

* \[Purple] blue red  

### Purple

Purple blue red.

You may use HTML brackets. &#91; and &#93; for [ and ].

---
title: "Untitled"
output: html_document
---

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

<!-- Line 10 is directly below this. This is line 9. -->
* [Purple] blue red  

* \[Purple\] blue red  
* Purple blue red  
* Purple blue red  
* Purple blue red  

<!-- SOLUTION LINE BELOW -->

* &#91;Purple&#93; blue red

### Purple

Purple blue red.

Yields

enter image description here

Related