@@ -11,6 +11,7 @@ import { mergeConfigs } from "../../core/config.ts";
1111import { texSafeFilename } from "../../core/tex.ts" ;
1212
1313import {
14+ kBibliography ,
1415 kCapBottom ,
1516 kCapLoc ,
1617 kCapTop ,
@@ -318,6 +319,16 @@ function pdfLatexPostProcessor(
318319 calloutFigureHoldLineProcessor ( ) ,
319320 ] ;
320321
322+ if ( format . pandoc [ kCiteMethod ] === "biblatex" ) {
323+ lineProcessors . push ( bibLatexBibligraphyRefsDivProcessor ( ) ) ;
324+ } else if ( format . pandoc [ kCiteMethod ] === "natbib" ) {
325+ lineProcessors . push (
326+ natbibBibligraphyRefsDivProcessor (
327+ format . metadata [ kBibliography ] as string [ ] | undefined ,
328+ ) ,
329+ ) ;
330+ }
331+
321332 const marginCites = format . metadata [ kCitationLocation ] === "margin" ;
322333 const renderedCites = { } ;
323334 if ( marginCites ) {
@@ -633,6 +644,47 @@ const calloutFigureHoldLineProcessor = () => {
633644 } ;
634645} ;
635646
647+ const kQuartoBibPlaceholderRegex = "%bib-loc-124C8010" ;
648+ const bibLatexBibligraphyRefsDivProcessor = ( ) => {
649+ let hasRefsDiv = false ;
650+ return ( line : string ) : string | undefined => {
651+ if ( line === kQuartoBibPlaceholderRegex ) {
652+ if ( ! hasRefsDiv ) {
653+ hasRefsDiv = true ;
654+ return "\\printbibliography[heading=none]" ;
655+ } else {
656+ // already seen a refs div, just ignore this one
657+ return undefined ;
658+ }
659+ } else if ( hasRefsDiv && line . match ( / ^ \\ p r i n t b i b l i o g r a p h y $ / ) ) {
660+ return undefined ;
661+ } else {
662+ return line ;
663+ }
664+ } ;
665+ } ;
666+
667+ const natbibBibligraphyRefsDivProcessor = ( bibs ?: string [ ] ) => {
668+ let hasRefsDiv = false ;
669+ return ( line : string ) : string | undefined => {
670+ if ( line === kQuartoBibPlaceholderRegex ) {
671+ if ( bibs && ! hasRefsDiv ) {
672+ hasRefsDiv = true ;
673+ return `\\renewcommand{\\bibsection}{}\n\\bibliography{${
674+ bibs . join ( "," )
675+ } }`;
676+ } else {
677+ // already seen a refs div, just ignore this one
678+ return undefined ;
679+ }
680+ } else if ( hasRefsDiv && line . match ( / ^ \s * \\ b i b l i o g r a p h y { .* } $ / ) ) {
681+ return undefined ;
682+ } else {
683+ return line ;
684+ }
685+ } ;
686+ } ;
687+
636688// Removes the biblatex \printbibiliography command
637689const suppressBibLatexBibliographyLineProcessor = ( ) => {
638690 return ( line : string ) : string | undefined => {
@@ -656,7 +708,6 @@ const suppressNatbibBibliographyLineProcessor = () => {
656708
657709// {?quarto-cite:(id)}
658710const kQuartoCiteRegex = / { \? q u a r t o - c i t e : ( .* ?) } / g;
659-
660711const bibLatexCiteLineProcessor = ( ) => {
661712 return ( line : string ) : string | undefined => {
662713 return line . replaceAll ( kQuartoCiteRegex , ( _match , citeKey ) => {
0 commit comments