Skip to content

Commit

Permalink
Update citation-backlinks.lua
Browse files Browse the repository at this point in the history
updated to work with typst
  • Loading branch information
bcdavasconcelos authored Dec 21, 2023
1 parent 439d6c7 commit e00337f
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions _extensions/citetools/citation-backlinks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

--- citation-backlinks.lua – adds citation backlinks to the bibliography
---
--- Copyright: © 2022 John MacFarlane and Albert Krewinkel
--- Copyright: © 2023 John MacFarlane and Albert Krewinkel and Bernardo Vasconcelos
--- License: MIT – see LICENSE for details

-- Makes sure users know if their pandoc version is too old for this
Expand All @@ -16,11 +16,15 @@ local cites = {}
-- counter for cite identifiers
local cite_number = 1

local function with_latex_label(s, el)
local function with_label(s, el)
if FORMAT == "latex" then
-- return {pandoc.RawInline("latex", "\\pagelabel{" .. s .. "}"), el}
return {pandoc.RawInline("latex", "\\label{" .. s .. "}"), el}
else
end
if FORMAT == "typst" then
return {el, pandoc.RawInline("typst", " #label(\"" .. s .. "\")")}
end
if FORMAT == "docx" or FORMAT == "html" then
return {el}
end
end
Expand All @@ -35,7 +39,11 @@ function Cite(el)
cites[citation.id] = {cite_id}
end
end
return pandoc.Span(with_latex_label(cite_id, el), pandoc.Attr(cite_id))
if FORMAT == "typst" then
return pandoc.Span(with_label(cite_id, el))
else
return pandoc.Span(with_label(cite_id, el), pandoc.Attr(cite_id))
end
end

function append_inline(blocks, inlines)
Expand Down Expand Up @@ -63,7 +71,6 @@ function Div(el)

for i,cite_id in ipairs(cites[citation_id] or {}) do
local marker = pandoc.Str(i)

if FORMAT == "latex" then
marker = pandoc.RawInline("latex", "\\pageref{" .. cite_id .. "}")
end
Expand Down

0 comments on commit e00337f

Please sign in to comment.