-- further.lua — "to go further" notes, for material beside the lecture's own -- -- ::: {.further} -- Everything in here is optional reading. -- ::: -- -- ::: {.further title="Cantor pairing"} -- ... -- ::: -- -- The box is purple, so it reads as an aside and never as the course's own -- statement. HTML: a box with a heading. PDF: a tcolorbox in the same colour. -- -- Metadata: -- furthercolor: "#6B3FA0" # the accent of these notes -- further: -- label: "Pour aller plus loin" # defaults to the document `lang` local LABELS = { en = "To go further", fr = "Pour aller plus loin", de = "Vertiefung", } local DEFAULT_COLOR = "#6B3FA0" local label = LABELS.en local color = DEFAULT_COLOR local function fmt_is(name) if quarto and quarto.doc and quarto.doc.is_format then return quarto.doc.is_format(name) end return FORMAT ~= nil and FORMAT:match(name) ~= nil end local function str(v) if v == nil then return nil end if type(v) == "boolean" then return tostring(v) end return pandoc.utils.stringify(v) end local function esc_html(s) return (s:gsub("&", "&"):gsub("<", "<"):gsub(">", ">"):gsub('"', """)) end local function read_meta(meta) local lang = (str(meta.lang) or "en"):lower():gsub("[_-].*$", "") label = LABELS[lang] or LABELS.en if type(meta.further) == "table" and meta.further.label ~= nil then label = str(meta.further.label) end if meta.furthercolor ~= nil then color = str(meta.furthercolor) end local color_dark = meta["furthercolor-dark"] ~= nil and str(meta["furthercolor-dark"]) or nil if quarto ~= nil and quarto.doc ~= nil then if fmt_is("html") then quarto.doc.add_html_dependency({ name = "calc-further", version = "1.0.0", stylesheets = { "further.css" }, }) -- as for notecolor: the book's own colour is kept, and theme.css -- lifts it for a dark page instead of replacing it quarto.doc.include_text("in-header", table.concat({ "", }, "\n")) elseif fmt_is("latex") then -- same options as Quarto's callouts, so the two never clash quarto.doc.use_latex_package("tcolorbox", "skins,breakable") quarto.doc.use_latex_package("xcolor") quarto.doc.include_text("in-header", "\\definecolor{furthercolor}{HTML}{" .. color:gsub("^#", "") .. "}") end end return meta end ------------------------------------------------------------------ render -- `sep`: what goes between the label and a title= of its own. LaTeX fonts -- often lack the U+2002 glyph, so the pdf gets \enspace instead. local function head_text(el, sep) local title = el.attributes.title if title ~= nil and title ~= "" then return label .. (sep or "\u{2002}—\u{2002}") .. title end return label end local function html_box(el) local blocks = pandoc.Blocks({ pandoc.RawBlock("html", '