我有一份四分减价文件(test.qmd)。它包含一个名为BibTeX的切换按钮,该按钮在展开时展开为指定的$\BibTeX$条目。
test.qmd文件reprex如下所示:
---
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>问题是BibTeX条目被格式化为R代码块,这会导致奇怪的突出显示,因为test'撇号被解释为R字符串的开始,而不是文字BibTeX条目文本。有关针织产品的输出,请参见下图:

是否有一种使用BibTeX文件语法突出显示此bib条目代码块的方法?
发布于 2022-10-30 19:38:44
备选案文1
您可以简单地使用bibtex作为代码块头来获得BibTeX语法高亮显示。
另外,由于bibtex是此MWE中的第一个代码块,您可能希望将knitr指定为引擎,否则Quarto将尝试使用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>选项2
或者,如果出于某种原因,您希望使用r代码块,但仍然希望获得bibtex语法突出显示,一种可能的方法是将bib写入输出,并指定sourceCode bibtex作为输出类。
---
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:假
#\\class-输出:"sourceCode bibtex“
围围<-
@misc{test2022paper,
title = { A test' paper},author = {Test authora, Test authorb},year = 2022,eprint = {arXiv:test}}“
cat(bib,sep = "\n")
</div>
</div>

https://stackoverflow.com/questions/74256003
复制相似问题