From f9202f5d3918cb99e35ab3c74f09e1bf7f81368a Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 22 Dec 2015 13:10:46 -0800 Subject: 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. --- src/Text/Pandoc/Writers/LaTeX.hs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/Text/Pandoc') diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs index 31feecc7c..025915c37 100644 --- a/src/Text/Pandoc/Writers/LaTeX.hs +++ b/src/Text/Pandoc/Writers/LaTeX.hs @@ -41,7 +41,7 @@ import Network.URI ( isURI, unEscapeString ) import Data.Aeson (object, (.=), FromJSON) import Data.List ( (\\), isInfixOf, stripPrefix, intercalate, intersperse, nub, nubBy ) import Data.Char ( toLower, isPunctuation, isAscii, isLetter, isDigit, ord ) -import Data.Maybe ( fromMaybe, isJust ) +import Data.Maybe ( fromMaybe, isJust, catMaybes ) import qualified Data.Text as T import Control.Applicative ((<|>)) import Control.Monad.State @@ -153,6 +153,14 @@ pandocToLaTeX options (Pandoc meta blocks) = do authorsMeta <- mapM (stringToLaTeX TextString . stringify) $ docAuthors meta let docLangs = nub $ query (extract "lang") blocks let hasStringValue x = isJust (getField x metadata :: Maybe String) + let geometryFromMargins = intercalate [','] $ catMaybes $ + map (\(x,y) -> + ((x ++ "=") ++) <$> getField y metadata) + [("lmargin","margin-left") + ,("rmargin","margin-right") + ,("tmargin","margin-top") + ,("bmargin","margin-bottom") + ] let context = defField "toc" (writerTableOfContents options) $ defField "toc-depth" (show (writerTOCDepth options - if stBook st @@ -196,6 +204,7 @@ pandocToLaTeX options (Pandoc meta blocks) = do then ""::String else "ltr") $ defField "section-titles" True $ + defField "geometry" geometryFromMargins $ metadata let toPolyObj lang = object [ "name" .= T.pack name , "options" .= T.pack opts ] -- cgit v1.2.3