@@ -37,6 +37,7 @@ import Text.Pandoc.Walk (query)
3737import Text.Printf ( printf )
3838import Data.List ( intercalate, intersperse )
3939import Data.Char ( ord )
40+import Data.Maybe ( catMaybes )
4041import Control.Monad.State
4142import Text.Pandoc.Pretty
4243import Text.Pandoc.ImageSize
@@ -72,6 +73,14 @@ pandocToConTeXt options (Pandoc meta blocks) = do
7273 meta
7374 body <- mapM (elementToConTeXt options) $ hierarchicalize blocks
7475 let main = (render colwidth . vcat) body
76+ let layoutFromMargins = intercalate [','] $ catMaybes $
77+ map (\(x,y) ->
78+ ((x ++ "=") ++) <$> getField y metadata)
79+ [("leftmargin","margin-left")
80+ ,("rightmargin","margin-right")
81+ ,("top","margin-top")
82+ ,("bottom","margin-bottom")
83+ ]
7584 let context = defField "toc" (writerTableOfContents options)
7685 $ defField "placelist" (intercalate ("," :: String) $
7786 take (writerTOCDepth options + if writerChapters options
@@ -80,6 +89,7 @@ pandocToConTeXt options (Pandoc meta blocks) = do
8089 ["chapter","section","subsection","subsubsection",
8190 "subsubsubsection","subsubsubsubsection"])
8291 $ defField "body" main
92+ $ defField "layout" layoutFromMargins
8393 $ defField "number-sections" (writerNumberSections options)
8494 $ metadata
8595 let context' = defField "context-lang" (maybe "" (fromBcp47 . splitBy (=='-')) $