Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
zepinglee committed Aug 27, 2024
1 parent 10e548e commit 75ea356
Show file tree
Hide file tree
Showing 9 changed files with 215 additions and 60 deletions.
129 changes: 69 additions & 60 deletions citeproc/citeproc-engine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,22 @@ local Registry = {}

---@class CiteProc
---@field style Style
---@field sys any
---@field locales Locale[]
---@field system_locales Locale[]
---@field lang string
---@field sys CiteProcSys
---@field locales table<LanguageCode, Locale>
---@field system_locales table<LanguageCode, Locale>
---@field lang LanguageCode
---@field output_format OutputFormat
---@field opt table
---@field registry Registry
---@field cite_first_note_numbers table<ItemId, NoteIndex>
---@field locale_tags_info_dict {[LanguageCode]: table}
---@field cite_last_note_numbers table<ItemId, NoteIndex>
---@field note_citations_map table<NoteIndex, CitationId[]>
---@field tainted_item_ids table<ItemId, boolean>
---@field disam_irs IrNode[]
---@field cite_irs_by_output table<string, IrNode[]>
---@field person_names PersonNameIr[]
---@field person_names_by_output table<string, PersonNameIr[]>
---@field locale_tags_info_dict table<LanguageCode, table>
local CiteProc = {}

---@class CiteProcSys
Expand All @@ -125,64 +132,61 @@ function CiteProc.new(sys, style, lang, force_lang)
if sys.retrieveItem == nil then
error("\"citeprocSys.retrieveItem\" required")
end
---@type CiteProc
local o = {}

o.style = Style:parse(style)

o.sys = sys
o.locales = {}
o.system_locales = {}

o.lang = o.style.default_locale
if not o.lang or force_lang then
o.lang = lang or "en-US"
local parsed_style = Style:parse(style)
local engine_lang = parsed_style.default_locale
if not engine_lang or force_lang then
engine_lang = lang or "en-US"
end

o.output_format = LatexWriter:new()

o.opt = {
-- Similar to citeproc-js's development_extensions.wrap_url_and_doi
wrap_url_and_doi = false,
citation_link = false,
title_link = false,
}

o.registry = {
citations_by_id = {}, -- A map
citation_list = {}, -- A list
citations_by_item_id = {}, -- A map from item id to a map of citations
registry = {}, -- A map of bibliographic meta data
reflist = {}, -- list of cited ids
uncited_list = {},
previous_citation = nil,
requires_sorting = false,
widest_label = "",
maxoffset = 0,
---@type CiteProc
local o = {
style = parsed_style,
sys = sys,
locales = {},
system_locales = {},
lang = engine_lang,
output_format = LatexWriter:new(),
opt = {
-- Similar to citeproc-js's development_extensions.wrap_url_and_doi
wrap_url_and_doi = false,
citation_link = false,
title_link = false,
},
registry = {
citations_by_id = {}, -- A map
citation_list = {}, -- A list
citations_by_item_id = {}, -- A map from item id to a map of citations
registry = {}, -- A map of bibliographic meta data
reflist = {}, -- list of cited ids
uncited_list = {},
previous_citation = nil,
requires_sorting = false,
widest_label = "",
maxoffset = 0,
},

cite_first_note_numbers = {},
cite_last_note_numbers = {},
note_citations_map = {},

tainted_item_ids = {},

disam_irs = {},
-- { <ir1>, <ir2>, ... }

cite_irs_by_output = {},
-- {
-- ["Roe, J"] = {<ir1>},
-- ["Doe, J"] = {<ir2>, <ir3>},
-- ["Doe, John"] = {<ir2>},
-- ["Doe, Jack"] = {<ir2>},
-- }

person_names = {},
person_names_by_output = {},

locale_tags_info_dict = {},
}

o.cite_first_note_numbers = {}
o.cite_last_note_numbers = {}
o.note_citations_map = {}

o.tainted_item_ids = {}

o.disam_irs = {}
-- { <ir1>, <ir2>, ... }

o.cite_irs_by_output = {}
-- {
-- ["Roe, J"] = {<ir1>},
-- ["Doe, J"] = {<ir2>, <ir3>},
-- ["Doe, John"] = {<ir2>},
-- ["Doe, Jack"] = {<ir2>},
-- }

o.person_names = {}
o.person_names_by_output = {}

o.locale_tags_info_dict = {}

setmetatable(o, { __index = CiteProc })
return o
end
Expand Down Expand Up @@ -480,6 +484,8 @@ function CiteProc:_check_input(citation, citationsPre, citationsPost)
util.warning(string.format("Chapter index sequence is not sane at citationsPre[%d]", i))
end
if chapter_number ~= last_chapter_number then
-- Reset

last_note_number = 0
end
last_chapter_number = chapter_number
Expand Down Expand Up @@ -741,6 +747,9 @@ function CiteProc:get_preceding_cite_item(cite_item, previous_cite, previous_cit
-- b. the current cite is the first cite in the citation, and the previous
-- citation consists of a single cite referencing the same item
local previous_note_number = previous_citation.properties.noteIndex
if not self.note_citations_map[previous_note_number] then
print(debug.traceback())
end
local num_previous_note_citations = #self.note_citations_map[previous_note_number]
if (previous_note_number == note_number - 1 and num_previous_note_citations == 1)
or previous_note_number == note_number then
Expand Down
21 changes: 21 additions & 0 deletions tests/latex/luatex-1/issue-75.lvt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
% <https://github.com/zepinglee/citeproc-lua/discussions/74>

\input{regression-test}
\documentclass{book}
\input{csl-test}

\usepackage[style=apa]{citation-style-language}
\cslsetup{regression-test = true}
\addbibresource{test.json}


\begin{document}
\START

\chapter{Chapter}
\section*{Section}
\cite{ITEM-1}
\nocite{ITEM-3}

\OMIT
\end{document}
15 changes: 15 additions & 0 deletions tests/latex/luatex-1/issue-75.tlg
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
This is a generated file for the l3build validation system.
Don't change this file in any respect.
Chapter 1.
> \l__csl_citation_info_tl=citationID={ITEM-1@1},citationItems={{id={ITEM-1}}},properties={noteIndex={0},chapterIndex={1}}.
<recently read> }
l. ...\cite{ITEM-1}
> \l__csl_citation_tl=(D’Arcus, 2005).
<recently read> }
l. ...\cite{ITEM-1}
> \l__csl_citation_info_tl=citationID={@nocite},citationItems={{id={ITEM-3}}},properties={noteIndex={0}}.
<recently read> }
l. ...\nocite{ITEM-3}
> \l__csl_citation_tl=.
<recently read> }
l. ...\nocite{ITEM-3}
21 changes: 21 additions & 0 deletions tests/latex/luatex-2/issue-75.lvt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
% <https://github.com/zepinglee/citeproc-lua/discussions/74>

