paleolimbot / rbbt

R Interface to the Better BiBTex Zotero Connector
145 stars 26 forks source link

Conflict with Quarto cross-referencing system #35

Open dmi3kno opened 2 years ago

dmi3kno commented 2 years ago

In Quarto internal references are now "bare" i.e. not prepended by /@ref(). Quarto website explains

Quarto uses the prefix #fig- rather than #fig: (which is more compatible with Jupyter notebook cell ids

``{r}
#| label: fig-cars
#| fig-cap: "Famous mtcars plot"
plot(mpg~hp, data=mtcars)
``
Refer to plot @fig-cars. Read more about this data in @wickham2016DataScienceImport

Of course, when I run RBBT addin on this file I get an error "Error: not found: fig-cars".

I don't have a solution in mind other than creating a "whitelist" of references, which RBBT skips. So far we have c("^fig-", "^tbl-", "^eq-", "^sec-", "^lst-", "^thm-").

Could we allow the ignore argument in rbbt::bbt_write_bib() to take regex? Then this vector of extensions could be made the default value. Today you are doing setdiff() without validating the ignore vector.

https://github.com/paleolimbot/rbbt/blob/7c76fcca8ff29e4554910e631bfe24ffe5aac2de/R/write-bib.R#L45-L46

bwiernik commented 2 years ago

Just commenting that that's an extremely frustrating design choice on the part of Quarto to co-opt the syntax that is already in wide use for citations for a different purpose

dmi3kno commented 2 years ago

May I also suggest that while we're on it, we improve the error message? Instead of "Error: not found: fig-cars". it should say: "RBBT error when parsing example.qmd: the key @fig-cars was not found in Zotero database. If this is not a bibliography key, remember to add it to the vector of ignored keys" or something along these lines.

dmi3kno commented 1 year ago

Could we, please, talk about this? I am exempting all of the keys used for cross-referencing listing them in ignore argument of bbt_write_bib() but since the prefixes are standardized I see no reason why c("^fig-", "^tbl-", "^eq-", "^sec-", "^lst-", "^thm-") can not be exempted automatically.

dmi3kno commented 1 year ago

This is becoming slightly urgent. Rstudio Visual Editor is getting really slowed down by large Zotero collections, as reported in this issue (rstudio/rstudio#9878). My preferred way of inserting references is through {rbbt} add-in ("Update bibliography for current document from Zotero"), partially because it does not require loading the Visual Editor (and it is talking to my Zotero much faster).

But now all of the @fig-something and @tbl-something in the text are causing errors because {rbbt} does not except them. Could we please provide the list of excepted prefixes for example in options()?

daniela-palleschi commented 1 year ago

I second the request for adding a list of excepted prefixes. fwiw, my current workaround is to

  1. use Ctrl+F to find and replace all instances of e.g., "@fig-" with some unique string like "xyzfig-",
  2. run rbbt::bbt_update_bib("filename.qmd"), now that it'll ignore all instances of "xyzfig-"
  3. then comment out rbbt::bbt_update_bib("filename.qmd") so that it won't run again when rendering
  4. undo the "@fig-" to "xyzfig-" replacement

Now when rendering, rbbt isn't doing anything because I've commented out bbt_update_bib(), so there's no conflict between rbbt and the Quarto cross-references. It works, but isn't optimal.

paleolimbot commented 1 year ago

The magic happens here:

https://github.com/paleolimbot/rbbt/blob/master/R/detect-citations.R#L36-L58

I don't have a set up anymore where I can test this but am happy to review a better set of regexes for detecting or excluding citation! It sounds like something as simple as stringr::str_subset(refs, "@(fig-|tbl-)", negate = TRUE) might work at the end of that function.

dmi3kno commented 1 year ago

I pushed the PR #42 which should close this issue

dmi3kno commented 1 year ago

Quarto plans to discontinue inline expressions in YAML (see quarto-dev/quarto-cli#6189). They recommend using pre-render scripts instead. There are more tips in the referenced closed issue.

For now, make sure you add engine: knitr