From 375201651ac38557b651f38a98793a870e8d191a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Canouil?= <8896044+mcanouil@users.noreply.github.com> Date: Sat, 26 Jul 2025 23:46:59 +0200 Subject: [PATCH] fix: improve handling of listoflistings commands in LaTeX metadata injection --- src/resources/filters/crossref/meta.lua | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/resources/filters/crossref/meta.lua b/src/resources/filters/crossref/meta.lua index 207f850e911..579089e13e1 100644 --- a/src/resources/filters/crossref/meta.lua +++ b/src/resources/filters/crossref/meta.lua @@ -9,7 +9,6 @@ function crossrefMetaInject() return trim(pandoc.write(pandoc.Pandoc(quarto.utils.as_blocks(inlines)), "latex")) end metaInjectLatex(meta, function(inject) - inject(usePackage("caption")) inject( @@ -21,10 +20,10 @@ function crossrefMetaInject() maybeRenewCommand("tablename", as_latex(title("tbl", "Table"))) .. "}\n" ) - + if param("listings", false) then inject( - "\\newcommand*\\listoflistings\\lstlistoflistings\n" .. + "\\@ifundefined{listoflistings}{\\newcommand*\\listoflistings\\lstlistoflistings}{}\n" .. "\\AtBeginDocument{%\n" .. "\\renewcommand*\\lstlistlistingname{" .. listOfTitle("lol", "List of Listings") .. "}\n" .. "}\n" @@ -38,7 +37,8 @@ function crossrefMetaInject() ) inject( - "\\newcommand*\\listoflistings{\\listof{codelisting}{" .. listOfTitle("lol", "List of Listings") .. "}}\n" + "\\@ifundefined{listoflistings}{\\newcommand*\\listoflistings{\\listof{codelisting}{" .. + listOfTitle("lol", "List of Listings") .. "}}}{}\n" ) end @@ -61,24 +61,23 @@ function crossrefMetaInject() "\n'', 'none', ':', 'colon', '.', 'period', ' ', 'space', and 'quad'") end end - + local theoremIncludes = theoremLatexIncludes() if theoremIncludes then inject(theoremIncludes) end end) - + return meta end } end -function maybeRenewCommand(command, arg) +function maybeRenewCommand(command, arg) local commandWithArg = command .. "{" .. arg .. "}" return "\\ifdefined\\" .. command .. "\n " .. "\\renewcommand*\\" .. commandWithArg .. "\n\\else\n " .. "\\newcommand\\" .. commandWithArg .. "\n\\fi\n" end - -- latex 'listof' title for type function listOfTitle(type, default) local title = crossrefOption(type .. "-title")