texlive[64484] Master/texmf-dist: citation-style-language (23sep22)

commits+karl at tug.org commits+karl at tug.org
Fri Sep 23 22:42:53 CEST 2022


Revision: 64484
          http://tug.org/svn/texlive?view=revision&revision=64484
Author:   karl
Date:     2022-09-23 22:42:52 +0200 (Fri, 23 Sep 2022)
Log Message:
-----------
citation-style-language (23sep22)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/latex/citation-style-language/CHANGELOG.md
    trunk/Master/texmf-dist/doc/latex/citation-style-language/citation-style-language-doc.pdf
    trunk/Master/texmf-dist/doc/latex/citation-style-language/citation-style-language-doc.tex
    trunk/Master/texmf-dist/doc/man/man1/citeproc-lua.man1.pdf
    trunk/Master/texmf-dist/scripts/citation-style-language/citeproc-cli.lua
    trunk/Master/texmf-dist/scripts/citation-style-language/citeproc-latex-core.lua
    trunk/Master/texmf-dist/scripts/citation-style-language/citeproc-latex.lua
    trunk/Master/texmf-dist/scripts/citation-style-language/citeproc-output.lua
    trunk/Master/texmf-dist/scripts/citation-style-language/citeproc.lua
    trunk/Master/texmf-dist/tex/latex/citation-style-language/citation-style-language.sty

Modified: trunk/Master/texmf-dist/doc/latex/citation-style-language/CHANGELOG.md
===================================================================
--- trunk/Master/texmf-dist/doc/latex/citation-style-language/CHANGELOG.md	2022-09-23 00:35:00 UTC (rev 64483)
+++ trunk/Master/texmf-dist/doc/latex/citation-style-language/CHANGELOG.md	2022-09-23 20:42:52 UTC (rev 64484)
@@ -7,6 +7,13 @@
 
 ## [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 @@
 
 - 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

Modified: trunk/Master/texmf-dist/doc/latex/citation-style-language/citation-style-language-doc.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/doc/latex/citation-style-language/citation-style-language-doc.tex
===================================================================
--- trunk/Master/texmf-dist/doc/latex/citation-style-language/citation-style-language-doc.tex	2022-09-23 00:35:00 UTC (rev 64483)
+++ trunk/Master/texmf-dist/doc/latex/citation-style-language/citation-style-language-doc.tex	2022-09-23 20:42:52 UTC (rev 64484)
@@ -49,7 +49,7 @@
   }%
 }
 
-\date{2022-09-18 v0.2.1}
+\date{2022-09-23 v0.2.2}
 
 \maketitle
 

Modified: trunk/Master/texmf-dist/doc/man/man1/citeproc-lua.man1.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/scripts/citation-style-language/citeproc-cli.lua
===================================================================
--- trunk/Master/texmf-dist/scripts/citation-style-language/citeproc-cli.lua	2022-09-23 00:35:00 UTC (rev 64483)
+++ trunk/Master/texmf-dist/scripts/citation-style-language/citeproc-cli.lua	2022-09-23 20:42:52 UTC (rev 64484)
@@ -101,7 +101,7 @@
     if match then
       bib_style = string.sub(match, 2, -2)
     else
-      match = string.match(line, "^\\bibdata%s*(%b{})")
+      match = string.match(line, "^\\csl at 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 citation_strings = core.process_citations(engine, citations)
 
+  -- util.debug(citation_strings)
+
   local output_string = ""
 
   for _, citation in ipairs(citations) do

Modified: trunk/Master/texmf-dist/scripts/citation-style-language/citeproc-latex-core.lua
===================================================================
--- trunk/Master/texmf-dist/scripts/citation-style-language/citeproc-latex-core.lua	2022-09-23 00:35:00 UTC (rev 64483)
+++ trunk/Master/texmf-dist/scripts/citation-style-language/citeproc-latex-core.lua	2022-09-23 20:42:52 UTC (rev 64484)
@@ -196,13 +196,22 @@
 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,36 +220,47 @@
   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)
+
+  engine:updateItems(id_list)
+  engine:updateUncitedItems(uncited_id_list)
+
 end
 
-
 function core.make_bibliography(engine)
   local result = engine:makeBibliography()
 
@@ -265,6 +285,7 @@
     res = res .. bib_options
   end
 
+  -- util.debug(params.bibstart)
   if params.bibstart then
     res = res .. params.bibstart
   end

Modified: trunk/Master/texmf-dist/scripts/citation-style-language/citeproc-latex.lua
===================================================================
--- trunk/Master/texmf-dist/scripts/citation-style-language/citeproc-latex.lua	2022-09-23 00:35:00 UTC (rev 64483)
+++ trunk/Master/texmf-dist/scripts/citation-style-language/citeproc-latex.lua	2022-09-23 20:42:52 UTC (rev 64484)
@@ -145,7 +145,10 @@
   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
 

Modified: trunk/Master/texmf-dist/scripts/citation-style-language/citeproc-output.lua
===================================================================
--- trunk/Master/texmf-dist/scripts/citation-style-language/citeproc-output.lua	2022-09-23 00:35:00 UTC (rev 64483)
+++ trunk/Master/texmf-dist/scripts/citation-style-language/citeproc-output.lua	2022-09-23 20:42:52 UTC (rev 64484)
@@ -1191,7 +1191,7 @@
 
 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 @@
   ["@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 @@
 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 @@
 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

Modified: trunk/Master/texmf-dist/scripts/citation-style-language/citeproc.lua
===================================================================
--- trunk/Master/texmf-dist/scripts/citation-style-language/citeproc.lua	2022-09-23 00:35:00 UTC (rev 64483)
+++ trunk/Master/texmf-dist/scripts/citation-style-language/citeproc.lua	2022-09-23 20:42:52 UTC (rev 64484)
@@ -9,7 +9,7 @@
 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

Modified: trunk/Master/texmf-dist/tex/latex/citation-style-language/citation-style-language.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/citation-style-language/citation-style-language.sty	2022-09-23 00:35:00 UTC (rev 64483)
+++ trunk/Master/texmf-dist/tex/latex/citation-style-language/citation-style-language.sty	2022-09-23 20:42:52 UTC (rev 64484)
@@ -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,13 +414,19 @@
     \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
+          }
       }
   }
 
@@ -427,14 +433,7 @@
 \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
 \tl_new:N \l__csl_prefix_separator_tl
@@ -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 at 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 at filesw
-      \iow_now:Nx \@auxout { \token_to_str:N \bibdata {#1} }
+      \iow_now:Nx \@auxout { \token_to_str:N \csl at data {#1} }
     \fi
   }
 



More information about the tex-live-commits mailing list.