Skip to content

Support Add reference by bibtex @ in the function tab_source_note #112

Closed

Description

@JiaxiangBU

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.

# Display the `islands_tbl` data with a heading and
# two source notes
gt_tbl <- 
  gt_tbl %>%
  tab_source_note(
    source_note = "Source: The World Almanac and Book of Facts, 1975, page 406."
  ) %>%
  tab_source_note(
    source_note = md("Reference: McNeil, D. R. (1977) *Interactive Data Analysis*. Wiley.")
  )

# Show the gt Table
gt_tbl

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.

Activity

  1. changed the title [-]Support bib te x[/-] [+]Support Add reference by bibtex `@` in the function `tab_source_note`[/+] on Dec 15, 2018
  2. rich-iannone commented on Dec 23, 2018

    @rich-iannone
    Member

    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.

  3. self-assigned this
    on Dec 23, 2018
  4. rich-iannone commented on Jan 22, 2019

    @rich-iannone
    Member

    Looking into the possibility of adding a new method for LaTeX that could use additional arguments for different citation types.

  5. JiaxiangBU commented on Feb 7, 2019

    @JiaxiangBU
    Author

    I find it maybe helps to add the arguement results='asis' in the R chunk.

    image

    image

    However, the arguement results='asis' maybe disturbs the gt display.

  6. csoeder commented on Apr 24, 2020

    @csoeder

    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!

  7. dmi3kno commented on May 22, 2020

    @dmi3kno

    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.

  8. dmi3kno commented on May 23, 2020

    @dmi3kno

    I think I have a solution.
    https://gist.github.com/dmi3kno/016b9ae2d2de1ef54f4df07ebcd24c4d

    Key takeaways:

    • use citation_package: natbib for processing references
    • make a dataframe of citations in LaTeX style (double-escaped).
    • pass to gt 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, "}")
    }
  9. added this to the FUTURE milestone on Aug 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions