quarto-dev / quarto-cli

Open-source scientific and technical publishing system built on Pandoc.
https://quarto.org
Other
3.77k stars 309 forks source link

Footnote adjacent to citation creates error in formatting #6177

Open alexfradera opened 1 year ago

alexfradera commented 1 year ago

Bug description

[@citation] next to [^ 1] creates issues with generation of correct bracketing.

Steps to reproduce

Reproducible example:
---
title: "Reference issues"
bibliography: 'biblio.bib'
csl: 'apa-6th-edition.csl'
format:
  html:
       code-fold: true
editor: visual
---

This looks normal [@Petersen2015a].

How about this? [@Petersen2015][^1].

[^1]: Just a footnote

Expected behavior

Ideally this should just render a normal citation with the footnote superscript immediately following.

Actual behavior

Instead, the citation does not render - see brackets

image

Your environment

R-4.3.1 RStudio 2023.06.1 Build 524

Quarto check output

Pandoc version 3.1.1: OK Dart Sass version 1.55.0: OK [>] Checking versions of quarto dependencies......OK [>] Checking Quarto installation......OK Version: 1.3.433 Path: C:\Program Files\Quarto\bin CodePage: 1252

cscheid commented 1 year ago

Can you share a repository with the .csl file and the .bib file you're using? Thanks.

alexfradera commented 1 year ago

Sure - in the repository you will also find the .qmd, slightly expanded to show variants where the expected behaviour is produced (eg when a space between the citation [] and the footnote [] ) https://github.com/alexfradera/temp

cderv commented 1 year ago

I believe this is a parsing behavior of Pandoc with citation in this case. If I run Pandoc on the wrong case of you document and looks at the parsed AST I got this

> quarto pandoc -t native
Abnormally operating brackets [@Petersen2015][^1].

[^1]: This footnote is directly adjacent
^Z
[ Para
    [ Str "Abnormally"
    , Space
    , Str "operating"
    , Space
    , Str "brackets"
    , Space
    , Str "["
    , Cite
        [ Citation
            { citationId = "Petersen2015"
            , citationPrefix = []
            , citationSuffix = []
            , citationMode = AuthorInText
            , citationNoteNum = 1
            , citationHash = 0
            }
        ]
        [ Str "@Petersen2015" ]
    , Str "]"
    , Note
        [ Para
            [ Str "This"
            , Space
            , Str "footnote"
            , Space
            , Str "is"
            , Space
            , Str "directly"
            , Space
            , Str "adjacent"
            ]
        ]
    , Str "."
    ]
]

We see that Str "[" and Str "]" are identified independently from the citation. The citation is resolved but using the unbracketed syntax.

If the bracketed syntax is taken into account it should be like with the space example

> quarto pandoc -t native
With operating brackets [@Petersen2015] [^1].

[^1]: This footnote is after a space
^Z
[ Para
    [ Str "With"
    , Space
    , Str "operating"
    , Space
    , Str "brackets"
    , Space
    , Cite
        [ Citation
            { citationId = "Petersen2015"
            , citationPrefix = []
            , citationSuffix = []
            , citationMode = NormalCitation
            , citationNoteNum = 1
            , citationHash = 0
            }
        ]
        [ Str "[@Petersen2015]" ]
    , Space
    , Note
        [ Para
            [ Str "This"
            , Space
            , Str "footnote"
            , Space
            , Str "is"
            , Space
            , Str "after"
            , Space
            , Str "a"
            , Space
            , Str "space"
            ]
        ]
    , Str "."
    ]
]

So I would report this in Pandoc repo directly