diff options
author | John MacFarlane <jgm@berkeley.edu> | 2015-12-22 13:10:46 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2015-12-22 13:10:46 -0800 |
commit | f9202f5d3918cb99e35ab3c74f09e1bf7f81368a (patch) | |
tree | d7f929f5e3a1eaad967b8c0e209051219e763b66 /src/Text/Pandoc | |
parent | 35e05449777255b624f0e8cb374e1fcdca86ba78 (diff) | |
download | pandoc-f9202f5d3918cb99e35ab3c74f09e1bf7f81368a.tar.gz |
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.hs | 11 |
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 ] |