Closed JiaxiangBU closed 3 months ago
Thanks for filing this issue. It seems like a very good idea to integrate citations with BibTeX. I'll look into how this can be done easily.
Looking into the possibility of adding a new method for LaTeX that could use additional arguments for different citation types.
I find it maybe helps to add the arguement results='asis'
in the R chunk.
However, the arguement results='asis'
maybe disturbs the gt
display.
Closely related, it would be really useful for me if there was some sort of fmt_citation function, which would take a bibtex file and then format a column of @-tags ("@Li2019") into a column of short ("Li (2019)") or long ("'Title of a Good Paper'. Bob Li, 2019 Journal of Cool Stuff vol. 4 no. 20" ) citation. This would be good for literature reviews, meta-analyses, tables of software used/data sources, etc.
Thanks for the great package!
My understand is that the reason @-tags don't work in gt
is because it exports LaTex, but pandoc
is skipping those tags when parsing the text with pandoc-citeproc
. On the other hand knitr::kable(format="markdown")
exports plain markdown tables and therefore they get properly parsed for @-tags. I don't know if anything can be done at all, since markdown formatting is very limited. Perhaps there's a solution with a different reference processor: natbib
or biblatex
, but I don't know enough to speak about that confidently.
I think I have a solution. https://gist.github.com/dmi3kno/016b9ae2d2de1ef54f4df07ebcd24c4d
Key takeaways:
citation_package: natbib
for processing referencesgt
and use post-formatting with tools::encoded_text_to_latex()
Generally speaking, fmt(cols, fns=tools::encoded_text_to_latex)
seems to be a useful pattern. Would you consider adding it as a standard formatter, i.e. fmt_latex()
, @rich-iannone ? Would you like a PR with that?
UPDATE
Here's my [@ref]
to \cite{ref}
transforming function
citeproc_to_natbib <- function(x){
p <- grepl("^\\[.+\\]$", x)
# strip square brackets, if any
if(p) x <- gsub("(^\\[)|(\\]$)", "", x)
txt_lst <- strsplit(x, ";\\s?")
txt_lst <- lapply(txt_lst, function(i) gsub("^@", "",i))
ltr <- ifelse(p, "p", "t")
txt <- sapply(txt_lst, paste0, collapse = ", ")
paste0("\\cite", ltr, "{", txt, "}")
}
I am reading the vignette and find this table add a source note with reference McNeil, D. R. (1977).
Here is related R code I copy from this vignette.
Does the function
tab_source_note
to support BibTeX reference in the future? Maybe it is hard because I don't see other packages to support this feature.