quarto-dev / quarto-cli

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

Varying the reference position in `quarto-journals` template #2024

Open jjallaire opened 2 years ago

jjallaire commented 2 years ago

Discussed in https://github.com/quarto-dev/quarto-cli/discussions/2009

@dragonstyle You should read to the bottom of the discussion to see the clearest explanation of what the bug is.

Originally posted by **sammo3182** August 19, 2022 Recently I asked a question about varying the reference allocation with Quarto in #1728. Then I find the problem that made the old rmarkdown tricks not work was because I used the [`article-format-template`](https://github.com/quarto-journals/article-format-template). The reference was in the right place I want when rendering the plain pdf but then moved to the very end of the document when rendering the `aft`. A replicable example: ```qmd --- format: pdf: number-sections: true aft-pdf: keep-tex: true aft-html: default bibliography: bio.bib title: A test --- content @Hu2020 # Reference ::: {#refs} ::: # Online Supplementary Materials ``` [bio.zip](https://github.com/quarto-dev/quarto-cli/files/9386033/bio.zip) See the difference of the reference when choosing the following options respectively: ![image](https://user-images.githubusercontent.com/6463211/185724871-cd89a2f3-24d7-4787-8515-d2aba80475e6.png) How could I allow the `aft` to recognize my reference setting? Any suggestion will be very helpful. Moreover, a more detailed instruction and examples about how to customize the template than the current [brief version](https://github.com/quarto-journals/article-format-template/blob/main/README.md) under aft repo and Quarto.org will be super welcomed---details like how to arrange the author area, showing the corresponding author, adding the key words and acknowledge, etc.
mcanouil commented 2 years ago

Simply to make it easier to see the issue without having to follow the whole thread, below the information about the generated tex file depending on the cite-method

It appears there is an issue (ot at least an undocumented behaviour in https://quarto.org/docs/authoring/footnotes-and-citations.html#bibliography-generation) when using cite-method: natbib (probably the same thing for cite-method: biblatex), which can be replicated also with other formats such as https://github.com/quarto-journals/jss

  • default cite-method (i.e., Pandoc citeproc)

    \hypertarget{references}{%
    \subsubsection*{References}\label{references}}
    \addcontentsline{toc}{subsubsection}{References}
    
    \hypertarget{refs}{}
    \begin{CSLReferences}{1}{0}
    \leavevmode\vadjust pre{\hypertarget{ref-CameronTrivedi2013}{}}%
    Cameron, A. Colin, and Pravin K. Trivedi. 2013. \emph{Regression
    Analysis of Count Data}. 2nd ed. Cambridge: Cambridge University Press.
    
    \end{CSLReferences}
  • natbib

    \hypertarget{references}{%
    \subsubsection*{References}\label{references}}
    \addcontentsline{toc}{subsubsection}{References}
    
    \hypertarget{refs}{}
    \begin{CSLReferences}{0}{0}
    \end{CSLReferences}

    and at the end

    \bibliography{bibliography.bib}
    \end{document}

The LaTeX partial biblio.tex is added to the end, no matter if refs div is set and where it is set. It's possible to manually move it (and remove the title with e.g., \renewcommand{\bibsection}{}) to make it look how it is supposed to. My guess is that it could be fixed in one of the pre/post processing scripts/filters used in Quarto.

Source: https://github.com/quarto-dev/quarto-cli/discussions/2009#discussioncomment-3439550

cderv commented 2 years ago

I believe using

::: {#refs}
:::

to place bibliography is a Pandoc Citeproc only feature. (https://pandoc.org/MANUAL.html#placement-of-the-bibliography)

I don't think this work in Pandoc itself when using --natbib or --biblatex. In those case, the LaTeX template will be used, with whichever content about natbib or biblatex is included.

So the difference between default pdf format and the one in aft-pdf made for the template is for me because of that : The demo format explicitly use a .bst file for styling and --natbib (https://github.com/quarto-journals/article-format-template/blob/main/_extensions/aft/_extension.yml#L26) and not Pandoc citeproc.

The question is here to me: Do we want to extend the bibliography placement feature from Pandoc citeproc to work also with other cite method by tweaking provided template, potentially building on our partial system ?

For quarto-journals and any other custom format, one could change the default template using partials system or the whole template. That is what quarto-journals/aft-pdf has done by tweaking the default pdf format.

Hopefully the above makes sense.

mcanouil commented 2 years ago

The easy and faster solution is to better document the feature in https://quarto.org/docs/authoring/footnotes-and-citations.html#bibliography-generation by mentioning that it only works using citeproc.

The more long term solution should be, in my opinion, a filter that mimic citeproc workflow by adding the bibliography command where the refs div is and when using natbib/biblatex.

dragonstyle commented 2 years ago

Just a note for future implementation - we could definitely detect this div in a filter (ensure that this is targeting PDF and not using citeproc) and insert the appropriate LaTeX in the div. We would then need to ensure we prevent the extra \bibliography from being written by the template (perhaps by adding additional conditionality to the template itself or worst case trying to strip it in a post processor).

dragonstyle commented 2 years ago

This is a little more of a can worms than I initially expected (it affects things like the positioning of backmatter and has some other negative interactions with the underlying latex template). I will have to give this some additional thought.