From 4de9a65b8f3ab92095abecae0b1891b66874324f Mon Sep 17 00:00:00 2001 From: Zeping Lee Date: Wed, 28 Aug 2024 00:43:01 +0800 Subject: [PATCH] Fix chapter number with \nocite (#75) --- citeproc/citeproc-engine.lua | 124 +++++++++++++------------ citeproc/citeproc-manager.lua | 9 +- latex/citation-style-language-cite.sty | 8 +- tests/latex/luatex-1/issue-75.lvt | 23 +++++ tests/latex/luatex-1/issue-75.tlg | 26 ++++++ tests/latex/luatex-2/issue-75.lvt | 23 +++++ tests/latex/luatex-2/issue-75.tlg | 26 ++++++ tests/latex/pdftex-1/issue-75.lvt | 23 +++++ tests/latex/pdftex-1/issue-75.tlg | 17 ++++ tests/latex/pdftex-2/issue-75.lvt | 23 +++++ tests/latex/pdftex-2/issue-75.tlg | 26 ++++++ 11 files changed, 263 insertions(+), 65 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 a30ca52..0f5e35c 100644 --- a/citeproc/citeproc-engine.lua +++ b/citeproc/citeproc-engine.lua @@ -105,15 +105,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 @@ -136,64 +143,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 diff --git a/citeproc/citeproc-manager.lua b/citeproc/citeproc-manager.lua index 6c95a94..4f824fe 100644 --- a/citeproc/citeproc-manager.lua +++ b/citeproc/citeproc-manager.lua @@ -864,9 +864,12 @@ function CslCitationManager:read_aux_file(aux_content) self:register_citation_info(tostring(ref_section_index), content) if ref_section.engine then local citation = self:_make_citation(content) - local citation_str = ref_section.engine:process_citation(citation) - - table.insert(output_lines, string.format("\\cslcitation{%s}{%s}", citation.citationID, citation_str)) + if citation.citationID == "@nocite" then + ref_section:_update_uncited_items() + else + local citation_str = ref_section.engine:process_citation(citation) + table.insert(output_lines, string.format("\\cslcitation{%s}{%s}", citation.citationID, citation_str)) + end end elseif command == "\\csl@aux@bibliography" then diff --git a/latex/citation-style-language-cite.sty b/latex/citation-style-language-cite.sty index 5bb57c7..38128a9 100644 --- a/latex/citation-style-language-cite.sty +++ b/latex/citation-style-language-cite.sty @@ -615,11 +615,15 @@ \__csl_collect_citation_items:nnn { } { } {#1} \tl_set:Nx \l__csl_cite_items_tl { \seq_use:Nn \l__csl_citation_items_seq { , } } + \prop_clear:N \l__csl_citation_properties_prop + \prop_put:Nnn \l__csl_citation_properties_prop { noteIndex } { 0 } + \__csl_make_chapter_property: + \__csl_serialize_prop:NN \l__csl_citation_properties_prop \l__csl_citation_properties_tl \tl_set:Nx \l__csl_citation_info_tl { citationID = { @nocite } , - citationItems = { \l__csl_cite_items_tl } , - properties = { noteIndex = { 0 } } + citationItems = { \tl_use:N \l__csl_cite_items_tl } , + properties = { \tl_use:N \l__csl_citation_properties_tl } } \bool_if:NT \l__csl_regression_test_bool { \tl_show:N \l__csl_citation_info_tl } diff --git a/tests/latex/luatex-1/issue-75.lvt b/tests/latex/luatex-1/issue-75.lvt new file mode 100644 index 0000000..36fb677 --- /dev/null +++ b/tests/latex/luatex-1/issue-75.lvt @@ -0,0 +1,23 @@ +% + +\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} + +\printbibliography + +\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..31e2683 --- /dev/null +++ b/tests/latex/luatex-1/issue-75.tlg @@ -0,0 +1,26 @@ +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},chapterIndex={1}}. + } +l. ...\nocite{ITEM-3} +> \l__csl_citation_tl=. + } +l. ...\nocite{ITEM-3} +The sequence \l__csl_bibliography_seq contains the items (without outer braces): +> {\begin {thebibliography}{index = 1, hanging-indent = true, line-spacing = 2, entry-spacing = 0}} +> {\bibitem {ITEM-1} D’Arcus, B. (2005). \textit {Boundaries of dissent: Protest and state power in the media age}. Routledge.} +> {\bibitem {ITEM-3} Lamport, L. (1994). \textit {LaTeX: A document preparation system: User’s guide and reference manual} (2nd ed.). Addison-Wesley.} +> {\end {thebibliography}}. + } +l. ... +[1 +] +[2 +] diff --git a/tests/latex/luatex-2/issue-75.lvt b/tests/latex/luatex-2/issue-75.lvt new file mode 100644 index 0000000..36fb677 --- /dev/null +++ b/tests/latex/luatex-2/issue-75.lvt @@ -0,0 +1,23 @@ +% + +\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} + +\printbibliography + +\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..31e2683 --- /dev/null +++ b/tests/latex/luatex-2/issue-75.tlg @@ -0,0 +1,26 @@ +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},chapterIndex={1}}. + } +l. ...\nocite{ITEM-3} +> \l__csl_citation_tl=. + } +l. ...\nocite{ITEM-3} +The sequence \l__csl_bibliography_seq contains the items (without outer braces): +> {\begin {thebibliography}{index = 1, hanging-indent = true, line-spacing = 2, entry-spacing = 0}} +> {\bibitem {ITEM-1} D’Arcus, B. (2005). \textit {Boundaries of dissent: Protest and state power in the media age}. Routledge.} +> {\bibitem {ITEM-3} Lamport, L. (1994). \textit {LaTeX: A document preparation system: User’s guide and reference manual} (2nd ed.). Addison-Wesley.} +> {\end {thebibliography}}. + } +l. ... +[1 +] +[2 +] diff --git a/tests/latex/pdftex-1/issue-75.lvt b/tests/latex/pdftex-1/issue-75.lvt new file mode 100644 index 0000000..36fb677 --- /dev/null +++ b/tests/latex/pdftex-1/issue-75.lvt @@ -0,0 +1,23 @@ +% + +\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} + +\printbibliography + +\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..3180ee6 --- /dev/null +++ b/tests/latex/pdftex-1/issue-75.tlg @@ -0,0 +1,17 @@ +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},chapterIndex={1}}. + } +l. ...\nocite{ITEM-3} +> \l__csl_citation_tl=. + } +l. ...\nocite{ITEM-3} +Package CSL Warning: The bibliography is empty. diff --git a/tests/latex/pdftex-2/issue-75.lvt b/tests/latex/pdftex-2/issue-75.lvt new file mode 100644 index 0000000..36fb677 --- /dev/null +++ b/tests/latex/pdftex-2/issue-75.lvt @@ -0,0 +1,23 @@ +% + +\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} + +\printbibliography + +\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..31e2683 --- /dev/null +++ b/tests/latex/pdftex-2/issue-75.tlg @@ -0,0 +1,26 @@ +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},chapterIndex={1}}. + } +l. ...\nocite{ITEM-3} +> \l__csl_citation_tl=. + } +l. ...\nocite{ITEM-3} +The sequence \l__csl_bibliography_seq contains the items (without outer braces): +> {\begin {thebibliography}{index = 1, hanging-indent = true, line-spacing = 2, entry-spacing = 0}} +> {\bibitem {ITEM-1} D’Arcus, B. (2005). \textit {Boundaries of dissent: Protest and state power in the media age}. Routledge.} +> {\bibitem {ITEM-3} Lamport, L. (1994). \textit {LaTeX: A document preparation system: User’s guide and reference manual} (2nd ed.). Addison-Wesley.} +> {\end {thebibliography}}. + } +l. ... +[1 +] +[2 +]