diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 01553a3e..6957acf4 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -58,4 +58,4 @@ jobs: # we integrate a random UUID into the key to keep them different. # DO NOT CHANGE THIS - name: Test LaTeX package - run: l3build check -q -H + run: l3build check -q diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f14880c..214ebed8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### 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 diff --git a/citeproc/citeproc-latex-core.lua b/citeproc/citeproc-latex-core.lua index 8472818b..b77f7b68 100644 --- a/citeproc/citeproc-latex-core.lua +++ b/citeproc/citeproc-latex-core.lua @@ -265,6 +265,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/citeproc/citeproc-latex.lua b/citeproc/citeproc-latex.lua index cce8f2a1..bd23fc93 100644 --- a/citeproc/citeproc-latex.lua +++ b/citeproc/citeproc-latex.lua @@ -145,6 +145,7 @@ function csl.bibliography() end local result = core.make_bibliography(csl.engine) + -- util.debug(result) tex.print(util.split(result, "\n")) end diff --git a/citeproc/citeproc-output.lua b/citeproc/citeproc-output.lua index 6aca4533..6e9947c2 100644 --- a/citeproc/citeproc-output.lua +++ b/citeproc/citeproc-output.lua @@ -1256,25 +1256,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 +1343,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/test/latex/config-other-1.lua b/test/latex/config-other-1.lua index 07f0006a..4c344981 100644 --- a/test/latex/config-other-1.lua +++ b/test/latex/config-other-1.lua @@ -6,3 +6,11 @@ checkengines = {"pdftex", "xetex"} stdengine = "pdftex" checkruns = 1 + +-- function runtest_tasks(name, run) +-- if run == 1 then +-- return "texlua citeproc-lua.lua " .. name +-- else +-- return "" +-- end +-- end diff --git a/test/latex/luatex-1-csl.lvt b/test/latex/luatex-1-author-date.lvt similarity index 100% rename from test/latex/luatex-1-csl.lvt rename to test/latex/luatex-1-author-date.lvt diff --git a/test/latex/luatex-2-csl.tlg b/test/latex/luatex-1-author-date.tlg similarity index 99% rename from test/latex/luatex-2-csl.tlg rename to test/latex/luatex-1-author-date.tlg index 56f92139..9f5210fd 100644 --- a/test/latex/luatex-2-csl.tlg +++ b/test/latex/luatex-1-author-date.tlg @@ -91,4 +91,4 @@ braces): l. ...} ============================================================ [1 -] (luatex-2-csl.aux) +] (luatex-1-author-date.aux) diff --git a/test/latex/luatex-1-numeric.lvt b/test/latex/luatex-1-numeric.lvt new file mode 100644 index 00000000..5ab3c9a5 --- /dev/null +++ b/test/latex/luatex-1-numeric.lvt @@ -0,0 +1,24 @@ +\input{regression-test} + +\documentclass{article} + +\input{csl-test} + +\usepackage{citation-style-language} + +\cslsetup{style = ieee} +\addbibresource{test.bib} + + +\begin{document} + +\START + +\input{csl-citation-tests} + +\TEST{Bibilography}{ + \printbibliography + \showbibliography +} + +\end{document} diff --git a/test/latex/luatex-1-numeric.tlg b/test/latex/luatex-1-numeric.tlg new file mode 100644 index 00000000..32a516e2 --- /dev/null +++ b/test/latex/luatex-1-numeric.tlg @@ -0,0 +1,94 @@ +This is a generated file for the l3build validation system. +Don't change this file in any respect. +(csl-citation-tests.tex +============================================================ +TEST 1: Single cite item in a citation +============================================================ +> \l__csl_citation_tl=[1]. + } +l. ...} +============================================================ +============================================================ +TEST 2: Multiple cite items in a citation +============================================================ +> \l__csl_citation_tl=[1], [2]. + } +l. ...} +============================================================ +============================================================ +TEST 3: Citation with page locator +============================================================ +> \l__csl_citation_tl=[1, p. 6]. + } +l. ...} +============================================================ +============================================================ +TEST 4: Citation with section locator +============================================================ +> \l__csl_citation_tl=[1, Sec. 2.3]. + } +l. ...} +============================================================ +============================================================ +TEST 5: Citation with implicit page locator +============================================================ +> \l__csl_citation_tl=[1, p. 6]. + } +l. ...} +============================================================ +============================================================ +TEST 6: Citation with prefix and suffix +============================================================ +> \l__csl_citation_tl=prefix [1] suffix. + } +l. ...} +============================================================ +============================================================ +TEST 7: Citation with implicit prefix and suffix +============================================================ +> \l__csl_citation_tl=prefix [1], suffix. + } +l. ...} +============================================================ +============================================================ +TEST 8: Citation with implicit suffix +============================================================ +> \l__csl_citation_tl=[1], suffix. + } +l. ...} +============================================================ +============================================================ +TEST 9: Citation with implicit prefix +============================================================ +> \l__csl_citation_tl=prefix [1]. + } +l. ...} +============================================================ +============================================================ +TEST 10: Multiple cite items with options +============================================================ +> \l__csl_citation_tl=See [1, p. 6], [2, Fig. 2]. + } +l. ...} +============================================================ +============================================================ +TEST 11: Item in bibliography but no citation +============================================================ +> \l__csl_citation_tl=. + } +l. ...} +============================================================ +) +============================================================ +TEST 12: Bibilography +============================================================ +The comma list \g__csl_bib_items_clist contains the items (without outer +braces): +> {ITEM-1} +> {ITEM-2} +> {ITEM-3}. + } +l. ...} +============================================================ +[1 +] (luatex-1-numeric.aux) diff --git a/test/latex/luatex-2-csl.lvt b/test/latex/luatex-2-author-date.lvt similarity index 100% rename from test/latex/luatex-2-csl.lvt rename to test/latex/luatex-2-author-date.lvt diff --git a/test/latex/other-2-csl.tlg b/test/latex/luatex-2-author-date.tlg similarity index 99% rename from test/latex/other-2-csl.tlg rename to test/latex/luatex-2-author-date.tlg index 69f790ad..f72f480b 100644 --- a/test/latex/other-2-csl.tlg +++ b/test/latex/luatex-2-author-date.tlg @@ -91,4 +91,4 @@ braces): l. ...} ============================================================ [1 -] (other-2-csl.aux) +] (luatex-2-author-date.aux) diff --git a/test/latex/luatex-2-numeric.lvt b/test/latex/luatex-2-numeric.lvt new file mode 100644 index 00000000..5ab3c9a5 --- /dev/null +++ b/test/latex/luatex-2-numeric.lvt @@ -0,0 +1,24 @@ +\input{regression-test} + +\documentclass{article} + +\input{csl-test} + +\usepackage{citation-style-language} + +\cslsetup{style = ieee} +\addbibresource{test.bib} + + +\begin{document} + +\START + +\input{csl-citation-tests} + +\TEST{Bibilography}{ + \printbibliography + \showbibliography +} + +\end{document} diff --git a/test/latex/luatex-2-numeric.tlg b/test/latex/luatex-2-numeric.tlg new file mode 100644 index 00000000..3d73237c --- /dev/null +++ b/test/latex/luatex-2-numeric.tlg @@ -0,0 +1,94 @@ +This is a generated file for the l3build validation system. +Don't change this file in any respect. +(csl-citation-tests.tex +============================================================ +TEST 1: Single cite item in a citation +============================================================ +> \l__csl_citation_tl=[1]. + } +l. ...} +============================================================ +============================================================ +TEST 2: Multiple cite items in a citation +============================================================ +> \l__csl_citation_tl=[1], [2]. + } +l. ...} +============================================================ +============================================================ +TEST 3: Citation with page locator +============================================================ +> \l__csl_citation_tl=[1, p. 6]. + } +l. ...} +============================================================ +============================================================ +TEST 4: Citation with section locator +============================================================ +> \l__csl_citation_tl=[1, Sec. 2.3]. + } +l. ...} +============================================================ +============================================================ +TEST 5: Citation with implicit page locator +============================================================ +> \l__csl_citation_tl=[1, p. 6]. + } +l. ...} +============================================================ +============================================================ +TEST 6: Citation with prefix and suffix +============================================================ +> \l__csl_citation_tl=prefix [1] suffix. + } +l. ...} +============================================================ +============================================================ +TEST 7: Citation with implicit prefix and suffix +============================================================ +> \l__csl_citation_tl=prefix [1], suffix. + } +l. ...} +============================================================ +============================================================ +TEST 8: Citation with implicit suffix +============================================================ +> \l__csl_citation_tl=[1], suffix. + } +l. ...} +============================================================ +============================================================ +TEST 9: Citation with implicit prefix +============================================================ +> \l__csl_citation_tl=prefix [1]. + } +l. ...} +============================================================ +============================================================ +TEST 10: Multiple cite items with options +============================================================ +> \l__csl_citation_tl=See [1, p. 6], [2, Fig. 2]. + } +l. ...} +============================================================ +============================================================ +TEST 11: Item in bibliography but no citation +============================================================ +> \l__csl_citation_tl=. + } +l. ...} +============================================================ +) +============================================================ +TEST 12: Bibilography +============================================================ +The comma list \g__csl_bib_items_clist contains the items (without outer +braces): +> {ITEM-1} +> {ITEM-2} +> {ITEM-3}. + } +l. ...} +============================================================ +[1 +] (luatex-2-numeric.aux) diff --git a/test/latex/other-1-csl.lvt b/test/latex/other-1-author-date.lvt similarity index 100% rename from test/latex/other-1-csl.lvt rename to test/latex/other-1-author-date.lvt diff --git a/test/latex/other-1-author-date.tlg b/test/latex/other-1-author-date.tlg new file mode 100644 index 00000000..4f7690b4 --- /dev/null +++ b/test/latex/other-1-author-date.tlg @@ -0,0 +1,109 @@ +This is a generated file for the l3build validation system. +Don't change this file in any respect. +(csl-citation-tests.tex +============================================================ +TEST 1: Single cite item in a citation +============================================================ +Package citation-style-language Warning: Citation `ITEM-1' on page 1 undefined +(citation-style-language) on line .... +> \l__csl_citation_tl=[\textbf {ITEM-1}]. + } +l. ...} +============================================================ +============================================================ +TEST 2: Multiple cite items in a citation +============================================================ +Package citation-style-language Warning: Citation `ITEM-1, ITEM-2' on page 1 +(citation-style-language) undefined on line .... +> \l__csl_citation_tl=[\textbf {ITEM-1, ITEM-2}]. + } +l. ...} +============================================================ +============================================================ +TEST 3: Citation with page locator +============================================================ +Package citation-style-language Warning: Citation `ITEM-1' on page 1 undefined +(citation-style-language) on line .... +> \l__csl_citation_tl=[\textbf {ITEM-1}]. + } +l. ...} +============================================================ +============================================================ +TEST 4: Citation with section locator +============================================================ +Package citation-style-language Warning: Citation `ITEM-1' on page 1 undefined +(citation-style-language) on line .... +> \l__csl_citation_tl=[\textbf {ITEM-1}]. + } +l. ...} +============================================================ +============================================================ +TEST 5: Citation with implicit page locator +============================================================ +Package citation-style-language Warning: Citation `ITEM-1' on page 1 undefined +(citation-style-language) on line .... +> \l__csl_citation_tl=[\textbf {ITEM-1}]. + } +l. ...} +============================================================ +============================================================ +TEST 6: Citation with prefix and suffix +============================================================ +Package citation-style-language Warning: Citation `ITEM-1' on page 1 undefined +(citation-style-language) on line .... +> \l__csl_citation_tl=[\textbf {ITEM-1}]. + } +l. ...} +============================================================ +============================================================ +TEST 7: Citation with implicit prefix and suffix +============================================================ +Package citation-style-language Warning: Citation `ITEM-1' on page 1 undefined +(citation-style-language) on line .... +> \l__csl_citation_tl=[\textbf {ITEM-1}]. + } +l. ...} +============================================================ +============================================================ +TEST 8: Citation with implicit suffix +============================================================ +Package citation-style-language Warning: Citation `ITEM-1' on page 1 undefined +(citation-style-language) on line .... +> \l__csl_citation_tl=[\textbf {ITEM-1}]. + } +l. ...} +============================================================ +============================================================ +TEST 9: Citation with implicit prefix +============================================================ +Package citation-style-language Warning: Citation `ITEM-1' on page 1 undefined +(citation-style-language) on line .... +> \l__csl_citation_tl=[\textbf {ITEM-1}]. + } +l. ...} +============================================================ +============================================================ +TEST 10: Multiple cite items with options +============================================================ +Package citation-style-language Warning: Citation `ITEM-1, ITEM-2' on page 1 +(citation-style-language) undefined on line .... +> \l__csl_citation_tl=[\textbf {ITEM-1, ITEM-2}]. + } +l. ...} +============================================================ +============================================================ +TEST 11: Item in bibliography but no citation +============================================================ +> \l__csl_citation_tl=. + } +l. ...} +============================================================ +) +============================================================ +TEST 12: Bibilography +============================================================ +Package citation-style-language Warning: The bibliography is empty. +============================================================ +[1 +] (other-1-author-date.aux) +LaTeX Warning: There were undefined references. diff --git a/test/latex/other-1-numeric.lvt b/test/latex/other-1-numeric.lvt new file mode 100644 index 00000000..5ab3c9a5 --- /dev/null +++ b/test/latex/other-1-numeric.lvt @@ -0,0 +1,24 @@ +\input{regression-test} + +\documentclass{article} + +\input{csl-test} + +\usepackage{citation-style-language} + +\cslsetup{style = ieee} +\addbibresource{test.bib} + + +\begin{document} + +\START + +\input{csl-citation-tests} + +\TEST{Bibilography}{ + \printbibliography + \showbibliography +} + +\end{document} diff --git a/test/latex/other-1-csl.tlg b/test/latex/other-1-numeric.tlg similarity index 99% rename from test/latex/other-1-csl.tlg rename to test/latex/other-1-numeric.tlg index 76645159..6324d63a 100644 --- a/test/latex/other-1-csl.tlg +++ b/test/latex/other-1-numeric.tlg @@ -105,5 +105,5 @@ TEST 12: Bibilography Package citation-style-language Warning: The bibliography is empty. ============================================================ [1 -] (other-1-csl.aux) +] (other-1-numeric.aux) LaTeX Warning: There were undefined references. diff --git a/test/latex/other-2-csl.lvt b/test/latex/other-2-author-date.lvt similarity index 100% rename from test/latex/other-2-csl.lvt rename to test/latex/other-2-author-date.lvt diff --git a/test/latex/luatex-1-csl.tlg b/test/latex/other-2-author-date.tlg similarity index 99% rename from test/latex/luatex-1-csl.tlg rename to test/latex/other-2-author-date.tlg index 9aab55ea..5b15e47b 100644 --- a/test/latex/luatex-1-csl.tlg +++ b/test/latex/other-2-author-date.tlg @@ -91,4 +91,4 @@ braces): l. ...} ============================================================ [1 -] (luatex-1-csl.aux) +] (other-2-author-date.aux) diff --git a/test/latex/other-2-numeric.lvt b/test/latex/other-2-numeric.lvt new file mode 100644 index 00000000..5ab3c9a5 --- /dev/null +++ b/test/latex/other-2-numeric.lvt @@ -0,0 +1,24 @@ +\input{regression-test} + +\documentclass{article} + +\input{csl-test} + +\usepackage{citation-style-language} + +\cslsetup{style = ieee} +\addbibresource{test.bib} + + +\begin{document} + +\START + +\input{csl-citation-tests} + +\TEST{Bibilography}{ + \printbibliography + \showbibliography +} + +\end{document} diff --git a/test/latex/other-2-numeric.tlg b/test/latex/other-2-numeric.tlg new file mode 100644 index 00000000..c8704a9c --- /dev/null +++ b/test/latex/other-2-numeric.tlg @@ -0,0 +1,94 @@ +This is a generated file for the l3build validation system. +Don't change this file in any respect. +(csl-citation-tests.tex +============================================================ +TEST 1: Single cite item in a citation +============================================================ +> \l__csl_citation_tl=[2]. + } +l. ...} +============================================================ +============================================================ +TEST 2: Multiple cite items in a citation +============================================================ +> \l__csl_citation_tl=[2], [3]. + } +l. ...} +============================================================ +============================================================ +TEST 3: Citation with page locator +============================================================ +> \l__csl_citation_tl=[2, p. 6]. + } +l. ...} +============================================================ +============================================================ +TEST 4: Citation with section locator +============================================================ +> \l__csl_citation_tl=[2, Sec. 2.3]. + } +l. ...} +============================================================ +============================================================ +TEST 5: Citation with implicit page locator +============================================================ +> \l__csl_citation_tl=[2, p. 6]. + } +l. ...} +============================================================ +============================================================ +TEST 6: Citation with prefix and suffix +============================================================ +> \l__csl_citation_tl=prefix [2] suffix. + } +l. ...} +============================================================ +============================================================ +TEST 7: Citation with implicit prefix and suffix +============================================================ +> \l__csl_citation_tl=prefix [2], suffix. + } +l. ...} +============================================================ +============================================================ +TEST 8: Citation with implicit suffix +============================================================ +> \l__csl_citation_tl=[2], suffix. + } +l. ...} +============================================================ +============================================================ +TEST 9: Citation with implicit prefix +============================================================ +> \l__csl_citation_tl=prefix [2]. + } +l. ...} +============================================================ +============================================================ +TEST 10: Multiple cite items with options +============================================================ +> \l__csl_citation_tl=See [2, p. 6], [3, Fig. 2]. + } +l. ...} +============================================================ +============================================================ +TEST 11: Item in bibliography but no citation +============================================================ +> \l__csl_citation_tl=. + } +l. ...} +============================================================ +) +============================================================ +TEST 12: Bibilography +============================================================ +The comma list \g__csl_bib_items_clist contains the items (without outer +braces): +> {ITEM-3} +> {ITEM-1} +> {ITEM-2}. + } +l. ...} +============================================================ +[1 +] (other-2-numeric.aux)