git.iko.soy/typeable/pandoc
on master help sign in
LaTeX writer: create defaults for geometry using margin-left etc.

If `geometry` has no value, but `margin-left`, `margin-right`, `margin-top`, and/or `-margin-bottom` are given, a default value for `geometry` is created from these. Note that these variables already affect PDF production via HTML5 with wkhtmltopdf.

commitf9202f5d3918cb99e35ab3c74f09e1bf7f81368a authorJohn MacFarlane <jgm@berkeley.edu> dateTue 22 Dec 2015, 13:10 (11 years ago) parent35e0544
1 file changed+10−1
src/Text/Pandoc/Writers/LaTeX.hs+10−1
src/Text/Pandoc/Writers/LaTeX.hs+10−1
@@ -41,7 +41,7 @@ import Network.URI ( isURI, unEscapeString )
4141import Data.Aeson (object, (.=), FromJSON)
4242import Data.List ( (\\), isInfixOf, stripPrefix, intercalate, intersperse, nub, nubBy )
4343import Data.Char ( toLower, isPunctuation, isAscii, isLetter, isDigit, ord )
44−import Data.Maybe ( fromMaybe, isJust )
44+import Data.Maybe ( fromMaybe, isJust, catMaybes )
4545import qualified Data.Text as T
4646import Control.Applicative ((<|>))
4747import Control.Monad.State
@@ -153,6 +153,14 @@ pandocToLaTeX options (Pandoc meta blocks) = do
153153 authorsMeta <- mapM (stringToLaTeX TextString . stringify) $ docAuthors meta
154154 let docLangs = nub $ query (extract "lang") blocks
155155 let hasStringValue x = isJust (getField x metadata :: Maybe String)
156+ let geometryFromMargins = intercalate [','] $ catMaybes $
157+ map (\(x,y) ->
158+ ((x ++ "=") ++) <$> getField y metadata)
159+ [("lmargin","margin-left")
160+ ,("rmargin","margin-right")
161+ ,("tmargin","margin-top")
162+ ,("bmargin","margin-bottom")
163+ ]
156164 let context = defField "toc" (writerTableOfContents options) $
157165 defField "toc-depth" (show (writerTOCDepth options -
158166 if stBook st
@@ -196,6 +204,7 @@ pandocToLaTeX options (Pandoc meta blocks) = do
196204 then ""::String
197205 else "ltr") $
198206 defField "section-titles" True $
207+ defField "geometry" geometryFromMargins $
199208 metadata
200209 let toPolyObj lang = object [ "name" .= T.pack name
201210 , "options" .= T.pack opts ]