git.iko.soy/typeable/pandoc
on master help sign in
LaTeX writer: create defaults for geometry using margin-left etc.
f9202f5John MacFarlane
src/Text/Pandoc/Writers/LaTeX.hs+10−1
@@ -41,7 +41,7 @@ import Network.URI ( isURI, unEscapeString )
41import Data.Aeson (object, (.=), FromJSON)
41import Data.Aeson (object, (.=), FromJSON)
42import Data.List ( (\\), isInfixOf, stripPrefix, intercalate, intersperse, nub, nubBy )
42import Data.List ( (\\), isInfixOf, stripPrefix, intercalate, intersperse, nub, nubBy )
43import Data.Char ( toLower, isPunctuation, isAscii, isLetter, isDigit, ord )
43import Data.Char ( toLower, isPunctuation, isAscii, isLetter, isDigit, ord )
44−import Data.Maybe ( fromMaybe, isJust )
44+import Data.Maybe ( fromMaybe, isJust, catMaybes )
45import qualified Data.Text as T
45import qualified Data.Text as T
46import Control.Applicative ((<|>))
46import Control.Applicative ((<|>))
47import Control.Monad.State
47import Control.Monad.State
@@ -153,6 +153,14 @@ pandocToLaTeX options (Pandoc meta blocks) = do
153 authorsMeta <- mapM (stringToLaTeX TextString . stringify) $ docAuthors meta
153 authorsMeta <- mapM (stringToLaTeX TextString . stringify) $ docAuthors meta
154 let docLangs = nub $ query (extract "lang") blocks
154 let docLangs = nub $ query (extract "lang") blocks
155 let hasStringValue x = isJust (getField x metadata :: Maybe String)
155 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+ ]
156 let context = defField "toc" (writerTableOfContents options) $
164 let context = defField "toc" (writerTableOfContents options) $
157 defField "toc-depth" (show (writerTOCDepth options -
165 defField "toc-depth" (show (writerTOCDepth options -
158 if stBook st
166 if stBook st
@@ -196,6 +204,7 @@ pandocToLaTeX options (Pandoc meta blocks) = do
196 then ""::String
204 then ""::String
197 else "ltr") $
205 else "ltr") $
198 defField "section-titles" True $
206 defField "section-titles" True $
207+ defField "geometry" geometryFromMargins $
199 metadata
208 metadata
200 let toPolyObj lang = object [ "name" .= T.pack name
209 let toPolyObj lang = object [ "name" .= T.pack name
201 , "options" .= T.pack opts ]
210 , "options" .= T.pack opts ]