From 75ea356eb2a3fedb6c45df9158eff9f5f860a2a3 Mon Sep 17 00:00:00 2001 From: Zeping Lee Date: Tue, 27 Aug 2024 14:38:41 +0800 Subject: [PATCH] WIP --- citeproc/citeproc-engine.lua | 129 ++++++++++++++++-------------- tests/latex/luatex-1/issue-75.lvt | 21 +++++ tests/latex/luatex-1/issue-75.tlg | 15 ++++ tests/latex/luatex-2/issue-75.lvt | 21 +++++ tests/latex/luatex-2/issue-75.tlg | 15 ++++ tests/latex/pdftex-1/issue-75.lvt | 21 +++++ tests/latex/pdftex-1/issue-75.tlg | 16 ++++ tests/latex/pdftex-2/issue-75.lvt | 21 +++++ tests/latex/pdftex-2/issue-75.tlg | 16 ++++ 9 files changed, 215 insertions(+), 60 deletions(-) create mode 100644 tests/latex/luatex-1/issue-75.lvt create mode 100644 tests/latex/luatex-1/issue-75.tlg create mode 100644 tests/latex/luatex-2/issue-75.lvt create mode 100644 tests/latex/luatex-2/issue-75.tlg create mode 100644 tests/latex/pdftex-1/issue-75.lvt create mode 100644 tests/latex/pdftex-1/issue-75.tlg create mode 100644 tests/latex/pdftex-2/issue-75.lvt create mode 100644 tests/latex/pdftex-2/issue-75.tlg diff --git a/citeproc/citeproc-engine.lua b/citeproc/citeproc-engine.lua index 4bfab23..a490f8e 100644 --- a/citeproc/citeproc-engine.lua +++ b/citeproc/citeproc-engine.lua @@ -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 +---@field system_locales table +---@field lang LanguageCode ---@field output_format OutputFormat ---@field opt table ---@field registry Registry ---@field cite_first_note_numbers table ----@field locale_tags_info_dict {[LanguageCode]: table} +---@field cite_last_note_numbers table +---@field note_citations_map table +---@field tainted_item_ids table +---@field disam_irs IrNode[] +---@field cite_irs_by_output table +---@field person_names PersonNameIr[] +---@field person_names_by_output table +---@field locale_tags_info_dict table local CiteProc = {} ---@class CiteProcSys @@ -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 = {}, + -- { , , ... } + + cite_irs_by_output = {}, + -- { + -- ["Roe, J"] = {}, + -- ["Doe, J"] = {, }, + -- ["Doe, John"] = {}, + -- ["Doe, Jack"] = {}, + -- } + + 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 = {} - -- { , , ... } - - o.cite_irs_by_output = {} - -- { - -- ["Roe, J"] = {}, - -- ["Doe, J"] = {, }, - -- ["Doe, John"] = {}, - -- ["Doe, Jack"] = {}, - -- } - - o.person_names = {} - o.person_names_by_output = {} - - o.locale_tags_info_dict = {} - setmetatable(o, { __index = CiteProc }) return o end @@ -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 @@ -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 diff --git a/tests/latex/luatex-1/issue-75.lvt b/tests/latex/luatex-1/issue-75.lvt new file mode 100644 index 0000000..51f1800 --- /dev/null +++ b/tests/latex/luatex-1/issue-75.lvt @@ -0,0 +1,21 @@ +% + +\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} diff --git a/tests/latex/luatex-1/issue-75.tlg b/tests/latex/luatex-1/issue-75.tlg new file mode 100644 index 0000000..4a26282 --- /dev/null +++ b/tests/latex/luatex-1/issue-75.tlg @@ -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}}. + } +l. ...\cite{ITEM-1} +> \l__csl_citation_tl=(D’Arcus, 2005). + } +l. ...\cite{ITEM-1} +> \l__csl_citation_info_tl=citationID={@nocite},citationItems={{id={ITEM-3}}},properties={noteIndex={0}}. + } +l. ...\nocite{ITEM-3} +> \l__csl_citation_tl=. + } +l. ...\nocite{ITEM-3} diff --git a/tests/latex/luatex-2/issue-75.lvt b/tests/latex/luatex-2/issue-75.lvt new file mode 100644 index 0000000..51f1800 --- /dev/null +++ b/tests/latex/luatex-2/issue-75.lvt @@ -0,0 +1,21 @@ +% + +\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} diff --git a/tests/latex/luatex-2/issue-75.tlg b/tests/latex/luatex-2/issue-75.tlg new file mode 100644 index 0000000..4a26282 --- /dev/null +++ b/tests/latex/luatex-2/issue-75.tlg @@ -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}}. + } +l. ...\cite{ITEM-1} +> \l__csl_citation_tl=(D’Arcus, 2005). + } +l. ...\cite{ITEM-1} +> \l__csl_citation_info_tl=citationID={@nocite},citationItems={{id={ITEM-3}}},properties={noteIndex={0}}. + } +l. ...\nocite{ITEM-3} +> \l__csl_citation_tl=. + } +l. ...\nocite{ITEM-3} diff --git a/tests/latex/pdftex-1/issue-75.lvt b/tests/latex/pdftex-1/issue-75.lvt new file mode 100644 index 0000000..51f1800 --- /dev/null +++ b/tests/latex/pdftex-1/issue-75.lvt @@ -0,0 +1,21 @@ +% + +\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} diff --git a/tests/latex/pdftex-1/issue-75.tlg b/tests/latex/pdftex-1/issue-75.tlg new file mode 100644 index 0000000..6f85169 --- /dev/null +++ b/tests/latex/pdftex-1/issue-75.tlg @@ -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}}. + } +l. ...\cite{ITEM-1} +LaTeX Warning: Citation `ITEM-1' on page 1 undefined on input line .... +> \l__csl_citation_tl=[\textbf {ITEM-1}]. + } +l. ...\cite{ITEM-1} +> \l__csl_citation_info_tl=citationID={@nocite},citationItems={{id={ITEM-3}}},properties={noteIndex={0}}. + } +l. ...\nocite{ITEM-3} +> \l__csl_citation_tl=. + } +l. ...\nocite{ITEM-3} diff --git a/tests/latex/pdftex-2/issue-75.lvt b/tests/latex/pdftex-2/issue-75.lvt new file mode 100644 index 0000000..51f1800 --- /dev/null +++ b/tests/latex/pdftex-2/issue-75.lvt @@ -0,0 +1,21 @@ +% + +\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} diff --git a/tests/latex/pdftex-2/issue-75.tlg b/tests/latex/pdftex-2/issue-75.tlg new file mode 100644 index 0000000..6f85169 --- /dev/null +++ b/tests/latex/pdftex-2/issue-75.tlg @@ -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}}. + } +l. ...\cite{ITEM-1} +LaTeX Warning: Citation `ITEM-1' on page 1 undefined on input line .... +> \l__csl_citation_tl=[\textbf {ITEM-1}]. + } +l. ...\cite{ITEM-1} +> \l__csl_citation_info_tl=citationID={@nocite},citationItems={{id={ITEM-3}}},properties={noteIndex={0}}. + } +l. ...\nocite{ITEM-3} +> \l__csl_citation_tl=. + } +l. ...\nocite{ITEM-3}