-- Render content below header in three columns local multicol_begin = pandoc.RawBlock('latex', [[ \begin{multicols}{3}\raggedcolumns ]]) local multicol_end = pandoc.RawBlock('latex', [[ \end{multicols} ]]) -- TODO: detect pre-quarto-filter pattern too local function is_newpage_command(elem) return elem.t == "RawBlock" and elem.text == "\\newpage{}" end -- TODO: include header level 2 and author paragraph above multicolumn function is_author(elem) return elem.t == Para and elem.content[1].text == "Forfatter:" end function Pandoc(doc) if FORMAT:match 'latex' then -- locate topmost-only elements where multicol state should change local multicol_now = false local multicol_places = {} for i, elem in ipairs(doc.blocks) do if elem.t == "Header" and elem.level == 1 then multicol_places[i] = multicol_now and "renew" or "begin" multicol_now = true elseif is_newpage_command(elem) then if multicol_now then multicol_places[i] = "end" multicol_now = false end elseif elem.t == "HorizontalRule" then if multicol_now then multicol_places[i] = "end" multicol_now = false end end end if multicol_now then multicol_places[#doc.blocks] = "end" end -- apply multicol, in reverse order since it shifts later indices for i = #doc.blocks, 1, -1 do local state = multicol_places[i] if state ~= nil then if state == "begin" then doc.blocks:insert(i + 1, multicol_begin) elseif state == "renew" then doc.blocks:insert(i + 1, multicol_begin) doc.blocks:insert(i, multicol_end) elseif state == "end" then doc.blocks:insert(i, multicol_end) end end end if #multicol_places >= 1 then return doc end end end