summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2015-12-22 13:10:46 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2015-12-22 13:10:46 -0800
commitf9202f5d3918cb99e35ab3c74f09e1bf7f81368a (patch)
treed7f929f5e3a1eaad967b8c0e209051219e763b66 /src/Text/Pandoc
parent35e05449777255b624f0e8cb374e1fcdca86ba78 (diff)
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.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Writers/LaTeX.hs11
1 files changed, 10 insertions, 1 deletions
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 ]