Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make suppress-bibliography work with --biblatex #9131

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

bgrenet
Copy link

@bgrenet bgrenet commented Oct 12, 2023

Currently, setting the metadata variable suppress-bibliography has no effect with --biblatex nor --natbib. I add a simple conditional to make it work.

@jgm
Copy link
Owner

jgm commented Oct 12, 2023

Looks like this would only affect --natbib, not --biblatex...

@bgrenet
Copy link
Author

bgrenet commented Oct 12, 2023

Looks like this would only affect --natbib, not --biblatex...

The conditional encompasses the two versions, it opens on line 556 and closes on line 588. I've tested it and seems to work.

For the CI, from what I understand there are some failure because my changes introduce some new extra blank lines, right?

@jgm
Copy link
Owner

jgm commented Oct 13, 2023

OK, that helps. The template's structure is hard to see -- I've added some tabs to help myself:

$if(natbib)$
  $if(bibliography)$
    $if(biblio-title)$
      $if(has-chapters)$
      \renewcommand\bibname{$biblio-title$}
      $else$
      \renewcommand\refname{$biblio-title$}
      $endif$
    $endif$
    $if(beamer)$
      \begin{frame}[allowframebreaks]{$biblio-title$}
        \bibliographytrue
    $endif$
    \bibliography{$for(bibliography)$$bibliography$$sep$,$endfor$}
    $if(beamer)$
      \end{frame}
    $endif$
  $endif$
$endif$
$if(biblatex)$
  $if(beamer)$
    \begin{frame}[allowframebreaks]{$biblio-title$}
      \bibliographytrue
      \printbibliography[heading=none]
    \end{frame}
  $else$
    \printbibliography$if(biblio-title)$[title=$biblio-title$]$endif$
  $endif$
$endif$

If I understand correctly, you're adding a conditional that omits this whole section when suppressbibliography is used.

My understanding was that in natbib, \bibliography is needed not only to print the bibliography but to tell the compiler what bibtex file to look at. In biblatex, these two functions are separated out into \addbibresource and \printbibliography. So, does it really work with natbib if there's nothing in the document telling latex what the bibliography file is?

On the test suite: yes, if your changes introduced blank lines, then either you should modify the template or the test suite accordingly.
You could try changing

$if(suppress-bibliography)$$else$

to

$if(suppress-bibliography)$
$else$

I know there's some fancy stuff in doctemplates regarding blank lines, but I don't recall the details.

@bgrenet
Copy link
Author

bgrenet commented Oct 13, 2023

If I understand correctly, you're adding a conditional that omits this whole section when suppressbibliography is used.

Right.

My understanding was that in natbib, \bibliography is needed not only to print the bibliography but to tell the compiler what bibtex file to look at. In biblatex, these two functions are separated out into \addbibresource and \printbibliography. So, does it really work with natbib if there's nothing in the document telling latex what the bibliography file is?

I had the impression that it works, but I have to run more extensive tests to be sure. I'll do that and do accordingly. (I am not used to natbib so I have to be more careful I guess.)

On the test suite: yes, if your changes introduced blank lines, then either you should modify the template or the test suite accordingly.

Ok I'll do that.

@bgrenet
Copy link
Author

bgrenet commented Oct 24, 2023

My understanding was that in natbib, \bibliography is needed not only to print the bibliography but to tell the compiler what bibtex file to look at. In biblatex, these two functions are separated out into \addbibresource and \printbibliography. So, does it really work with natbib if there's nothing in the document telling latex what the bibliography file is?

I did some tests with natbib. The point would be to allow the user to print the bibliography at the place she wants. Yet the TeX result would be valid (would compile) only if the user has issued a \bibliography{...} somewhere in the text. Since I am not sure my change meets some necessity, I removed it.

So currently (I am waiting for CI reports) I implement only suppress-bibliography for --biblatex where it is very useful, for instance to issue manually one or several \printbibliography.

@bgrenet bgrenet changed the title Make suppress-bibliography work with --natbib and --biblatex Make suppress-bibliography work with --biblatex Oct 24, 2023
@jgm
Copy link
Owner

jgm commented Oct 24, 2023

@bgrenet
Copy link
Author

bgrenet commented Oct 24, 2023

tl;dr: I think that suppress-bibliography is actually unneeded with natbib, since the bibliography is printed if, and only if, the user provides --bibliography=....

But if you don't provide --bibliography, then it won't resolve the citations either (\bibliography specifies the data source).

I'm okay with just implementing this for biblatex, though, if getting it to work with natbib is too complex.

@bgrenet
Copy link
Author

bgrenet commented Oct 25, 2023

Now I see one possible solution for natbib:

  • If a user wants to provide \bibliography{...} by themself, they can simply use --natbib without --bibliography=...;
  • If a user wants to only have citations but no bibliography, or to print some bib entries only, they can use --natbib with --bibliography=... and --suppress-bibliography.

If this makes sense, I can implement it. Not sure it's worth it though.

@jgm
Copy link
Owner

jgm commented Oct 25, 2023

If a user wants to only have citations but no bibliography, or to print some bib entries only, they can use --natbib with --bibliography=... and --suppress-bibliography.

That would be the intended behavior, yes, but the question we're asking is how is this to be implemented? That is, what will --suppress-bibliography do, in terms of the template? If it removes \bibliography{} then citeproc won't generate citations either. That's the whole problem we've been discussing, so I must not be understanding you.

@bgrenet
Copy link
Author

bgrenet commented Oct 26, 2023

That would be the intended behavior, yes, but the question we're asking is how is this to be implemented? That is, what will --suppress-bibliography do, in terms of the template? If it removes \bibliography{} then citeproc won't generate citations either. That's the whole problem we've been discussing, so I must not be understanding you.

I don't see the problem since, as pandoc user's guide states, the --natbib option "is not for use with the --citeproc option or with PDF output." Therefore one can implement something for --natbib that won't have any effect with --citeproc. I just tested with my initial implementation (which was buggy for other reasons): pandoc MWE.md --citeproc --metadata=suppress-bibliography --bibliography=biblio.bib -o MWE.pdf works perfectly, the citation is correctly typeset and there is no bibliography at the end of the document.

@jgm
Copy link
Owner

jgm commented Oct 26, 2023

I don't see the problem since, as pandoc user's guide states, the --natbib option "is not for use with the --citeproc option or with PDF output."

That's right, but using --bibliography with --natbib doesn't trigger citeproc, it only sets the content of \bibliography{..} in the template, which is something you need for natbib.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants