2022-12-13
I had a Quarto document which included a bibliography (created with the default Pandoc citation handling based on citeproc) and I wanted to highlight a particular author name by making it bold.
First, I made a Quarto filter extension following the steps here: https://quarto.org/docs/extensions/filters.html#quick-start.
I called the filter boldname, and for the Lua filter I
adapted the code found here.
I put the following code in the boldname.lua file:
local highlight_author_filter = {
Para = function(el)
for k,_ in ipairs(el.content) do
if el.content[k].t == "Str" and el.content[k].text == "Wright"
and el.content[k+1].t == "Space"
and el.content[k+2].t == "Str" and el.content[k+2].text:find("^N") then
local _,e = el.content[k+2].text:find("^N")
local rest = el.content[k+2].text:sub(e+1)
el.content[k] = pandoc.Strong { pandoc.Str("Wright N") }
el.content[k+1] = pandoc.Str(rest)
table.remove(el.content, k+2)
end
end
return el
end
}
function Div (div)
if div.identifier:find("^ref-") then
return pandoc.walk_block(div, highlight_author_filter)
end
return nil
endThis should highlight the text “Wright N” wherever it appears in any div that starts with “ref-”, which is all the divs that contain bibliography entries.
However, this alone did not work because (I think) the citeproc step
that creates the bibliography happens after the Lua filter is
applied. This is mentioned here.
So I used the method described here,
creating another filter (called dociteproc) to run citeproc
first. In the dociteproc.lua file I put the following
code:
-- Lua filter that behaves like `--citeproc`
function Pandoc (doc)
return pandoc.utils.citeproc(doc)
endFinally, in the YAML metadata of the Quarto document I included
filters:
- dociteproc
- boldname
citeproc: falseto run the dociteproc filter followed by the
boldname filter.
The result was that in the bibliography, all appearances of “Wright N” appeared as “Wright N”.