' .. labels.solution
.. '
'))
blocks:extend(sol)
blocks:insert(pandoc.RawBlock("html", "
"))
end
return pandoc.Div(blocks, pandoc.Attr("exo-" .. num, { "exo" }))
end
------------------------------------------------------------------ latex
local function latex_exo(num, title, stmt, hints, sol)
local out = pandoc.Blocks({})
local head = pandoc.Inlines({
pandoc.RawInline("latex", "\\hypertarget{exo-" .. num .. "}{}"),
pandoc.Strong(head_inlines(num, title)),
})
out:insert(pandoc.Para(head))
out:extend(stmt)
for i, h in ipairs(hints) do
out:insert(pandoc.RawBlock("latex",
"\\begin{tcolorbox}[colback=notecolor!5!white,colframe=notecolor!40!white,colbacktitle=notecolor!15!white,"
.. "coltitle=black,fonttitle=\\small\\bfseries,title={" .. labels.hint
.. " " .. i .. "},left=1.5mm,right=1.5mm,top=1mm,bottom=1mm]"))
out:extend(h)
out:insert(pandoc.RawBlock("latex", "\\end{tcolorbox}"))
end
local solblocks = nil
if sol ~= nil then
out:insert(pandoc.Para(pandoc.Inlines({
pandoc.RawInline("latex",
"{\\small\\itshape\\hyperlink{sol-" .. num .. "}{" .. labels.solution
.. " " .. num .. " $\\to$ p.\\,\\pageref{sol:" .. num .. "}}}"),
})))
solblocks = pandoc.Blocks({ pandoc.Para(pandoc.Inlines({
pandoc.RawInline("latex",
"\\hypertarget{sol-" .. num .. "}{}\\label{sol:" .. num .. "}"),
pandoc.Strong(pandoc.Inlines({ pandoc.Str(labels.solution .. " " .. num) })),
pandoc.Str("\u{2002}"),
pandoc.RawInline("latex",
"{\\small(\\hyperlink{exo-" .. num .. "}{$\\leftarrow$ "
.. labels.label .. " " .. num .. "})}"),
})) })
solblocks:extend(sol)
end
return out, solblocks
end
------------------------------------------------------------------ walk
local function walk(doc)
local is_latex = fmt_is("latex")
local is_html = fmt_is("html")
local chapter, cnt = 0, 0
local pending = {}
local out = pandoc.Blocks({})
local function flush()
if #pending == 0 then return end
out:insert(pandoc.Header(2,
pandoc.Inlines({ pandoc.Str(labels.solutions) }),
pandoc.Attr("", { "unnumbered" })))
for _, s in ipairs(pending) do out:extend(s) end
pending = {}
end
for _, b in ipairs(doc.blocks) do
if b.t == "Header" and b.level == 1 then
if is_latex then flush() end
if not b.classes:includes("unnumbered") then -- prefaces etc. don't count
chapter = chapter + 1
cnt = 0
end
out:insert(b)
elseif b.t == "Div" and b.classes:includes("exo") then
cnt = cnt + 1
local num = chapter > 0 and (chapter .. "." .. cnt) or tostring(cnt)
local stmt, hints, sol = split_exo(b)
if is_latex then
local inplace, solb = latex_exo(num, b.attributes.title, stmt, hints, sol)
out:extend(inplace)
if solb ~= nil then pending[#pending + 1] = solb end
elseif is_html then
out:insert(html_exo(num, b.attributes.title, stmt, hints, sol))
else
out:insert(b)
end
else
out:insert(b)
end
end
if is_latex then flush() end
doc.blocks = out
return doc
end
return {
{ Meta = read_meta },
{ Pandoc = walk },
}