@@ -20,7 +20,7 @@ import Text.Pandoc.Readers.Org.Parsing
2020import Control.Monad (mzero, void)
2121import Data.Char (toLower)
2222import Data.Maybe (listToMaybe)
23−import Data.Text (Text)
23+import Data.Text (Text, unpack)
2424
2525-- | Read and handle space separated org-mode export settings.
2626exportSettings :: PandocMonad m => OrgParser m ()
@@ -59,7 +59,7 @@ exportSetting = choice
5959 , ignoredSetting "stat"
6060 , booleanSetting "tags" (\val es -> es { exportWithTags = val })
6161 , ignoredSetting "tasks"
62− , ignoredSetting "tex"
62+ , texSetting "tex" (\val es -> es { exportWithLatex = val })
6363 , ignoredSetting "timestamp"
6464 , ignoredSetting "title"
6565 , ignoredSetting "toc"
@@ -68,6 +68,8 @@ exportSetting = choice
6868 , ignoreAndWarn
6969 ] <?> "export setting"
7070
71+-- | Generic handler for export settings. Takes a parser which converts
72+-- the plain option text into a data structure.
7173genericExportSetting :: Monad m
7274 => OrgParser m a
7375 -> Text
@@ -101,10 +103,8 @@ archivedTreeSetting :: Monad m
101103archivedTreeSetting =
102104 genericExportSetting $ archivedTreesHeadlineSetting <|> archivedTreesBoolean
103105 where
104− archivedTreesHeadlineSetting = try $ do
105− _ <- string "headline"
106− lookAhead (newline <|> spaceChar)
107− return ArchivedTreesHeadlineOnly
106+ archivedTreesHeadlineSetting =
107+ ArchivedTreesHeadlineOnly <$ optionString "headline"
108108
109109 archivedTreesBoolean = try $ do
110110 exportBool <- elispBoolean
@@ -143,6 +143,22 @@ complementableListSetting = genericExportSetting $ choice
143143 char '"'
144144 *> manyTillChar alphaNum (char '"')
145145
146+-- | Parses either @t@, @nil@, or @verbatim@ into a 'TeXExport' value.
147+texSetting :: Monad m
148+ => Text
149+ -> ExportSettingSetter TeXExport
150+ -> OrgParser m ()
151+texSetting = genericExportSetting $ texVerbatim <|> texBoolean
152+ where
153+ texVerbatim = TeXVerbatim <$ optionString "verbatim"
154+
155+ texBoolean = try $ do
156+ exportBool <- elispBoolean
157+ return $
158+ if exportBool
159+ then TeXExport
160+ else TeXIgnore
161+
146162-- | Read but ignore the export setting.
147163ignoredSetting :: Monad m => Text -> OrgParser m ()
148164ignoredSetting s = try (() <$ textStr s <* char ':' <* many1 nonspaceChar)
@@ -164,3 +180,11 @@ elispBoolean = try $ do
164180 "{}" -> False
165181 "()" -> False
166182 _ -> True
183+
184+-- | Try to parse a literal string as the option value. Returns the
185+-- string on success.
186+optionString :: Monad m => Text -> OrgParser m Text
187+optionString s = try $ do
188+ _ <- string (unpack s)
189+ lookAhead (newline <|> spaceChar)
190+ return s