Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/resources/filters/crossref/custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ function initialize_custom_crossref_categories(meta)
add_crossref_category(obj_entry)

if quarto.doc.isFormat("pdf") then
local function as_latex(inlines)
return trim(pandoc.write(pandoc.Pandoc(inlines), "latex"))
end
metaInjectLatex(meta, function(inject)
local env_name = entry["latex-env"]
local name = entry["name"]
Expand All @@ -80,7 +83,7 @@ function initialize_custom_crossref_categories(meta)
usePackage("float") .. "\n" ..
"\\floatstyle{plain}\n" ..
"\\@ifundefined{c@chapter}{\\newfloat{" .. env_name .. "}{h}{" .. list_of_name .. "}}{\\newfloat{" .. env_name .. "}{h}{" .. list_of_name .. "}[chapter]}\n" ..
"\\floatname{".. env_name .. "}{" .. titleString(ref_type, env_prefix) .. "}\n"
"\\floatname{".. env_name .. "}{" .. as_latex(title(ref_type, env_prefix)) .. "}\n"
)

-- FIXME this is a bit of hack for the case of custom categories with
Expand Down
31 changes: 27 additions & 4 deletions src/resources/filters/crossref/meta.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
function crossrefMetaInject()
return {
Meta = function(meta)
local function as_latex(inlines)
return trim(pandoc.write(pandoc.Pandoc(inlines), "latex"))
end
metaInjectLatex(meta, function(inject)

inject(usePackage("caption"))
Expand All @@ -14,30 +17,50 @@ function crossrefMetaInject()
maybeRenewCommand("contentsname", param("toc-title-document", "Table of contents")) ..
maybeRenewCommand("listfigurename", listOfTitle("lof", "List of Figures")) ..
maybeRenewCommand("listtablename", listOfTitle("lot", "List of Tables")) ..
maybeRenewCommand("figurename", titleString("fig", "Figure")) ..
maybeRenewCommand("tablename", titleString("tbl", "Table")) ..
maybeRenewCommand("figurename", as_latex(title("fig", "Figure"))) ..
maybeRenewCommand("tablename", as_latex(title("tbl", "Table"))) ..
"}\n"
)

if param("listings", false) then
inject(
"\\newcommand*\\listoflistings\\lstlistoflistings\n" ..
"\\AtBeginDocument{%\n" ..
"\\renewcommand*\\lstlistlistingname{" .. listOfTitle("lol", "List of Listigs") .. "}\n" ..
"\\renewcommand*\\lstlistlistingname{" .. listOfTitle("lol", "List of Listings") .. "}\n" ..
"}\n"
)
else
inject(
usePackage("float") .. "\n" ..
"\\floatstyle{ruled}\n" ..
"\\@ifundefined{c@chapter}{\\newfloat{codelisting}{h}{lop}}{\\newfloat{codelisting}{h}{lop}[chapter]}\n" ..
"\\floatname{codelisting}{" .. titleString("lst", "Listing") .. "}\n"
"\\floatname{codelisting}{" .. as_latex(title("lst", "Listing")) .. "}\n"
)

inject(
"\\newcommand*\\listoflistings{\\listof{codelisting}{" .. listOfTitle("lol", "List of Listings") .. "}}\n"
)
end

-- title-delim
if crossrefOption("title-delim") ~= nil then
local titleDelim = pandoc.utils.stringify(crossrefOption("title-delim"))
if titleDelim == ":" or titleDelim == "colon" then
inject("\\captionsetup{labelsep=colon}\n")
elseif titleDelim == "." or titleDelim == "period" then
inject("\\captionsetup{labelsep=period}\n")
elseif titleDelim == " " or titleDelim == "space" then
inject("\\captionsetup{labelsep=space}\n")
elseif titleDelim == "quad" then
inject("\\captionsetup{labelsep=quad}\n")
elseif titleDelim == "none" or titleDelim == "" then
inject("\\captionsetup{labelsep=none}\n")
else
warn("\nIgnoring invalid value for 'title-delim' option in PDF: " .. titleDelim .. "." ..
"\nThe valid values in the caption LaTeX package are:" ..
"\n'', 'none', ':', 'colon', '.', 'period', ' ', 'space', and 'quad'")
end
end

local theoremIncludes = theoremLatexIncludes()
if theoremIncludes then
Expand Down