Skip to content

Commit

Permalink
Fix labels in bibligraphy (fix #25)
Browse files Browse the repository at this point in the history
  • Loading branch information
zepinglee committed Sep 23, 2022
1 parent 95ea0e2 commit d9100e7
Show file tree
Hide file tree
Showing 22 changed files with 522 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions citeproc/citeproc-latex-core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions citeproc/citeproc-latex.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 19 additions & 15 deletions citeproc/citeproc-output.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions test/latex/config-other-1.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,4 @@ braces):
l. ...}
============================================================
[1
] (luatex-2-csl.aux)
] (luatex-1-author-date.aux)
24 changes: 24 additions & 0 deletions test/latex/luatex-1-numeric.lvt
Original file line number Diff line number Diff line change
@@ -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}
94 changes: 94 additions & 0 deletions test/latex/luatex-1-numeric.tlg
Original file line number Diff line number Diff line change
@@ -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].
<recently read> }
l. ...}
============================================================
============================================================
TEST 2: Multiple cite items in a citation
============================================================
> \l__csl_citation_tl=[1], [2].
<recently read> }
l. ...}
============================================================
============================================================
TEST 3: Citation with page locator
============================================================
> \l__csl_citation_tl=[1, p. 6].
<recently read> }
l. ...}
============================================================
============================================================
TEST 4: Citation with section locator
============================================================
> \l__csl_citation_tl=[1, Sec. 2.3].
<recently read> }
l. ...}
============================================================
============================================================
TEST 5: Citation with implicit page locator
============================================================
> \l__csl_citation_tl=[1, p. 6].
<recently read> }
l. ...}
============================================================
============================================================
TEST 6: Citation with prefix and suffix
============================================================
> \l__csl_citation_tl=prefix [1] suffix.
<recently read> }
l. ...}
============================================================
============================================================
TEST 7: Citation with implicit prefix and suffix
============================================================
> \l__csl_citation_tl=prefix [1], suffix.
<recently read> }
l. ...}
============================================================
============================================================
TEST 8: Citation with implicit suffix
============================================================
> \l__csl_citation_tl=[1], suffix.
<recently read> }
l. ...}
============================================================
============================================================
TEST 9: Citation with implicit prefix
============================================================
> \l__csl_citation_tl=prefix [1].
<recently read> }
l. ...}
============================================================
============================================================
TEST 10: Multiple cite items with options
============================================================
> \l__csl_citation_tl=See [1, p. 6], [2, Fig. 2].
<recently read> }
l. ...}
============================================================
============================================================
TEST 11: Item in bibliography but no citation
============================================================
> \l__csl_citation_tl=.
<recently read> }
l. ...}
============================================================
)
============================================================
TEST 12: Bibilography
============================================================
The comma list \g__csl_bib_items_clist contains the items (without outer
braces):
> {ITEM-1}
> {ITEM-2}
> {ITEM-3}.
<recently read> }
l. ...}
============================================================
[1
] (luatex-1-numeric.aux)
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,4 @@ braces):
l. ...}
============================================================
[1
] (other-2-csl.aux)
] (luatex-2-author-date.aux)
24 changes: 24 additions & 0 deletions test/latex/luatex-2-numeric.lvt
Original file line number Diff line number Diff line change
@@ -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}
94 changes: 94 additions & 0 deletions test/latex/luatex-2-numeric.tlg
Original file line number Diff line number Diff line change
@@ -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].
<recently read> }
l. ...}
============================================================
============================================================
TEST 2: Multiple cite items in a citation
============================================================
> \l__csl_citation_tl=[1], [2].
<recently read> }
l. ...}
============================================================
============================================================
TEST 3: Citation with page locator
============================================================
> \l__csl_citation_tl=[1, p. 6].
<recently read> }
l. ...}
============================================================
============================================================
TEST 4: Citation with section locator
============================================================
> \l__csl_citation_tl=[1, Sec. 2.3].
<recently read> }
l. ...}
============================================================
============================================================
TEST 5: Citation with implicit page locator
============================================================
> \l__csl_citation_tl=[1, p. 6].
<recently read> }
l. ...}
============================================================
============================================================
TEST 6: Citation with prefix and suffix
============================================================
> \l__csl_citation_tl=prefix [1] suffix.
<recently read> }
l. ...}
============================================================
============================================================
TEST 7: Citation with implicit prefix and suffix
============================================================
> \l__csl_citation_tl=prefix [1], suffix.
<recently read> }
l. ...}
============================================================
============================================================
TEST 8: Citation with implicit suffix
============================================================
> \l__csl_citation_tl=[1], suffix.
<recently read> }
l. ...}
============================================================
============================================================
TEST 9: Citation with implicit prefix
============================================================
> \l__csl_citation_tl=prefix [1].
<recently read> }
l. ...}
============================================================
============================================================
TEST 10: Multiple cite items with options
============================================================
> \l__csl_citation_tl=See [1, p. 6], [2, Fig. 2].
<recently read> }
l. ...}
============================================================
============================================================
TEST 11: Item in bibliography but no citation
============================================================
> \l__csl_citation_tl=.
<recently read> }
l. ...}
============================================================
)
============================================================
TEST 12: Bibilography
============================================================
The comma list \g__csl_bib_items_clist contains the items (without outer
braces):
> {ITEM-1}
> {ITEM-2}
> {ITEM-3}.
<recently read> }
l. ...}
============================================================
[1
] (luatex-2-numeric.aux)
File renamed without changes.
Loading

0 comments on commit d9100e7

Please sign in to comment.