Skip to content

Commit 3752016

Browse files
committed
fix: improve handling of listoflistings commands in LaTeX metadata injection
1 parent 8e9761e commit 3752016

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/resources/filters/crossref/meta.lua

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ function crossrefMetaInject()
99
return trim(pandoc.write(pandoc.Pandoc(quarto.utils.as_blocks(inlines)), "latex"))
1010
end
1111
metaInjectLatex(meta, function(inject)
12-
1312
inject(usePackage("caption"))
1413

1514
inject(
@@ -21,10 +20,10 @@ function crossrefMetaInject()
2120
maybeRenewCommand("tablename", as_latex(title("tbl", "Table"))) ..
2221
"}\n"
2322
)
24-
23+
2524
if param("listings", false) then
2625
inject(
27-
"\\newcommand*\\listoflistings\\lstlistoflistings\n" ..
26+
"\\@ifundefined{listoflistings}{\\newcommand*\\listoflistings\\lstlistoflistings}{}\n" ..
2827
"\\AtBeginDocument{%\n" ..
2928
"\\renewcommand*\\lstlistlistingname{" .. listOfTitle("lol", "List of Listings") .. "}\n" ..
3029
"}\n"
@@ -38,7 +37,8 @@ function crossrefMetaInject()
3837
)
3938

4039
inject(
41-
"\\newcommand*\\listoflistings{\\listof{codelisting}{" .. listOfTitle("lol", "List of Listings") .. "}}\n"
40+
"\\@ifundefined{listoflistings}{\\newcommand*\\listoflistings{\\listof{codelisting}{" ..
41+
listOfTitle("lol", "List of Listings") .. "}}}{}\n"
4242
)
4343
end
4444

@@ -61,24 +61,23 @@ function crossrefMetaInject()
6161
"\n'', 'none', ':', 'colon', '.', 'period', ' ', 'space', and 'quad'")
6262
end
6363
end
64-
64+
6565
local theoremIncludes = theoremLatexIncludes()
6666
if theoremIncludes then
6767
inject(theoremIncludes)
6868
end
6969
end)
70-
70+
7171
return meta
7272
end
7373
}
7474
end
7575

76-
function maybeRenewCommand(command, arg)
76+
function maybeRenewCommand(command, arg)
7777
local commandWithArg = command .. "{" .. arg .. "}"
7878
return "\\ifdefined\\" .. command .. "\n " .. "\\renewcommand*\\" .. commandWithArg .. "\n\\else\n " .. "\\newcommand\\" .. commandWithArg .. "\n\\fi\n"
7979
end
8080

81-
8281
-- latex 'listof' title for type
8382
function listOfTitle(type, default)
8483
local title = crossrefOption(type .. "-title")

0 commit comments

Comments
 (0)