Skip to content

Commit

Permalink
Fix chapter number with \nocite (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
zepinglee committed Aug 27, 2024
1 parent dd37879 commit 4de9a65
Show file tree
Hide file tree
Showing 11 changed files with 263 additions and 65 deletions.
124 changes: 64 additions & 60 deletions citeproc/citeproc-engine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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<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 @@ -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 = {},
-- { <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
9 changes: 6 additions & 3 deletions citeproc/citeproc-manager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions latex/citation-style-language-cite.sty
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
23 changes: 23 additions & 0 deletions tests/latex/luatex-1/issue-75.lvt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
% <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}

\printbibliography

\OMIT
\end{document}
26 changes: 26 additions & 0 deletions tests/latex/luatex-1/issue-75.tlg
Original file line number Diff line number Diff line change
@@ -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}}.
<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},chapterIndex={1}}.
<recently read> }
l. ...\nocite{ITEM-3}
> \l__csl_citation_tl=.
<recently read> }
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}}.
<recently read> }
l. ...
[1
]
[2
]
23 changes: 23 additions & 0 deletions tests/latex/luatex-2/issue-75.lvt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
% <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}

\printbibliography

\OMIT
\end{document}
26 changes: 26 additions & 0 deletions tests/latex/luatex-2/issue-75.tlg
Original file line number Diff line number Diff line change
@@ -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}}.
<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},chapterIndex={1}}.
<recently read> }
l. ...\nocite{ITEM-3}
> \l__csl_citation_tl=.
<recently read> }
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}}.
<recently read> }
l. ...
[1
]
[2
]
23 changes: 23 additions & 0 deletions tests/latex/pdftex-1/issue-75.lvt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
% <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}

\printbibliography

\OMIT
\end{document}
17 changes: 17 additions & 0 deletions tests/latex/pdftex-1/issue-75.tlg
Original file line number Diff line number Diff line change
@@ -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}}.
<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},chapterIndex={1}}.
<recently read> }
l. ...\nocite{ITEM-3}
> \l__csl_citation_tl=.
<recently read> }
l. ...\nocite{ITEM-3}
Package CSL Warning: The bibliography is empty.
23 changes: 23 additions & 0 deletions tests/latex/pdftex-2/issue-75.lvt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
% <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}

\printbibliography

\OMIT
\end{document}
26 changes: 26 additions & 0 deletions tests/latex/pdftex-2/issue-75.tlg
Original file line number Diff line number Diff line change
@@ -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}}.
<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},chapterIndex={1}}.
<recently read> }
l. ...\nocite{ITEM-3}
> \l__csl_citation_tl=.
<recently read> }
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}}.
<recently read> }
l. ...
[1
]
[2
]

0 comments on commit 4de9a65

Please sign in to comment.