summaryrefslogtreecommitdiff
path: root/biblio
diff options
context:
space:
mode:
Diffstat (limited to 'biblio')
-rw-r--r--biblio/citation-style-language/CHANGELOG.md10
-rw-r--r--biblio/citation-style-language/citation-style-language-doc.pdfbin227617 -> 227617 bytes
-rw-r--r--biblio/citation-style-language/citation-style-language-doc.tex2
-rw-r--r--biblio/citation-style-language/citation-style-language.sty63
-rw-r--r--biblio/citation-style-language/citeproc-cli.lua4
-rw-r--r--biblio/citation-style-language/citeproc-latex-core.lua65
-rw-r--r--biblio/citation-style-language/citeproc-latex.lua3
-rw-r--r--biblio/citation-style-language/citeproc-output.lua48
-rw-r--r--biblio/citation-style-language/citeproc.lua2
9 files changed, 129 insertions, 68 deletions
diff --git a/biblio/citation-style-language/CHANGELOG.md b/biblio/citation-style-language/CHANGELOG.md
index 6dd051a601..1f5bc98a69 100644
--- a/biblio/citation-style-language/CHANGELOG.md
+++ b/biblio/citation-style-language/CHANGELOG.md
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+## [v0.2.2] - 2022-09-23
+
+### Fixed
+
+- `latexmk` can automatically call citeproc-lua when compiling with `pdflatex` or `xelatex` (thanks to [John Collins](http://personal.psu.edu/~jcc8/)).
+- Fix incorrect labels in numeric reference list ([#25](https://github.com/zepinglee/citeproc-lua/issues/25)).
+
## [v0.2.1] - 2022-09-18
### Changed
@@ -56,7 +63,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Initial CTAN release.
-[Unreleased]: https://github.com/zepinglee/citeproc-lua/compare/v0.2.1...HEAD
+[Unreleased]: https://github.com/zepinglee/citeproc-lua/compare/v0.2.2...HEAD
+[v0.2.2]: https://github.com/zepinglee/citeproc-lua/compare/v0.2.1...0.2.2
[v0.2.1]: https://github.com/zepinglee/citeproc-lua/compare/v0.2.0...0.2.1
[v0.2.0]: https://github.com/zepinglee/citeproc-lua/compare/v0.1.1...0.2.0
[v0.1.1]: https://github.com/zepinglee/citeproc-lua/compare/v0.1.0...v0.1.1
diff --git a/biblio/citation-style-language/citation-style-language-doc.pdf b/biblio/citation-style-language/citation-style-language-doc.pdf
index 6a7dd5f03f..f94a5152e5 100644
--- a/biblio/citation-style-language/citation-style-language-doc.pdf
+++ b/biblio/citation-style-language/citation-style-language-doc.pdf
Binary files differ
diff --git a/biblio/citation-style-language/citation-style-language-doc.tex b/biblio/citation-style-language/citation-style-language-doc.tex
index e4f9ea4376..2b5bc99058 100644
--- a/biblio/citation-style-language/citation-style-language-doc.tex
+++ b/biblio/citation-style-language/citation-style-language-doc.tex
@@ -49,7 +49,7 @@
}%
}
-\date{2022-09-18 v0.2.1}
+\date{2022-09-23 v0.2.2}
\maketitle
diff --git a/biblio/citation-style-language/citation-style-language.sty b/biblio/citation-style-language/citation-style-language.sty
index bc4acd29e2..30aaefdf42 100644
--- a/biblio/citation-style-language/citation-style-language.sty
+++ b/biblio/citation-style-language/citation-style-language.sty
@@ -9,7 +9,7 @@
\RequirePackage{expl3}
\RequirePackage{xparse}
-\ProvidesExplPackage {citation-style-language} {2022-09-18} {v0.2.1}
+\ProvidesExplPackage {citation-style-language} {2022-09-23} {v0.2.2}
{Citation Style Language for LaTeX}
\RequirePackage { l3keys2e }
@@ -414,26 +414,25 @@
\sys_if_engine_luatex:TF
{
\bool_if:NTF \l__csl_engine_initialized_bool
- { \lua_now:n { csl.bibliography() } }
+ {
+ \__csl_collect_bibliography:n { \lua_now:n { csl.bibliography() } }
+ % \tl_show:N \g__csl_bibliography_tl
+ \tl_use:N \g__csl_bibliography_tl
+ }
{ \msg_warning:nnn { citation-style-language } { bibliography / empty } }
}
{
\tl_if_empty:NTF \g__csl_bibliography_tl
{ \msg_warning:nnn { citation-style-language } { bibliography / empty } }
- { \exp_args:NV \__csl_print_bibliography:n \g__csl_bibliography_tl }
+ {
+ \tl_use:N \g__csl_bibliography_tl
+ }
}
}
\msg_new:nnn { citation-style-language } { bibliography / empty }
{ The~ bibliography~ is~ empty. }
-\cs_new:Npn \__csl_print_bibliography:n #1
- {
- \begin { thebibliography }
- #1
- \end { thebibliography }
- }
-
\tl_new:N \l__csl_style_tl
\clist_new:N \l__csl_bib_resources_clist
@@ -709,19 +708,38 @@
% of `thebibliography` is stored into \g__csl_bibliography_tl.
\cs_new:Npn \__csl_load_bbl:
{
+ % The \@input@ prints "No file ....bbl" in the .log file from which
+ % the latexmk decides to run $bibtex or not.
+ \__csl_collect_bibliography:n { \@input@ { \jobname .bbl } }
+ % \file_if_exist_input:nF { \jobname .bbl }
+ % {
+ % \msg_warning:nnx { citation-style-language } { file / non-exist} { \jobname .bbl }
+ % }
+ }
+
+% Collection the bibliography (as well as \cslsetup) into \g__csl_bibliography_setup_tl
+\cs_new:Npn \__csl_collect_bibliography:n #1
+ {
\group_begin:
\RenewDocumentCommand \cslsetup { m }
- { \tl_set:Nn \g__csl_bibliography_setup_tl {##1} }
+ { \tl_gset:Nn \g__csl_bibliography_setup_tl { \cslsetup { ##1 } } }
\RenewDocumentEnvironment { thebibliography } { m +b }
- { \tl_gset:Nn \g__csl_bibliography_tl { {##1} ##2 } }
+ {
+ \tl_gset:Nn \g__csl_bibliography_tl
+ {
+ \begin { thebibliography } {##1}
+ ##2
+ \end { thebibliography }
+ }
+ }
{ }
- % The \@input@ prints "No file ....bbl" in the .log file from which
- % the latexmk decides to run $bibtex or not.
- \@input@ { \jobname .bbl }
- % \file_if_exist_input:nF { \jobname .bbl }
- % {
- % \msg_warning:nnx { citation-style-language } { file / non-exist} { \jobname .bbl }
- % }
+ % Perform the execution
+ #1
+ \tl_if_empty:NF \g__csl_bibliography_setup_tl
+ {
+ \tl_gput_left:Nn \g__csl_bibliography_tl { \par }
+ \tl_gput_left:NV \g__csl_bibliography_tl \g__csl_bibliography_setup_tl
+ }
\group_end:
}
@@ -745,8 +763,11 @@
{ \clist_put_right:Nn \l__csl_bib_resources_clist {#2} }
+% In earlier time, \bibdata{xxx.json} was used but this causes latexmk unable
+% to find xxx.json.bib and it refuses to run the $bibtex procedure.
+% John Collins suggests using a different command than \bibdata.
\clist_new:N \g__csl_aux_bib_files_clist
-\cs_set:Npn \bibdata #1
+\cs_new:Npn \csl@data #1
{ \clist_gput_right:Nn \g__csl_aux_bib_files_clist {#1} }
@@ -759,7 +780,7 @@
\cs_new:Npn \__csl_write_aux_bibdata:n #1
{
\if@filesw
- \iow_now:Nx \@auxout { \token_to_str:N \bibdata {#1} }
+ \iow_now:Nx \@auxout { \token_to_str:N \csl@data {#1} }
\fi
}
diff --git a/biblio/citation-style-language/citeproc-cli.lua b/biblio/citation-style-language/citeproc-cli.lua
index a199c8e68c..9023728473 100644
--- a/biblio/citation-style-language/citeproc-cli.lua
+++ b/biblio/citation-style-language/citeproc-cli.lua
@@ -101,7 +101,7 @@ local function read_aux_file(aux_file)
if match then
bib_style = string.sub(match, 2, -2)
else
- match = string.match(line, "^\\bibdata%s*(%b{})")
+ match = string.match(line, "^\\csl@data%s*(%b{})")
if match then
for _, bib in ipairs(util.split(string.sub(match, 2, -2), "%s*,%s*")) do
table.insert(bib_files, bib)
@@ -145,6 +145,8 @@ local function process_aux_file(aux_file)
local citation_strings = core.process_citations(engine, citations)
+ -- util.debug(citation_strings)
+
local output_string = ""
for _, citation in ipairs(citations) do
diff --git a/biblio/citation-style-language/citeproc-latex-core.lua b/biblio/citation-style-language/citeproc-latex-core.lua
index 8472818bac..325217862b 100644
--- a/biblio/citation-style-language/citeproc-latex-core.lua
+++ b/biblio/citation-style-language/citeproc-latex-core.lua
@@ -196,13 +196,22 @@ end
function core.process_citations(engine, citations)
local citations_pre = {}
- core.update_uncited_items(engine, citations)
local citation_strings = {}
+ core.update_cited_and_uncited_ids(engine, citations)
+
for _, citation in ipairs(citations) do
if citation.citationID ~= "@nocite" then
+ -- local res = engine:processCitationCluster(citation, citations_pre, {})
+ -- for _, tuple in ipairs(res[2]) do
+ -- local citation_str = tuple[2]
+ -- local citation_id = tuple[3]
+ -- citation_strings[citation_id] = citation_str
+ -- util.debug(citation_str)
+ -- end
+
local citation_str = engine:process_citation(citation)
- citation_strings[citation.citationID] = citation_str
+ citation_strings[citation.citationID] = citation_str
table.insert(citations_pre, {citation.citationID, citation.properties.noteIndex})
end
@@ -211,35 +220,46 @@ function core.process_citations(engine, citations)
return citation_strings
end
+function core.update_cited_and_uncited_ids(engine, citations)
+ local id_list = {}
+ local id_map = {} -- Boolean map for checking if id in list
+ local uncited_id_list = {}
+ local uncited_id_map = {}
-function core.update_uncited_items(engine, citations)
- -- util.debug(core.uncite_all_items)
- if core.uncite_all_items then
- -- \nocite{*}
- for id, _ in pairs(core.bib) do
- table.insert(core.uncited_ids, id)
- end
- else
- for _, citation in ipairs(citations) do
- if citation.citationID == "@nocite" then
- for _, cite_item in ipairs(citation.citationItems) do
- if cite_item.id == "*" then
- if not core.uncite_all_items then
- for id, _ in pairs(core.bib) do
- table.insert(core.uncited_ids, id)
+ for _, citation in ipairs(citations) do
+ if citation.citationID == "@nocite" then
+ for _, cite_item in ipairs(citation.citationItems) do
+ if cite_item.id == "*" then
+ if not core.uncite_all_items then
+ for id, _ in pairs(core.bib) do
+ if not uncited_id_map[id] then
+ table.insert(uncited_id_list, id)
+ uncited_id_map[id] = true
end
- core.uncite_all_items = true
end
- else
- table.insert(core.uncited_ids, cite_item.id)
+ core.uncite_all_items = true
end
+ elseif not uncited_id_map[cite_item.id] then
+ table.insert(uncited_id_list, cite_item.id)
+ uncited_id_map[cite_item.id] = true
+ end
+ end
+
+ else -- Real citation
+ for _, cite_item in ipairs(citation.citationItems) do
+ if not id_map[cite_item.id] then
+ table.insert(id_list, cite_item.id)
+ id_map[cite_item.id] = true
end
end
+
end
end
- engine:updateUncitedItems(core.uncited_ids)
-end
+ engine:updateItems(id_list)
+ engine:updateUncitedItems(uncited_id_list)
+
+end
function core.make_bibliography(engine)
local result = engine:makeBibliography()
@@ -265,6 +285,7 @@ function core.make_bibliography(engine)
res = res .. bib_options
end
+ -- util.debug(params.bibstart)
if params.bibstart then
res = res .. params.bibstart
end
diff --git a/biblio/citation-style-language/citeproc-latex.lua b/biblio/citation-style-language/citeproc-latex.lua
index cce8f2a191..4b05f0bdd6 100644
--- a/biblio/citation-style-language/citeproc-latex.lua
+++ b/biblio/citation-style-language/citeproc-latex.lua
@@ -145,6 +145,9 @@ function csl.bibliography()
end
local result = core.make_bibliography(csl.engine)
+ -- util.debug(result)
+
+ -- token.set_macro("g__csl_bibliography_tl", result)
tex.print(util.split(result, "\n"))
end
diff --git a/biblio/citation-style-language/citeproc-output.lua b/biblio/citation-style-language/citeproc-output.lua
index 6aca4533da..97cc53fc4a 100644
--- a/biblio/citation-style-language/citeproc-output.lua
+++ b/biblio/citation-style-language/citeproc-output.lua
@@ -1191,7 +1191,7 @@ local LatexWriter = Markup:new()
LatexWriter.markups = {
["bibstart"] = function (engine)
- return string.format("\\begin{thebibliography}{%s}\n\n", engine.registry.longest_label)
+ return string.format("\\begin{thebibliography}{%s}\n", engine.registry.longest_label)
end,
["bibend"] = "\\end{thebibliography}",
["@font-style/normal"] = "{\\normalshape %s}",
@@ -1209,15 +1209,17 @@ LatexWriter.markups = {
["@vertical-align/baseline"] = false,
["@cite/entry"] = false,
["@bibliography/entry"] = function (str, context)
- if not string.match(str, "\\bibitem") then
+ if string.match(str, "\\bibitem") then
+ str = str .. "\n"
+ else
str = "\\bibitem{".. context.id .. "}\n" .. str .. "\n"
end
return str
end,
- ["@display/block"] = false,
- ["@display/left-margin"] = '\n <div class="csl-left-margin">%s</div>',
- ["@display/right-inline"] = '<div class="csl-right-inline">%s</div>\n ',
- ["@display/indent"] = '<div class="csl-indent">%s</div>\n ',
+ -- ["@display/block"] = false,
+ -- ["@display/left-margin"] = '\n <div class="csl-left-margin">%s</div>',
+ -- ["@display/right-inline"] = '<div class="csl-right-inline">%s</div>',
+ -- ["@display/indent"] = '<div class="csl-indent">%s</div>\n ',
}
function LatexWriter:write_escaped(str, context)
@@ -1256,25 +1258,27 @@ function LatexWriter:write_formatted(inline, context)
end
function LatexWriter:write_display(inline, context)
- local plainter_text_writer = output_module.PlainTextWriter:new()
- local str = plainter_text_writer:write_inline(inline)
- local len = utf8.len(str)
- if len > context.engine.registry.maxoffset then
- context.engine.registry.maxoffset = len
- context.engine.registry.longest_label = str
+ if inline.div == "left-margin" then
+ local plainter_text_writer = output_module.PlainTextWriter:new()
+ local str = plainter_text_writer:write_inline(inline)
+ local len = utf8.len(str)
+ if len > context.engine.registry.maxoffset then
+ context.engine.registry.maxoffset = len
+ context.engine.registry.longest_label = str
+ end
end
local res = self:write_children(inline, context)
- if inline.display == "left-margin" then
+ if inline.div == "left-margin" then
if string.match(res, "%]") then
res = "{" .. res .. "}"
end
res = string.format("\\bibitem[%s]{%s}\n", res, context.id)
- elseif inline.display == "right-inline" then
+ elseif inline.div == "right-inline" then
return res
- elseif inline.display == "block" then
+ elseif inline.div == "block" then
return ""
end
return res
@@ -1341,12 +1345,14 @@ function HtmlWriter:write_formatted(inline, context)
end
function HtmlWriter:write_display(inline, context)
- local plainter_text_writer = output_module.PlainTextWriter:new()
- local str = plainter_text_writer:write_inline(inline)
- local len = utf8.len(str)
- if len > context.engine.registry.maxoffset then
- context.engine.registry.maxoffset = len
- context.engine.registry.longest_label = str
+ if inline.div == "left-margin" then
+ local plainter_text_writer = output_module.PlainTextWriter:new()
+ local str = plainter_text_writer:write_inline(inline)
+ local len = utf8.len(str)
+ if len > context.engine.registry.maxoffset then
+ context.engine.registry.maxoffset = len
+ context.engine.registry.longest_label = str
+ end
end
if #inline.inlines == 0 then
diff --git a/biblio/citation-style-language/citeproc.lua b/biblio/citation-style-language/citeproc.lua
index 67b7396152..a4b0424530 100644
--- a/biblio/citation-style-language/citeproc.lua
+++ b/biblio/citation-style-language/citeproc.lua
@@ -9,7 +9,7 @@ local citeproc = {}
local engine = require("citeproc-engine")
local util = require("citeproc-util")
-citeproc.__VERSION__ = "0.2.1"
+citeproc.__VERSION__ = "0.2.2"
citeproc.new = engine.CiteProc.new
citeproc.util = util