Change variable to polyglossia-lang.name and .options

closes #2437
This commit is contained in:
mb21 2015-10-07 22:40:51 +02:00
parent 6d3ad456a0
commit 80b851a4cf
2 changed files with 37 additions and 22 deletions

3
README
View file

@ -944,8 +944,7 @@ Language variables
using a code according to [BCP 47] (e.g. `en` or `en-GB`). using a code according to [BCP 47] (e.g. `en` or `en-GB`).
For some output formats, pandoc will convert it to an appropriate For some output formats, pandoc will convert it to an appropriate
format stored in the additional variables `babel-lang`, format stored in the additional variables `babel-lang`,
`polyglossia-lang`, `polyglossia-variant` (LaTeX) `polyglossia-lang` (LaTeX) and `context-lang` (ConTeXt).
and `context-lang` (ConTeXt).
`otherlangs` `otherlangs`
: a list of other languages used in the document : a list of other languages used in the document

View file

@ -38,9 +38,11 @@ import Text.Pandoc.Options
import Text.Pandoc.Templates import Text.Pandoc.Templates
import Text.Printf ( printf ) import Text.Printf ( printf )
import Network.URI ( isURI, unEscapeString ) import Network.URI ( isURI, unEscapeString )
import Data.Aeson (object, (.=))
import Data.List ( (\\), isInfixOf, stripPrefix, intercalate, intersperse ) import Data.List ( (\\), isInfixOf, stripPrefix, intercalate, intersperse )
import Data.Char ( toLower, isPunctuation, isAscii, isLetter, isDigit, ord ) import Data.Char ( toLower, isPunctuation, isAscii, isLetter, isDigit, ord )
import Data.Maybe ( fromMaybe ) import Data.Maybe ( fromMaybe )
import qualified Data.Text as T
import Control.Applicative ((<|>)) import Control.Applicative ((<|>))
import Control.Monad.State import Control.Monad.State
import qualified Text.Parsec as P import qualified Text.Parsec as P
@ -178,14 +180,16 @@ pandocToLaTeX options (Pandoc meta blocks) = do
defField "biblatex" True defField "biblatex" True
_ -> id) $ _ -> id) $
metadata metadata
let toPolyObj lang = object [ "name" .= T.pack name
, "options" .= T.pack opts ]
where
(name, opts) = toPolyglossia lang
let lang = maybe [] (splitBy (=='-')) $ getField "lang" context let lang = maybe [] (splitBy (=='-')) $ getField "lang" context
(polyLang, polyVar) = toPolyglossia lang
let context' = let context' =
defField "babel-lang" (toBabel lang) defField "babel-lang" (toBabel lang)
$ defField "polyglossia-lang" polyLang $ defField "polyglossia-lang" (toPolyObj lang)
$ defField "polyglossia-variant" polyVar
$ defField "polyglossia-otherlangs" $ defField "polyglossia-otherlangs"
(maybe [] (map $ fst . toPolyglossia . splitBy (=='-')) $ (maybe [] (map $ toPolyObj . splitBy (=='-')) $
getField "otherlangs" context) getField "otherlangs" context)
$ defField "latex-dir-rtl" (case (getField "dir" context)::Maybe String of $ defField "latex-dir-rtl" (case (getField "dir" context)::Maybe String of
Just "rtl" -> True Just "rtl" -> True
@ -996,24 +1000,36 @@ getListingsLanguage [] = Nothing
getListingsLanguage (x:xs) = toListingsLanguage x <|> getListingsLanguage xs getListingsLanguage (x:xs) = toListingsLanguage x <|> getListingsLanguage xs
-- Takes a list of the constituents of a BCP 47 language code and -- Takes a list of the constituents of a BCP 47 language code and
-- converts it to a Polyglossia (language, variant) tuple -- converts it to a Polyglossia (language, options) tuple
-- http://mirrors.concertpass.com/tex-archive/macros/latex/contrib/polyglossia/polyglossia.pdf -- http://mirrors.concertpass.com/tex-archive/macros/latex/contrib/polyglossia/polyglossia.pdf
toPolyglossia :: [String] -> (String, String) toPolyglossia :: [String] -> (String, String)
toPolyglossia ("de":"AT":_) = ("german", "austrian") toPolyglossia ("ar":"DZ":_) = ("arabic", "locale=algeria")
toPolyglossia ("de":"CH":_) = ("german", "swiss") toPolyglossia ("ar":"IQ":_) = ("arabic", "locale=mashriq")
toPolyglossia ("de":_) = ("german", "") toPolyglossia ("ar":"JO":_) = ("arabic", "locale=mashriq")
toPolyglossia ("dsb":_) = ("lsorbian", "") toPolyglossia ("ar":"LB":_) = ("arabic", "locale=mashriq")
toPolyglossia ("el":"poly":_) = ("greek", "poly") toPolyglossia ("ar":"LY":_) = ("arabic", "locale=libya")
toPolyglossia ("en":"AU":_) = ("english", "australian") toPolyglossia ("ar":"MA":_) = ("arabic", "locale=morocco")
toPolyglossia ("en":"CA":_) = ("english", "canadian") toPolyglossia ("ar":"MR":_) = ("arabic", "locale=mauritania")
toPolyglossia ("en":"GB":_) = ("english", "british") toPolyglossia ("ar":"PS":_) = ("arabic", "locale=mashriq")
toPolyglossia ("en":"NZ":_) = ("english", "newzealand") toPolyglossia ("ar":"SY":_) = ("arabic", "locale=mashriq")
toPolyglossia ("en":"UK":_) = ("english", "british") toPolyglossia ("ar":"TN":_) = ("arabic", "locale=tunisia")
toPolyglossia ("en":"US":_) = ("english", "american") toPolyglossia ("de":"1901":_) = ("german", "spelling=old")
toPolyglossia ("grc":_) = ("greek", "ancient") toPolyglossia ("de":"AT":"1901":_) = ("german", "variant=austrian, spelling=old")
toPolyglossia ("hsb":_) = ("usorbian", "") toPolyglossia ("de":"AT":_) = ("german", "variant=austrian")
toPolyglossia ("sl":_) = ("slovenian", "") toPolyglossia ("de":"CH":_) = ("german", "variant=swiss")
toPolyglossia x = (commonFromBcp47 x, "") toPolyglossia ("de":_) = ("german", "")
toPolyglossia ("dsb":_) = ("lsorbian", "")
toPolyglossia ("el":"poly":_) = ("greek", "variant=poly")
toPolyglossia ("en":"AU":_) = ("english", "variant=australian")
toPolyglossia ("en":"CA":_) = ("english", "variant=canadian")
toPolyglossia ("en":"GB":_) = ("english", "variant=british")
toPolyglossia ("en":"NZ":_) = ("english", "variant=newzealand")
toPolyglossia ("en":"UK":_) = ("english", "variant=british")
toPolyglossia ("en":"US":_) = ("english", "variant=american")
toPolyglossia ("grc":_) = ("greek", "variant=ancient")
toPolyglossia ("hsb":_) = ("usorbian", "")
toPolyglossia ("sl":_) = ("slovenian", "")
toPolyglossia x = (commonFromBcp47 x, "")
-- Takes a list of the constituents of a BCP 47 language code and -- Takes a list of the constituents of a BCP 47 language code and
-- converts it to a Babel language string. -- converts it to a Babel language string.