I have a quarto markdown document (test.qmd
). It contains a toggle button named BibTeX
which expands into a specified $\BibTeX$ entry when expanded.
The test.qmd
file reprex is as follows:
---
title: "test"
format: html
---
<!-- BibTeX -->
<button class="btn btn-info" type="button" data-bs-toggle="collapse" data-bs-target="#test2022paper" aria-expanded="false" aria-controls="test2022paper">
BibTeX
</button>
<div class="collapse" id="test2022paper">
<br>
<div class="card card-body">
```{r, eval=FALSE}
@misc{test2022paper,
title = {
A test' paper
},
author = {Test authora, Test authorb},
year = 2022,
eprint = {arXiv:test}
}
```
</div>
</div>
The issue is that the BibTeX entry is formatted as an R
code chunk, which causes strange highlighting since the test'
apostrophe is interpreted as the start of an R
string, not a literal BibTeX entry text. See the image below, for the knitted output:
Is there a way to display this BibTeX entry code chunk using bib
file syntax highlighting?
You can simply use bibtex
as code chunk header to get BibTeX syntax highlighting.
Also since bibtex
is the first code chunk in this MWE, you may want to specify knitr
as engine, otherwise Quarto will try to render this document using jupyter
.
---
title: "test"
format: html
engine: knitr
---
<!-- BibTeX -->
<button class="btn btn-info" type="button" data-bs-toggle="collapse" data-bs-target="#test2022paper" aria-expanded="false" aria-controls="test2022paper">
BibTeX
</button>
<div class="collapse" id="test2022paper">
<br>
<div class="card card-body">
```{bibtex}
@misc{test2022paper,
title = {
A test' paper
},
author = {Test authora, Test authorb},
year = 2022,
eprint = {arXiv:test}
}
```
</div>
</div>
Alternatively, if for some reason you want to use r-code chunk, but still want to get bibtex
syntax highlighting, a possible way would be writing that bib as output and specifying sourceCode bibtex
as output class.
---
title: "test"
format: html
---
<!-- BibTeX -->
<button class="btn btn-info" type="button" data-bs-toggle="collapse" data-bs-target="#test2022paper" aria-expanded="false" aria-controls="test2022paper">
BibTeX
</button>
<div class="collapse" id="test2022paper">
<br>
<div class="card card-body">
```{r}
#| echo: false
#| class-output: "sourceCode bibtex"
bib <-
"@misc{test2022paper,
title = {
A test' paper
},
author = {Test authora, Test authorb},
year = 2022,
eprint = {arXiv:test}
}"
cat(bib, sep = "\n")
```
</div>
</div>