quarto-dev / quarto

Quarto open-source scientific and technical publishing system
https://quarto.org
GNU Affero General Public License v3.0
331 stars 28 forks source link

Inserting R Package citations in the Quarto visual editor generates incorrect BibTex #490

Open gtritchie opened 2 months ago

gtritchie commented 2 months ago

This was reported against the RStudio IDE, see https://github.com/rstudio/rstudio/issues/12768 for full details.

The problems start when the citation returned from R is converted to CSL (Citation Style Language) here:

https://github.com/quarto-dev/quarto/blob/06678d55143a7d6de6c7f0232db0c5dcf8392ca6/packages/editor/src/behaviors/insert_citation/source_panels/insert_citation-source-panel-packages.tsx#L163

The citeInfo for the "devtools" example is:

{
    "type": "Manual",
    "title": "devtools: Tools to Make Developing R Packages Easier",
    "url": "https://CRAN.R-project.org/package=devtools",
    "note": "R package version 2.4.5",
    "doi": null,
    "publisher": null,
    "institution": null,
    "address": null,
    "journal": null,
    "year": "2022",
    "booktitle": null,
    "chapter": null,
    "number": null,
    "volume": null,
    "pages": null,
    "series": null,
    "school": null,
    "author": [
        {
            "given": [
                "Hadley"
            ],
            "family": "Wickham",
            "email": null,
            "role": "aut"
        },
        {
            "given": [
                "Jim"
            ],
            "family": "Hester",
            "email": null,
            "role": "aut"
        },
        {
            "given": [
                "Winston"
            ],
            "family": "Chang",
            "email": null,
            "role": "aut"
        },
        {
            "given": [
                "Jennifer"
            ],
            "family": "Bryan",
            "email": "jenny@rstudio.com",
            "role": "aut"
        }
    ],
    "editor": []
}

It is transformed to the following, changing the type and losing the note as described in the issue. The type mapping happens in types.ts: bibtextTypeToCSLType().

{
    "type": "article",
    "title": "devtools: Tools to Make Developing R Packages Easier",
    "URL": "https://CRAN.R-project.org/package=devtools",
    "author": [
        {
            "family": "Wickham",
            "given": "Hadley"
        },
        {
            "family": "Hester",
            "given": "Jim"
        },
        {
            "family": "Chang",
            "given": "Winston"
        },
        {
            "family": "Bryan",
            "given": "Jennifer"
        }
    ],
    "issued": {
        "date-parts": [
            [
                2022
            ]
        ]
    }
}
gtritchie commented 2 months ago

CSL doesn't have a "Manual" type, but perhaps "report" would be a better substitute than "article"?

report A technical report, government report, white paper, brief, or similar work distributed by an institution; Also used for manuals and similar technical documentation (e.g. a software, instrument, or test manual);

from https://docs.citationstyles.org/en/stable/specification.html#appendix-iii-types

UPDATE: The code, as currently written, intended to map BibTeX "manual" to CSL "book", but it is case-sensitive and is messed up by "Manual", falling back to the default of "article". So that part, at least, should be a simple fix.

https://github.com/quarto-dev/quarto/blob/06678d55143a7d6de6c7f0232db0c5dcf8392ca6/packages/editor/src/api/bibtex/types.ts#L94-L97