\input{regression-test}
\documentclass{book}
\input{csl-test}

\usepackage[style=apa]{citation-style-language}
\cslsetup{regression-test = true}
\addbibresource{test.json}


\begin{document}
\START

\chapter{Chapter}
\section*{Section}
\cite{ITEM-1}
\nocite{ITEM-3}

\OMIT
\end{document}
15 changes: 15 additions & 0 deletions tests/latex/luatex-2/issue-75.tlg
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
This is a generated file for the l3build validation system.
Don't change this file in any respect.
Chapter 1.
> \l__csl_citation_info_tl=citationID={ITEM-1@1},citationItems={{id={ITEM-1}}},properties={noteIndex={0},chapterIndex={1}}.
<recently read> }
l. ...\cite{ITEM-1}
> \l__csl_citation_tl=(D’Arcus, 2005).
<recently read> }
l. ...\cite{ITEM-1}
> \l__csl_citation_info_tl=citationID={@nocite},citationItems={{id={ITEM-3}}},properties={noteIndex={0}}.
<recently read> }
l. ...\nocite{ITEM-3}
> \l__csl_citation_tl=.
<recently read> }
l. ...\nocite{ITEM-3}
21 changes: 21 additions & 0 deletions tests/latex/pdftex-1/issue-75.lvt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
% <https://github.com/zepinglee/citeproc-lua/discussions/74>

\input{regression-test}
\documentclass{book}
\input{csl-test}

\usepackage[style=apa]{citation-style-language}
\cslsetup{regression-test = true}
\addbibresource{test.json}


\begin{document}
\START

\chapter{Chapter}
\section*{Section}
\cite{ITEM-1}
\nocite{ITEM-3}

\OMIT
\end{document}
16 changes: 16 additions & 0 deletions tests/latex/pdftex-1/issue-75.tlg
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
This is a generated file for the l3build validation system.
Don't change this file in any respect.
Chapter 1.
> \l__csl_citation_info_tl=citationID={ITEM-1@1},citationItems={{id={ITEM-1}}},properties={noteIndex={0},chapterIndex={1}}.
<recently read> }
l. ...\cite{ITEM-1}
LaTeX Warning: Citation `ITEM-1' on page 1 undefined on input line ....
> \l__csl_citation_tl=[\textbf {ITEM-1}].
<recently read> }
l. ...\cite{ITEM-1}
> \l__csl_citation_info_tl=citationID={@nocite},citationItems={{id={ITEM-3}}},properties={noteIndex={0}}.
<recently read> }
l. ...\nocite{ITEM-3}
> \l__csl_citation_tl=.
<recently read> }
l. ...\nocite{ITEM-3}
21 changes: 21 additions & 0 deletions tests/latex/pdftex-2/issue-75.lvt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
% <https://github.com/zepinglee/citeproc-lua/discussions/74>

\input{regression-test}
\documentclass{book}
\input{csl-test}

\usepackage[style=apa]{citation-style-language}
\cslsetup{regression-test = true}
\addbibresource{test.json}


\begin{document}
\START

\chapter{Chapter}
\section*{Section}
\cite{ITEM-1}
\nocite{ITEM-3}

\OMIT
\end{document}
16 changes: 16 additions & 0 deletions tests/latex/pdftex-2/issue-75.tlg
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
This is a generated file for the l3build validation system.
Don't change this file in any respect.
Chapter 1.
> \l__csl_citation_info_tl=citationID={ITEM-1@1},citationItems={{id={ITEM-1}}},properties={noteIndex={0},chapterIndex={1}}.
<recently read> }
l. ...\cite{ITEM-1}
LaTeX Warning: Citation `ITEM-1' on page 1 undefined on input line ....
> \l__csl_citation_tl=[\textbf {ITEM-1}].
<recently read> }
l. ...\cite{ITEM-1}
> \l__csl_citation_info_tl=citationID={@nocite},citationItems={{id={ITEM-3}}},properties={noteIndex={0}}.
<recently read> }
l. ...\nocite{ITEM-3}
> \l__csl_citation_tl=.
<recently read> }
l. ...\nocite{ITEM-3}

0 comments on commit 75ea356

Please sign in to comment.