I see! Since your code seems to not format the non-bibliography headings, I tried to fix it up a bit and added the surrounding boilerplate to make it directly reproducible (if you provide a bibliography file):
for reference: original in a complete example
#import "@preview/alexandria:0.1.1": *
#show: alexandria(prefix: "x-", read: path => read(path))
#set heading(numbering: "1.")
#show heading: it => {
if it.level != 1 or it.body != [Bibliography] { return it }
let levels = counter(heading).at(it.location())
set align(center)
text(it.body + " For Chapter " + str(counter(heading).get().first() - 1))
counter(heading).update(counter(heading).get().first() - 1)
}
= A
#bibliographyx("ref.bib", title: [Bibliography])
= B
#bibliographyx("ref.bib", title: [Bibliography])
If you find that my suggestions below don’t do what you want, check first if I got this right; maybe I misunderstood your intent.
A few things that you should fix about this are regarding the following:
- your bib headings aren’t blocks
- you are using
get()
→update()
for the counter; starting with the third chapter, this stops working with the dreaded “Layout did not converge within 5 attempts” – see here: Why is State Final not "final"? - #2 by SillyFreak
so you should at least adapt this to the following:
fixed block and convergence
#import "@preview/alexandria:0.1.1": *
#show: alexandria(prefix: "x-", read: path => read(path))
#set heading(numbering: "1.")
#show heading: it => {
if it.level != 1 or it.body != [Bibliography] { return it }
set align(center)
block[
#it.body for Chapter #(counter(heading).get().first() - 1)
]
counter(heading).update(value => value - 1)
}
= A
#bibliographyx("ref.bib", title: [Bibliography])
= B
#bibliographyx("ref.bib", title: [Bibliography])
The workaround that you used is for the problem that you can’t write show bibliography: set heading(...)
with Alexandria. Personally, for now I would solve that with a function. The advantage is that you don’t need to fiddle with the heading counter, since this way you can disable the heading numbering. It will also play more nicely with an outline, since the text is not only changed through the show rule but for the heading as a whole. And you can also set heading(outlined: none)
if you want. You can see the difference by adding #outline()
to the examples:
different workaround with a function
#import "@preview/alexandria:0.1.1": alexandria, bibliographyx as _bibliographyx
#show: alexandria(prefix: "x-", read: path => read(path))
#set heading(numbering: "1.")
#let bibliographyx(..args) = {
show heading: set align(center)
set heading(numbering: none)
_bibliographyx(
title: [Bibliography for Chapter #context (counter(heading).get().first())],
..args,
)
}
= A
#bibliographyx("ref.bib")
= B
#bibliographyx("ref.bib")