-- docs/book/pandoc/code-breaks.lua -- -- Inline code in the design record is full of long identifiers and paths -- (g_wirebind_attached_username, kernel/src/arch/riscv64/...), which LaTeX -- cannot break, so they run into the margin. Emit inline code as \texttt -- ourselves, escaped the same way pandoc does, with a break opportunity -- after each separator character. local BREAK_AFTER = { ["_"] = true, ["/"] = true, ["."] = true, ["-"] = true, [":"] = true, [","] = true, ["("] = true, ["="] = true } local ESCAPE = { ["\\"] = "\\textbackslash{}", ["{"] = "\\{", ["}"] = "\\}", ["$"] = "\\$", ["&"] = "\\&", ["#"] = "\\#", ["%"] = "\\%", ["_"] = "\\_", ["^"] = "\\textasciicircum{}", ["~"] = "\\textasciitilde{}", ["'"] = "\\textquotesingle{}", ["`"] = "\\textasciigrave{}", [" "] = "\\ ", } function Code(el) if not FORMAT:match("latex") then return nil end local out = {} for _, cp in utf8.codes(el.text) do local ch = utf8.char(cp) out[#out + 1] = ESCAPE[ch] or ch if BREAK_AFTER[ch] then out[#out + 1] = "\\allowbreak{}" end end return pandoc.RawInline("latex", "\\texttt{" .. table.concat(out) .. "}") end