pandoc-ext / section-bibliographies

Filter to create a separate bibliography for each section or chapter
MIT License
40 stars 4 forks source link

reference section not generated for unnumbered chapters #14

Closed mikabr closed 4 months ago

mikabr commented 1 year ago

I have an unnumbered chapter (a preface) that should have citations and references just like other chapters, but the filter doesn't appear to generate a reference section for it. (running quarto 1.3.433)

Minimal example:

---
format: pdf
bibliography: example.bib
reference-section-title: References
filters:
  - section-bibliographies
citeproc: false
---

# Preface {-}

text citing @frank2012

# Chapter 1

text citing @lewis1973

# Chapter 2

text citing @kraus2019
Screen Shot 2023-07-20 at 4 52 34 PM

Contrast with running pandoc's default citation handling, which does include the unnumbered chapter:

---
format: pdf
bibliography: example.bib
reference-section-title: References
citeproc: true
---

# Preface {-}

text citing @frank2012

# Chapter 1

text citing @lewis1973

# Chapter 2

text citing @kraus2019
Screen Shot 2023-07-20 at 4 52 12 PM

Seems like this could be due to the filter checking that a section has a number attribute in line 23?

local function is_section_div (div)
  return div.t == 'Div'
    and div.classes[1] == 'section'
    and div.attributes.number
end
andrewmcamp commented 1 year ago

I ran into this issue as well. I am not familiar with Lua and so my solution probably isn't best, but I was able to get the code to work by changing the following:

On lines 20-24:

local function is_section_div (div) return div.t == 'Div' and div.classes[1] == 'section' end

On lines 46-52:

if bib_header then bib_header.identifier = 'bibliography-' .. (header.attributes.number or 999) bib_header.level = header.level + 1 end if refs and refs.identifier == 'refs' then refs.identifier = 'refs-' .. (header.attributes.number or 999) end

As far as I can tell, this hasn't created unanticipated/wanted side effects.

mikabr commented 12 months ago

That works great, thanks!

tarleb commented 4 months ago

Thanks for the report!