Closed HedvigS closed 2 months ago
Thanks for the report.
This is indeed an issue with natbib
for example, but not with pandoc citeproc
---
title: "test"
output:
pdf_document:
keep_tex: true
citation_package: natbib
bibliography: packages.bib
---
```{r}
knitr::write_bib(x = "spam", "packages.bib")
@spam2017
leads to
! Misplaced alignment tab character &.
We can probably escape &
when there isn't a backslash before it (using negative lookbehind (?<!)
in Perl regex).
gsub('(?<!\\\\)&', '\\\\&', x, perl = TRUE)
We need to verify if pandoc-citeproc
is also fine with \&
in .bib
. If that's the case, please feel free to submit a pull request. Thanks!
We can probably escape
&
when there isn't a backslash before it (using negative lookbehind(?<!)
in Perl regex).gsub('(?<!\\\\)&', '\\\\&', x, perl = TRUE)
We need to verify if
pandoc-citeproc
is also fine with\&
in.bib
. If that's the case, please feel free to submit a pull request. Thanks!
Ok! Is that an encouragement to me or @cderv to submit a PR?
Is that an encouragement to me or @cderv to submit a PR?
Either of us I would say :)
Feel free to contribute if you are interested. Do you want to give it a try ?
Is that an encouragement to me or @cderv to submit a PR?
Either of us I would say :)
Feel free to contribute if you are interested. Do you want to give it a try ?
I could... but.. I have a deadline for a paper on Sunday and 53 exams to grade and I haven't edited knitr source code before. I think you're probably going to do it better and faster ;)
I totally get the workload you're juggling right now – the paper deadline and all those exams to grade must be keeping you super busy! Don't worry; It was appreciated you were willing to. We'll do it. Thanks again for opening the issue
I totally get the workload you're juggling right now – the paper deadline and all those exams to grade must be keeping you super busy! Don't worry; It was appreciated you were willing to. We'll do it. Thanks again for opening the issue
Thanks!!
By filing an issue to this repo, I promise that
xfun::session_info('knitr')
. I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version:remotes::install_github('yihui/knitr')
.I understand that my issue may be closed if I don't fulfill my promises.
For reasons beyond my understanding, some bibtex entries generated by citation() from Description files have non-escaped ampersands - which causes problems with LaTeX later.
See for example spam2017 below.
Currently, I'm doing a fairly "hacky" solve to this by reading in the output from write_bib and then doing some find and replace with stringr.
Could knitr::write_bib please check for non-escpaped ampersands and do this tweak if necessary?
Thank you! Love the package!