Skip to content
Snippets Groups Projects
Commit ecdeca89 authored by Alice Brenon's avatar Alice Brenon
Browse files

Add support for LaTeX's \chaptermark in glossary and biblio filters

parent 35f3523d
No related branches found
No related tags found
No related merge requests found
function getNumber(field, default) function getField(field, default)
if field == nil then if field == nil then
return default return default
else else
return field[1].text return field[1].text
end end
end end
function Pandoc(doc) function Pandoc(doc)
level = getNumber(doc.meta['bibliography-level'], 1) level = getField(doc.meta['bibliography-level'], 1)
entry_spacing = getNumber(doc.meta['bibliography-spacing'], 0) entry_spacing = getField(doc.meta['bibliography-spacing'], 0)
section_title = getField(doc.meta['bibliography-title'], "Bibliography")
doc.blocks:extend({pandoc.Header( doc.blocks:extend({pandoc.Header(
level, level,
doc.meta['bibliography-title'] or "Bibliography", section_title,
{id = 'bibliography', class = 'unnumbered'} {id = 'bibliography', class = 'unnumbered'}
), pandoc.RawInline(
"latex", ("\\chaptermark{" .. section_title .. "}")
), pandoc.Div( ), pandoc.Div(
{}, {},
{id = 'refs', ['entry-spacing'] = entry_spacing} {id = 'refs', ['entry-spacing'] = entry_spacing}
)}) )})
return pandoc.utils.citeproc(doc) return pandoc.utils.citeproc(doc)
end end
...@@ -83,10 +83,11 @@ loadDef t _ = do ...@@ -83,10 +83,11 @@ loadDef t _ = do
addGlossarySection :: MonadReader Config m => ([Block], Glossary) -> m [Block] addGlossarySection :: MonadReader Config m => ([Block], Glossary) -> m [Block]
addGlossarySection (blocks, definitions) addGlossarySection (blocks, definitions)
| null definitions = pure $ blocks | null definitions = pure $ blocks
| otherwise = (blocks <>) <$> sequence [asks header, body] | otherwise = (blocks <>) <$> sequence [asks header, chaptermark, body]
where where
header (Config {level, title}) = header (Config {level, title}) =
Header level ("glossary", ["unnumbered"], []) [Str title] Header level ("glossary", ["unnumbered"], []) [Str title]
chaptermark = Plain . pure <$> (raw sectionTitle =<< asks title)
body = DefinitionList <$> (mapM entryOf $ Map.toList definitions) body = DefinitionList <$> (mapM entryOf $ Map.toList definitions)
entryOf (key, definition) = (,[definition]) <$> sequence [raw target key] entryOf (key, definition) = (,[definition]) <$> sequence [raw target key]
...@@ -108,3 +109,7 @@ target t Html = ["<span id=\"", labelFor t, "\">", t, "</span>"] ...@@ -108,3 +109,7 @@ target t Html = ["<span id=\"", labelFor t, "\">", t, "</span>"]
link :: Text -> KnownFormat -> [Text] link :: Text -> KnownFormat -> [Text]
link t Latex = ["\\hyperlink{", labelFor t, "}{", t, "}"] link t Latex = ["\\hyperlink{", labelFor t, "}{", t, "}"]
link t Html = ["<a href=\"#", labelFor t, "\">", t, "</a>"] link t Html = ["<a href=\"#", labelFor t, "\">", t, "</a>"]
sectionTitle :: Text -> KnownFormat -> [Text]
sectionTitle t Latex = ["\\chaptermark{", t, "}"]
sectionTitle _ Html = [] -- does not apply so not implemented
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment