@@ -188,6 +188,9 @@ pandocToLaTeX options (Pandoc meta blocks) = do
188188 $ defField "polyglossia-otherlangs"
189189 (maybe [] (map $ fst . toPolyglossia . splitBy (=='-')) $
190190 getField "otherlangs" context)
191+ $ defField "latex-dir-rtl" (case (getField "dir" context)::Maybe String of
192+ Just "rtl" -> True
193+ _ -> False)
191194 $ context
192195 return $ if writerStandalone options
193196 then renderTemplate' template context'
@@ -324,14 +327,19 @@ isLineBreakOrSpace _ = False
324327blockToLaTeX :: Block -- ^ Block to convert
325328 -> State WriterState Doc
326329blockToLaTeX Null = return empty
327−blockToLaTeX (Div (identifier,classes,_) bs) = do
330+blockToLaTeX (Div (identifier,classes,kvs) bs) = do
328331 beamer <- writerBeamer `fmap` gets stOptions
329332 ref <- toLabel identifier
330333 let linkAnchor = if null identifier
331334 then empty
332335 else "\\hyperdef{}" <> braces (text ref) <>
333336 braces ("\\label" <> braces (text ref))
334− contents <- blockListToLaTeX bs
337+ contents' <- blockListToLaTeX bs
338+ let align dir = inCmd "begin" dir $$ contents' $$ inCmd "end" dir
339+ let contents = case lookup "dir" kvs of
340+ Just "rtl" -> align "RTL"
341+ Just "ltr" -> align "LTR"
342+ _ -> contents'
335343 if beamer && "notes" `elem` classes -- speaker notes
336344 then return $ "\\note" <> braces contents
337345 else return (linkAnchor $$ contents)
@@ -728,10 +736,12 @@ isQuoted _ = False
728736-- | Convert inline element to LaTeX
729737inlineToLaTeX :: Inline -- ^ Inline to convert
730738 -> State WriterState Doc
731−inlineToLaTeX (Span (id',classes,_) ils) = do
739+inlineToLaTeX (Span (id',classes,kvs) ils) = do
732740 let noEmph = "csl-no-emph" `elem` classes
733741 let noStrong = "csl-no-strong" `elem` classes
734742 let noSmallCaps = "csl-no-smallcaps" `elem` classes
743+ let rtl = ("dir","rtl") `elem` kvs
744+ let ltr = ("dir","ltr") `elem` kvs
735745 ref <- toLabel id'
736746 let linkAnchor = if null id'
737747 then empty
@@ -741,7 +751,9 @@ inlineToLaTeX (Span (id',classes,_) ils) = do
741751 ((if noEmph then inCmd "textup" else id) .
742752 (if noStrong then inCmd "textnormal" else id) .
743753 (if noSmallCaps then inCmd "textnormal" else id) .
744− (if not (noEmph || noStrong || noSmallCaps)
754+ (if rtl then inCmd "RL" else id) .
755+ (if ltr then inCmd "LR" else id) .
756+ (if not (noEmph || noStrong || noSmallCaps || rtl || ltr)
745757 then braces
746758 else id)) `fmap` inlineListToLaTeX ils
747759inlineToLaTeX (Emph lst) =