Skip to content

Commit

Permalink
fix(packages): Ignore @preamble in bibTeX bibliography
Browse files Browse the repository at this point in the history
Skip `@preamble` as done for `@comment`.
The `@preamble` command is used to provide TeX or LaTeX macros that
are processed by BibTeX program, but it is unspecified what to do
with these when converting to a format that does not use TeX.

See #2051
  • Loading branch information
Omikhleia authored and alerque committed Jun 23, 2024
1 parent ca906f0 commit 742a0c4
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions packages/bibtex/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@ local bibtexparser = epnf.define(function (_ENV)
local value = balanced + doubleq + myID
local pair = Cg(myTag * _ * "=" * _ * C(value)) * _ * sep^-1 / function (...) local t= {...}; return t[1], t[#t] end
local list = Cf(Ct("") * pair^0, rawset)
local commentKey = Cmt(R("az", "AZ")^1, function(_, _, a)
return a:lower() == "comment"
local skippedType = Cmt(R("az", "AZ")^1, function(_, _, tag)
-- ignore both @comment and @preamble
local t = tag:lower()
return t == "comment" or t == "preamble"
end)

START "document"
document = (V"comment" + V"entry")^1 -- order important: @comment must have precedence over @other
document = (V"skipped" + V"entry")^1 -- order important: skipped (@comment, @preamble) must be first
* (-1 + E("Unexpected character at end of input"))
comment = WS +
( V"blockcomment" + (P"%" * (1-S"\r\n")^0 * S"\r\n") / function () return "" end) -- Don't bother telling me about comments
blockcomment = (P("@") * commentKey) + balanced / function () return "" end -- Don't bother telling me about comments
skipped = WS +
( V"blockskipped" + (P"%" * (1-S"\r\n")^0 * S"\r\n") / "")
blockskipped = (P("@") * skippedType) + balanced / ""
entry = Ct( P("@") * Cg(myTag, "type") * _ * P("{") * _ * Cg(myID, "label") * _ * sep * list * P("}") * _ )
end)
-- luacheck: pop
Expand Down

0 comments on commit 742a0c4

Please sign in to comment.