{-# LANGUAGE CPP                   #-}
{-# LANGUAGE FlexibleInstances     #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings     #-}
{-# LANGUAGE PatternGuards         #-}
{-# LANGUAGE ScopedTypeVariables   #-}
{-# LANGUAGE ViewPatterns          #-}
{- |
   Module      : Text.Pandoc.Readers.LaTeX
   Copyright   : Copyright (C) 2006-2020 John MacFarlane
   License     : GNU GPL, version 2 or above

   Maintainer  : John MacFarlane <jgm@berkeley.edu>
   Stability   : alpha
   Portability : portable

Conversion of LaTeX to 'Pandoc' document.

-}
module Text.Pandoc.Readers.LaTeX ( readLaTeX,
                                   applyMacros,
                                   rawLaTeXInline,
                                   rawLaTeXBlock,
                                   inlineCommand,
                                   tokenize,
                                   untokenize
                                 ) where

import Control.Applicative (many, optional, (<|>))
import Control.Monad
import Control.Monad.Except (throwError)
import Data.Char (isDigit, isLetter, toUpper, chr)
import Data.Default
import Data.List (intercalate)
import qualified Data.Map as M
import Data.Maybe (fromMaybe, maybeToList)
import qualified Data.Set as Set
import Data.Text (Text)
import qualified Data.Text as T
import System.FilePath (addExtension, replaceExtension, takeExtension)
import Text.Pandoc.BCP47 (Lang (..), renderLang)
import Text.Pandoc.Builder
import Text.Pandoc.Class.PandocPure (PandocPure)
import Text.Pandoc.Class.PandocMonad (PandocMonad (..), getResourcePath,
                                      readFileFromDirs, report, setResourcePath,
                                      setTranslations, translateTerm)
import Text.Pandoc.Error (PandocError (PandocParseError, PandocParsecError))
import Text.Pandoc.Highlighting (fromListingsLanguage, languagesByExtension)
import Text.Pandoc.ImageSize (numUnit, showFl)
import Text.Pandoc.Logging
import Text.Pandoc.Options
import Text.Pandoc.Parsing hiding (blankline, many, mathDisplay, mathInline,
                            optional, space, spaces, withRaw, (<|>))
import Text.Pandoc.Readers.LaTeX.Types (ExpansionPoint (..), Macro (..),
                                        ArgSpec (..), Tok (..), TokType (..))
import Text.Pandoc.Readers.LaTeX.Parsing
import Text.Pandoc.Readers.LaTeX.Lang (polyglossiaLangToBCP47,
                                       babelLangToBCP47)
import Text.Pandoc.Shared
import qualified Text.Pandoc.Translations as Translations
import Text.Pandoc.Walk
import qualified Text.Pandoc.Builder as B
import qualified Data.Text.Normalize as Normalize
import Safe

-- for debugging:
-- import Text.Pandoc.Extensions (getDefaultExtensions)
-- import Text.Pandoc.Class.PandocIO (runIOorExplode, PandocIO)
-- import Debug.Trace (traceShowId)

-- | Parse LaTeX from string and return 'Pandoc' document.
readLaTeX :: PandocMonad m
          => ReaderOptions -- ^ Reader options
          -> Text        -- ^ String to parse (assumes @'\n'@ line endings)
          -> m Pandoc
readLaTeX :: ReaderOptions -> Text -> m Pandoc
readLaTeX opts :: ReaderOptions
opts ltx :: Text
ltx = do
  Either ParseError Pandoc
parsed <- ParsecT [Tok] LaTeXState m Pandoc
-> LaTeXState
-> SourceName
-> [Tok]
-> m (Either ParseError Pandoc)
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> u -> SourceName -> s -> m (Either ParseError a)
runParserT ParsecT [Tok] LaTeXState m Pandoc
forall (m :: * -> *). PandocMonad m => LP m Pandoc
parseLaTeX LaTeXState
forall a. Default a => a
def{ sOptions :: ReaderOptions
sOptions = ReaderOptions
opts } "source"
               (SourceName -> Text -> [Tok]
tokenize "source" (Text -> Text
crFilter Text
ltx))
  case Either ParseError Pandoc
parsed of
    Right result :: Pandoc
result -> Pandoc -> m Pandoc
forall (m :: * -> *) a. Monad m => a -> m a
return Pandoc
result
    Left e :: ParseError
e       -> PandocError -> m Pandoc
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (PandocError -> m Pandoc) -> PandocError -> m Pandoc
forall a b. (a -> b) -> a -> b
$ Text -> ParseError -> PandocError
PandocParsecError Text
ltx ParseError
e

parseLaTeX :: PandocMonad m => LP m Pandoc
parseLaTeX :: LP m Pandoc
parseLaTeX = do
  Blocks
bs <- LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks
  ParsecT [Tok] LaTeXState m ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof
  LaTeXState
st <- ParsecT [Tok] LaTeXState m LaTeXState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  let meta :: Meta
meta = LaTeXState -> Meta
sMeta LaTeXState
st
  let doc' :: Pandoc
doc' = Blocks -> Pandoc
doc Blocks
bs
  let headerLevel :: Block -> [Int]
headerLevel (Header n :: Int
n _ _) = [Int
n]
      headerLevel _              = []
#if MIN_VERSION_safe(0,3,18)
  let bottomLevel :: Int
bottomLevel = Int -> [Int] -> Int
forall a. Ord a => a -> [a] -> a
minimumBound 1 ([Int] -> Int) -> [Int] -> Int
forall a b. (a -> b) -> a -> b
$ (Block -> [Int]) -> Pandoc -> [Int]
forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query Block -> [Int]
headerLevel Pandoc
doc'
#else
  let bottomLevel = minimumDef 1 $ query headerLevel doc'
#endif
  let adjustHeaders :: Int -> Block -> Block
adjustHeaders m :: Int
m (Header n :: Int
n attr :: Attr
attr ils :: [Inline]
ils) = Int -> Attr -> [Inline] -> Block
Header (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
m) Attr
attr [Inline]
ils
      adjustHeaders _ x :: Block
x                   = Block
x
  let (Pandoc _ bs' :: [Block]
bs') =
       -- handle the case where you have \part or \chapter
       (if Int
bottomLevel Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< 1
           then (Block -> Block) -> Pandoc -> Pandoc
forall a b. Walkable a b => (a -> a) -> b -> b
walk (Int -> Block -> Block
adjustHeaders (1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
bottomLevel))
           else Pandoc -> Pandoc
forall a. a -> a
id) (Pandoc -> Pandoc) -> Pandoc -> Pandoc
forall a b. (a -> b) -> a -> b
$
       (Inline -> Inline) -> Pandoc -> Pandoc
forall a b. Walkable a b => (a -> a) -> b -> b
walk (Map Text [Inline] -> Inline -> Inline
resolveRefs (LaTeXState -> Map Text [Inline]
sLabels LaTeXState
st)) Pandoc
doc'
  Pandoc -> LP m Pandoc
forall (m :: * -> *) a. Monad m => a -> m a
return (Pandoc -> LP m Pandoc) -> Pandoc -> LP m Pandoc
forall a b. (a -> b) -> a -> b
$ Meta -> [Block] -> Pandoc
Pandoc Meta
meta [Block]
bs'

resolveRefs :: M.Map Text [Inline] -> Inline -> Inline
resolveRefs :: Map Text [Inline] -> Inline -> Inline
resolveRefs labels :: Map Text [Inline]
labels x :: Inline
x@(Link (ident :: Text
ident,classes :: [Text]
classes,kvs :: [(Text, Text)]
kvs) _ _) =
  case (Text -> [(Text, Text)] -> Maybe Text
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup "reference-type" [(Text, Text)]
kvs,
        Text -> [(Text, Text)] -> Maybe Text
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup "reference" [(Text, Text)]
kvs) of
        (Just "ref", Just lab :: Text
lab) ->
          case Text -> Map Text [Inline] -> Maybe [Inline]
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Text
lab Map Text [Inline]
labels of
               Just txt :: [Inline]
txt -> Attr -> [Inline] -> (Text, Text) -> Inline
Link (Text
ident,[Text]
classes,[(Text, Text)]
kvs) [Inline]
txt ("#" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
lab, "")
               Nothing  -> Inline
x
        _ -> Inline
x
resolveRefs _ x :: Inline
x = Inline
x


-- testParser :: LP PandocIO a -> Text -> IO a
-- testParser p t = do
--   res <- runIOorExplode (runParserT p defaultLaTeXState{
--             sOptions = def{ readerExtensions =
--               enableExtension Ext_raw_tex $
--                 getDefaultExtensions "latex" }} "source" (tokenize "source" t))
--   case res of
--        Left e  -> error (show e)
--        Right r -> return r


rawLaTeXBlock :: (PandocMonad m, HasMacros s, HasReaderOptions s)
              => ParserT Text s m Text
rawLaTeXBlock :: ParserT Text s m Text
rawLaTeXBlock = do
  ParsecT Text s m Char -> ParsecT Text s m Char
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (ParsecT Text s m Char -> ParsecT Text s m Char
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (Char -> ParsecT Text s m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '\\' ParsecT Text s m Char
-> ParsecT Text s m Char -> ParsecT Text s m Char
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Text s m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
letter))
  Text
inp <- ParserT Text s m Text
forall (m :: * -> *) s u. Monad m => ParsecT s u m s
getInput
  let toks :: [Tok]
toks = SourceName -> Text -> [Tok]
tokenize "source" Text
inp
  (Blocks, Text) -> Text
forall a b. (a, b) -> b
snd ((Blocks, Text) -> Text)
-> ParsecT Text s m (Blocks, Text) -> ParserT Text s m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ([Tok]
-> Bool
-> LP m Blocks
-> LP m Blocks
-> ParsecT Text s m (Blocks, Text)
forall (m :: * -> *) s a.
(PandocMonad m, HasMacros s, HasReaderOptions s) =>
[Tok] -> Bool -> LP m a -> LP m a -> ParserT Text s m (a, Text)
rawLaTeXParser [Tok]
toks Bool
False ((Text -> Blocks) -> LP m Blocks
forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
(Text -> a) -> LP m a
macroDef (Blocks -> Text -> Blocks
forall a b. a -> b -> a
const Blocks
forall a. Monoid a => a
mempty)) LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks
      ParsecT Text s m (Blocks, Text)
-> ParsecT Text s m (Blocks, Text)
-> ParsecT Text s m (Blocks, Text)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ([Tok]
-> Bool
-> LP m Blocks
-> LP m Blocks
-> ParsecT Text s m (Blocks, Text)
forall (m :: * -> *) s a.
(PandocMonad m, HasMacros s, HasReaderOptions s) =>
[Tok] -> Bool -> LP m a -> LP m a -> ParserT Text s m (a, Text)
rawLaTeXParser [Tok]
toks Bool
True
             (do [ParsecT [Tok] LaTeXState m Tok] -> ParsecT [Tok] LaTeXState m Tok
forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice ((Text -> ParsecT [Tok] LaTeXState m Tok)
-> [Text] -> [ParsecT [Tok] LaTeXState m Tok]
forall a b. (a -> b) -> [a] -> [b]
map Text -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq
                   ["include", "input", "subfile", "usepackage"])
                 ParsecT [Tok] LaTeXState m Inlines -> ParsecT [Tok] LaTeXState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ParsecT [Tok] LaTeXState m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
opt
                 LP m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
                 Blocks -> LP m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
forall a. Monoid a => a
mempty) LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks)
      ParsecT Text s m (Blocks, Text)
-> ParsecT Text s m (Blocks, Text)
-> ParsecT Text s m (Blocks, Text)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Tok]
-> Bool
-> LP m Blocks
-> LP m Blocks
-> ParsecT Text s m (Blocks, Text)
forall (m :: * -> *) s a.
(PandocMonad m, HasMacros s, HasReaderOptions s) =>
[Tok] -> Bool -> LP m a -> LP m a -> ParserT Text s m (a, Text)
rawLaTeXParser [Tok]
toks Bool
True
           (LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
environment LP m Blocks -> LP m Blocks -> LP m Blocks
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
blockCommand)
           ([Blocks] -> Blocks
forall a. Monoid a => [a] -> a
mconcat ([Blocks] -> Blocks)
-> ParsecT [Tok] LaTeXState m [Blocks] -> LP m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (LP m Blocks -> ParsecT [Tok] LaTeXState m [Blocks]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
block LP m Blocks -> LP m Blocks -> LP m Blocks
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
beginOrEndCommand))))

-- See #4667 for motivation; sometimes people write macros
-- that just evaluate to a begin or end command, which blockCommand
-- won't accept.
beginOrEndCommand :: PandocMonad m => LP m Blocks
beginOrEndCommand :: LP m Blocks
beginOrEndCommand = LP m Blocks -> LP m Blocks
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (LP m Blocks -> LP m Blocks) -> LP m Blocks -> LP m Blocks
forall a b. (a -> b) -> a -> b
$ do
  Tok _ (CtrlSeq name :: Text
name) txt :: Text
txt <- LP m Tok
forall (m :: * -> *). PandocMonad m => LP m Tok
anyControlSeq
  Bool -> ParsecT [Tok] LaTeXState m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT [Tok] LaTeXState m ())
-> Bool -> ParsecT [Tok] LaTeXState m ()
forall a b. (a -> b) -> a -> b
$ Text
name Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== "begin" Bool -> Bool -> Bool
|| Text
name Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== "end"
  (envname :: [Tok]
envname, rawargs :: [Tok]
rawargs) <- LP m [Tok] -> LP m ([Tok], [Tok])
forall (m :: * -> *) a. PandocMonad m => LP m a -> LP m (a, [Tok])
withRaw LP m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
  if Text -> Map Text (LP PandocPure Inlines) -> Bool
forall k a. Ord k => k -> Map k a -> Bool
M.member ([Tok] -> Text
untokenize [Tok]
envname)
      (Map Text (LP PandocPure Inlines)
forall (m :: * -> *). PandocMonad m => Map Text (LP m Inlines)
inlineEnvironments :: M.Map Text (LP PandocPure Inlines))
     then LP m Blocks
forall (m :: * -> *) a. MonadPlus m => m a
mzero
     else Blocks -> LP m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return (Blocks -> LP m Blocks) -> Blocks -> LP m Blocks
forall a b. (a -> b) -> a -> b
$ Text -> Text -> Blocks
rawBlock "latex"
                    (Text
txt Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> [Tok] -> Text
untokenize [Tok]
rawargs)

rawLaTeXInline :: (PandocMonad m, HasMacros s, HasReaderOptions s)
               => ParserT Text s m Text
rawLaTeXInline :: ParserT Text s m Text
rawLaTeXInline = do
  ParsecT Text s m Char -> ParsecT Text s m Char
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (ParsecT Text s m Char -> ParsecT Text s m Char
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (Char -> ParsecT Text s m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '\\' ParsecT Text s m Char
-> ParsecT Text s m Char -> ParsecT Text s m Char
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Text s m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
letter))
  Text
inp <- ParserT Text s m Text
forall (m :: * -> *) s u. Monad m => ParsecT s u m s
getInput
  let toks :: [Tok]
toks = SourceName -> Text -> [Tok]
tokenize "source" Text
inp
  Text
raw <- (Inlines, Text) -> Text
forall a b. (a, b) -> b
snd ((Inlines, Text) -> Text)
-> ParsecT Text s m (Inlines, Text) -> ParserT Text s m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
          (   [Tok]
-> Bool
-> LP m Inlines
-> LP m Inlines
-> ParsecT Text s m (Inlines, Text)
forall (m :: * -> *) s a.
(PandocMonad m, HasMacros s, HasReaderOptions s) =>
[Tok] -> Bool -> LP m a -> LP m a -> ParserT Text s m (a, Text)
rawLaTeXParser [Tok]
toks Bool
True
              (Inlines
forall a. Monoid a => a
mempty Inlines -> ParsecT [Tok] LaTeXState m [Tok] -> LP m Inlines
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (Text -> LP m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "input" LP m Tok
-> ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> LP m Inlines -> ParsecT [Tok] LaTeXState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
opt ParsecT [Tok] LaTeXState m ()
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced))
              LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
inlines
          ParsecT Text s m (Inlines, Text)
-> ParsecT Text s m (Inlines, Text)
-> ParsecT Text s m (Inlines, Text)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [Tok]
-> Bool
-> LP m Inlines
-> LP m Inlines
-> ParsecT Text s m (Inlines, Text)
forall (m :: * -> *) s a.
(PandocMonad m, HasMacros s, HasReaderOptions s) =>
[Tok] -> Bool -> LP m a -> LP m a -> ParserT Text s m (a, Text)
rawLaTeXParser [Tok]
toks Bool
True (LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
inlineEnvironment LP m Inlines -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
inlineCommand')
              LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
inlines
          )
  SourceName
finalbraces <- [SourceName] -> SourceName
forall a. Monoid a => [a] -> a
mconcat ([SourceName] -> SourceName)
-> ParsecT Text s m [SourceName] -> ParsecT Text s m SourceName
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text s m SourceName -> ParsecT Text s m [SourceName]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (ParsecT Text s m SourceName -> ParsecT Text s m SourceName
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (SourceName -> ParsecT Text s m SourceName
forall s (m :: * -> *) u.
Stream s m Char =>
SourceName -> ParsecT s u m SourceName
string "{}")) -- see #5439
  Text -> ParserT Text s m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> ParserT Text s m Text) -> Text -> ParserT Text s m Text
forall a b. (a -> b) -> a -> b
$ Text
raw Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> SourceName -> Text
T.pack SourceName
finalbraces

inlineCommand :: PandocMonad m => ParserT Text ParserState m Inlines
inlineCommand :: ParserT Text ParserState m Inlines
inlineCommand = do
  ParsecT Text ParserState m Char -> ParsecT Text ParserState m Char
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (ParsecT Text ParserState m Char -> ParsecT Text ParserState m Char
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (Char -> ParsecT Text ParserState m Char
forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
char '\\' ParsecT Text ParserState m Char
-> ParsecT Text ParserState m Char
-> ParsecT Text ParserState m Char
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT Text ParserState m Char
forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char
letter))
  Text
inp <- ParsecT Text ParserState m Text
forall (m :: * -> *) s u. Monad m => ParsecT s u m s
getInput
  let toks :: [Tok]
toks = SourceName -> Text -> [Tok]
tokenize "source" Text
inp
  (Inlines, Text) -> Inlines
forall a b. (a, b) -> a
fst ((Inlines, Text) -> Inlines)
-> ParsecT Text ParserState m (Inlines, Text)
-> ParserT Text ParserState m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Tok]
-> Bool
-> LP m Inlines
-> LP m Inlines
-> ParsecT Text ParserState m (Inlines, Text)
forall (m :: * -> *) s a.
(PandocMonad m, HasMacros s, HasReaderOptions s) =>
[Tok] -> Bool -> LP m a -> LP m a -> ParserT Text s m (a, Text)
rawLaTeXParser [Tok]
toks Bool
True (LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
inlineEnvironment LP m Inlines -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
inlineCommand')
          LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
inlines

-- inline elements:

word :: PandocMonad m => LP m Inlines
word :: LP m Inlines
word = (Text -> Inlines
str (Text -> Inlines) -> (Tok -> Text) -> Tok -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tok -> Text
untoken) (Tok -> Inlines) -> ParsecT [Tok] LaTeXState m Tok -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Tok -> Bool) -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => (Tok -> Bool) -> LP m Tok
satisfyTok Tok -> Bool
isWordTok

regularSymbol :: PandocMonad m => LP m Inlines
regularSymbol :: LP m Inlines
regularSymbol = (Text -> Inlines
str (Text -> Inlines) -> (Tok -> Text) -> Tok -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tok -> Text
untoken) (Tok -> Inlines) -> ParsecT [Tok] LaTeXState m Tok -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Tok -> Bool) -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => (Tok -> Bool) -> LP m Tok
satisfyTok Tok -> Bool
isRegularSymbol
  where isRegularSymbol :: Tok -> Bool
isRegularSymbol (Tok _ Symbol t :: Text
t) = Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ (Char -> Bool) -> Text -> Bool
T.any Char -> Bool
isSpecial Text
t
        isRegularSymbol _                = Bool
False
        isSpecial :: Char -> Bool
isSpecial c :: Char
c = Char
c Char -> Set Char -> Bool
forall a. Ord a => a -> Set a -> Bool
`Set.member` Set Char
specialChars

inlineGroup :: PandocMonad m => LP m Inlines
inlineGroup :: LP m Inlines
inlineGroup = do
  Inlines
ils <- LP m Inlines -> LP m Inlines
forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
grouped LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
inline
  if Inlines -> Bool
forall a. Many a -> Bool
isNull Inlines
ils
     then Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
forall a. Monoid a => a
mempty
     else Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> LP m Inlines) -> Inlines -> LP m Inlines
forall a b. (a -> b) -> a -> b
$ Attr -> Inlines -> Inlines
spanWith Attr
nullAttr Inlines
ils
          -- we need the span so we can detitlecase bibtex entries;
          -- we need to know when something is {C}apitalized

doLHSverb :: PandocMonad m => LP m Inlines
doLHSverb :: LP m Inlines
doLHSverb =
  (Attr -> Text -> Inlines
codeWith ("",["haskell"],[]) (Text -> Inlines) -> ([Tok] -> Text) -> [Tok] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize)
    ([Tok] -> Inlines)
-> ParsecT [Tok] LaTeXState m [Tok] -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m Tok
-> ParsecT [Tok] LaTeXState m Tok
-> ParsecT [Tok] LaTeXState m [Tok]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ((Tok -> Bool) -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => (Tok -> Bool) -> LP m Tok
satisfyTok (Bool -> Bool
not (Bool -> Bool) -> (Tok -> Bool) -> Tok -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tok -> Bool
isNewlineTok)) (Char -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '|')

mkImage :: PandocMonad m => [(Text, Text)] -> Text -> LP m Inlines
mkImage :: [(Text, Text)] -> Text -> LP m Inlines
mkImage options :: [(Text, Text)]
options (Text -> SourceName
T.unpack -> SourceName
src) = do
   let replaceTextwidth :: (a, Text) -> (a, Text)
replaceTextwidth (k :: a
k,v :: Text
v) =
         case Text -> Maybe (Double, Text)
numUnit Text
v of
              Just (num :: Double
num, "\\textwidth") -> (a
k, Double -> Text
forall a. RealFloat a => a -> Text
showFl (Double
num Double -> Double -> Double
forall a. Num a => a -> a -> a
* 100) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> "%")
              _                         -> (a
k, Text
v)
   let kvs :: [(Text, Text)]
kvs = ((Text, Text) -> (Text, Text)) -> [(Text, Text)] -> [(Text, Text)]
forall a b. (a -> b) -> [a] -> [b]
map (Text, Text) -> (Text, Text)
forall a. (a, Text) -> (a, Text)
replaceTextwidth
             ([(Text, Text)] -> [(Text, Text)])
-> [(Text, Text)] -> [(Text, Text)]
forall a b. (a -> b) -> a -> b
$ ((Text, Text) -> Bool) -> [(Text, Text)] -> [(Text, Text)]
forall a. (a -> Bool) -> [a] -> [a]
filter (\(k :: Text
k,_) -> Text
k Text -> [Text] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` ["width", "height"]) [(Text, Text)]
options
   let attr :: (Text, [a], [(Text, Text)])
attr = ("",[], [(Text, Text)]
kvs)
   let alt :: Inlines
alt = Text -> Inlines
str "image"
   Text
defaultExt <- (ReaderOptions -> Text) -> ParserT [Tok] LaTeXState m Text
forall st s (m :: * -> *) t b.
(HasReaderOptions st, Stream s m t) =>
(ReaderOptions -> b) -> ParserT s st m b
getOption ReaderOptions -> Text
readerDefaultImageExtension
   let exts' :: [SourceName]
exts' = [".pdf", ".png", ".jpg", ".mps", ".jpeg", ".jbig2", ".jb2"]
   let exts :: [SourceName]
exts  = [SourceName]
exts' [SourceName] -> [SourceName] -> [SourceName]
forall a. [a] -> [a] -> [a]
++ (SourceName -> SourceName) -> [SourceName] -> [SourceName]
forall a b. (a -> b) -> [a] -> [b]
map ((Char -> Char) -> SourceName -> SourceName
forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toUpper) [SourceName]
exts'
   let findFile :: SourceName -> [SourceName] -> m SourceName
findFile s :: SourceName
s [] = SourceName -> m SourceName
forall (m :: * -> *) a. Monad m => a -> m a
return SourceName
s
       findFile s :: SourceName
s (e :: SourceName
e:es :: [SourceName]
es) = do
         let s' :: SourceName
s' = SourceName -> SourceName -> SourceName
addExtension SourceName
s SourceName
e
         Bool
exists <- SourceName -> m Bool
forall (m :: * -> *). PandocMonad m => SourceName -> m Bool
fileExists SourceName
s'
         if Bool
exists
            then SourceName -> m SourceName
forall (m :: * -> *) a. Monad m => a -> m a
return SourceName
s'
            else SourceName -> [SourceName] -> m SourceName
findFile SourceName
s [SourceName]
es
   SourceName
src' <- case SourceName -> SourceName
takeExtension SourceName
src of
               "" | Bool -> Bool
not (Text -> Bool
T.null Text
defaultExt) -> SourceName -> ParsecT [Tok] LaTeXState m SourceName
forall (m :: * -> *) a. Monad m => a -> m a
return (SourceName -> ParsecT [Tok] LaTeXState m SourceName)
-> SourceName -> ParsecT [Tok] LaTeXState m SourceName
forall a b. (a -> b) -> a -> b
$ SourceName -> SourceName -> SourceName
addExtension SourceName
src (SourceName -> SourceName) -> SourceName -> SourceName
forall a b. (a -> b) -> a -> b
$ Text -> SourceName
T.unpack Text
defaultExt
                  | Bool
otherwise -> SourceName -> [SourceName] -> ParsecT [Tok] LaTeXState m SourceName
forall (m :: * -> *).
PandocMonad m =>
SourceName -> [SourceName] -> m SourceName
findFile SourceName
src [SourceName]
exts
               _  -> SourceName -> ParsecT [Tok] LaTeXState m SourceName
forall (m :: * -> *) a. Monad m => a -> m a
return SourceName
src
   Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> LP m Inlines) -> Inlines -> LP m Inlines
forall a b. (a -> b) -> a -> b
$ Attr -> Text -> Text -> Inlines -> Inlines
imageWith Attr
forall a. (Text, [a], [(Text, Text)])
attr (SourceName -> Text
T.pack SourceName
src') "" Inlines
alt

doxspace :: PandocMonad m => LP m Inlines
doxspace :: LP m Inlines
doxspace =
  (Inlines
space Inlines -> ParsecT [Tok] LaTeXState m Tok -> LP m Inlines
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT [Tok] LaTeXState m Tok -> ParsecT [Tok] LaTeXState m Tok
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead ((Tok -> Bool) -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => (Tok -> Bool) -> LP m Tok
satisfyTok Tok -> Bool
startsWithLetter)) LP m Inlines -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
forall a. Monoid a => a
mempty
  where startsWithLetter :: Tok -> Bool
startsWithLetter (Tok _ Word t :: Text
t) =
          case Text -> Maybe (Char, Text)
T.uncons Text
t of
               Just (c :: Char
c, _) | Char -> Bool
isLetter Char
c -> Bool
True
               _           -> Bool
False
        startsWithLetter _ = Bool
False


-- converts e.g. \SI{1}[\$]{} to "$ 1" or \SI{1}{\euro} to "1 €"
dosiunitx :: PandocMonad m => LP m Inlines
dosiunitx :: LP m Inlines
dosiunitx = do
  LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts
  Inlines
value <- LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok
  Inlines
valueprefix <- Inlines -> LP m Inlines -> LP m Inlines
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option "" (LP m Inlines -> LP m Inlines) -> LP m Inlines -> LP m Inlines
forall a b. (a -> b) -> a -> b
$ LP m Inlines -> LP m Inlines
forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
bracketed LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok
  Inlines
unit <- LP m Inlines -> LP m Inlines
forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
grouped ([Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines)
-> ParsecT [Tok] LaTeXState m [Inlines] -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines -> ParsecT [Tok] LaTeXState m [Inlines]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
siUnit) LP m Inlines -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
siUnit LP m Inlines -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok
  let emptyOr160 :: a -> p
emptyOr160 "" = ""
      emptyOr160 _  = "\160"
  Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> LP m Inlines)
-> ([Inlines] -> Inlines) -> [Inlines] -> LP m Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> LP m Inlines) -> [Inlines] -> LP m Inlines
forall a b. (a -> b) -> a -> b
$ [Inlines
valueprefix,
                      Inlines -> Inlines
forall a p. (Eq a, IsString a, IsString p) => a -> p
emptyOr160 Inlines
valueprefix,
                      Inlines
value,
                      Inlines -> Inlines
forall a p. (Eq a, IsString a, IsString p) => a -> p
emptyOr160 Inlines
unit,
                      Inlines
unit]

siUnit :: PandocMonad m => LP m Inlines
siUnit :: LP m Inlines
siUnit = do
  Tok _ (CtrlSeq name :: Text
name) _ <- LP m Tok
forall (m :: * -> *). PandocMonad m => LP m Tok
anyControlSeq
  if Text
name Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== "square"
     then do
       Inlines
unit <- LP m Inlines -> LP m Inlines
forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
grouped ([Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines)
-> ParsecT [Tok] LaTeXState m [Inlines] -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines -> ParsecT [Tok] LaTeXState m [Inlines]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
siUnit) LP m Inlines -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
siUnit LP m Inlines -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok
       Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> LP m Inlines)
-> ([Inlines] -> Inlines) -> [Inlines] -> LP m Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> LP m Inlines) -> [Inlines] -> LP m Inlines
forall a b. (a -> b) -> a -> b
$ [Inlines
unit, "\178"]
     else
       case Text -> Map Text Inlines -> Maybe Inlines
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Text
name Map Text Inlines
siUnitMap of
            Just il :: Inlines
il -> Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
il
            Nothing -> LP m Inlines
forall (m :: * -> *) a. MonadPlus m => m a
mzero

siUnitMap :: M.Map Text Inlines
siUnitMap :: Map Text Inlines
siUnitMap = [(Text, Inlines)] -> Map Text Inlines
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList
  [ ("fg", Text -> Inlines
str "fg")
  , ("pg", Text -> Inlines
str "pg")
  , ("ng", Text -> Inlines
str "ng")
  , ("ug", Text -> Inlines
str "μg")
  , ("mg", Text -> Inlines
str "mg")
  , ("g", Text -> Inlines
str "g")
  , ("kg", Text -> Inlines
str "kg")
  , ("amu", Text -> Inlines
str "u")
  , ("pm", Text -> Inlines
str "pm")
  , ("nm", Text -> Inlines
str "nm")
  , ("um", Text -> Inlines
str "μm")
  , ("mm", Text -> Inlines
str "mm")
  , ("cm", Text -> Inlines
str "cm")
  , ("dm", Text -> Inlines
str "dm")
  , ("m", Text -> Inlines
str "m")
  , ("km", Text -> Inlines
str "km")
  , ("as", Text -> Inlines
str "as")
  , ("fs", Text -> Inlines
str "fs")
  , ("ps", Text -> Inlines
str "ps")
  , ("ns", Text -> Inlines
str "ns")
  , ("us", Text -> Inlines
str "μs")
  , ("ms", Text -> Inlines
str "ms")
  , ("s", Text -> Inlines
str "s")
  , ("fmol", Text -> Inlines
str "fmol")
  , ("pmol", Text -> Inlines
str "pmol")
  , ("nmol", Text -> Inlines
str "nmol")
  , ("umol", Text -> Inlines
str "μmol")
  , ("mmol", Text -> Inlines
str "mmol")
  , ("mol", Text -> Inlines
str "mol")
  , ("kmol", Text -> Inlines
str "kmol")
  , ("pA", Text -> Inlines
str "pA")
  , ("nA", Text -> Inlines
str "nA")
  , ("uA", Text -> Inlines
str "μA")
  , ("mA", Text -> Inlines
str "mA")
  , ("A", Text -> Inlines
str "A")
  , ("kA", Text -> Inlines
str "kA")
  , ("ul", Text -> Inlines
str "μl")
  , ("ml", Text -> Inlines
str "ml")
  , ("l", Text -> Inlines
str "l")
  , ("hl", Text -> Inlines
str "hl")
  , ("uL", Text -> Inlines
str "μL")
  , ("mL", Text -> Inlines
str "mL")
  , ("L", Text -> Inlines
str "L")
  , ("hL", Text -> Inlines
str "hL")
  , ("mHz", Text -> Inlines
str "mHz")
  , ("Hz", Text -> Inlines
str "Hz")
  , ("kHz", Text -> Inlines
str "kHz")
  , ("MHz", Text -> Inlines
str "MHz")
  , ("GHz", Text -> Inlines
str "GHz")
  , ("THz", Text -> Inlines
str "THz")
  , ("mN", Text -> Inlines
str "mN")
  , ("N", Text -> Inlines
str "N")
  , ("kN", Text -> Inlines
str "kN")
  , ("MN", Text -> Inlines
str "MN")
  , ("Pa", Text -> Inlines
str "Pa")
  , ("kPa", Text -> Inlines
str "kPa")
  , ("MPa", Text -> Inlines
str "MPa")
  , ("GPa", Text -> Inlines
str "GPa")
  , ("mohm", Text -> Inlines
str "mΩ")
  , ("kohm", Text -> Inlines
str "kΩ")
  , ("Mohm", Text -> Inlines
str "MΩ")
  , ("pV", Text -> Inlines
str "pV")
  , ("nV", Text -> Inlines
str "nV")
  , ("uV", Text -> Inlines
str "μV")
  , ("mV", Text -> Inlines
str "mV")
  , ("V", Text -> Inlines
str "V")
  , ("kV", Text -> Inlines
str "kV")
  , ("W", Text -> Inlines
str "W")
  , ("uW", Text -> Inlines
str "μW")
  , ("mW", Text -> Inlines
str "mW")
  , ("kW", Text -> Inlines
str "kW")
  , ("MW", Text -> Inlines
str "MW")
  , ("GW", Text -> Inlines
str "GW")
  , ("J", Text -> Inlines
str "J")
  , ("uJ", Text -> Inlines
str "μJ")
  , ("mJ", Text -> Inlines
str "mJ")
  , ("kJ", Text -> Inlines
str "kJ")
  , ("eV", Text -> Inlines
str "eV")
  , ("meV", Text -> Inlines
str "meV")
  , ("keV", Text -> Inlines
str "keV")
  , ("MeV", Text -> Inlines
str "MeV")
  , ("GeV", Text -> Inlines
str "GeV")
  , ("TeV", Text -> Inlines
str "TeV")
  , ("kWh", Text -> Inlines
str "kWh")
  , ("F", Text -> Inlines
str "F")
  , ("fF", Text -> Inlines
str "fF")
  , ("pF", Text -> Inlines
str "pF")
  , ("K", Text -> Inlines
str "K")
  , ("dB", Text -> Inlines
str "dB")
  , ("angstrom", Text -> Inlines
str "Å")
  , ("arcmin", Text -> Inlines
str "′")
  , ("arcminute", Text -> Inlines
str "′")
  , ("arcsecond", Text -> Inlines
str "″")
  , ("astronomicalunit", Text -> Inlines
str "ua")
  , ("atomicmassunit", Text -> Inlines
str "u")
  , ("atto", Text -> Inlines
str "a")
  , ("bar", Text -> Inlines
str "bar")
  , ("barn", Text -> Inlines
str "b")
  , ("becquerel", Text -> Inlines
str "Bq")
  , ("bel", Text -> Inlines
str "B")
  , ("candela", Text -> Inlines
str "cd")
  , ("celsius", Text -> Inlines
str "°C")
  , ("centi", Text -> Inlines
str "c")
  , ("coulomb", Text -> Inlines
str "C")
  , ("dalton", Text -> Inlines
str "Da")
  , ("day", Text -> Inlines
str "d")
  , ("deca", Text -> Inlines
str "d")
  , ("deci", Text -> Inlines
str "d")
  , ("decibel", Text -> Inlines
str "db")
  , ("degreeCelsius",Text -> Inlines
str "°C")
  , ("degree", Text -> Inlines
str "°")
  , ("deka", Text -> Inlines
str "d")
  , ("electronvolt", Text -> Inlines
str "eV")
  , ("exa", Text -> Inlines
str "E")
  , ("farad", Text -> Inlines
str "F")
  , ("femto", Text -> Inlines
str "f")
  , ("giga", Text -> Inlines
str "G")
  , ("gram", Text -> Inlines
str "g")
  , ("hectare", Text -> Inlines
str "ha")
  , ("hecto", Text -> Inlines
str "h")
  , ("henry", Text -> Inlines
str "H")
  , ("hertz", Text -> Inlines
str "Hz")
  , ("hour", Text -> Inlines
str "h")
  , ("joule", Text -> Inlines
str "J")
  , ("katal", Text -> Inlines
str "kat")
  , ("kelvin", Text -> Inlines
str "K")
  , ("kilo", Text -> Inlines
str "k")
  , ("kilogram", Text -> Inlines
str "kg")
  , ("knot", Text -> Inlines
str "kn")
  , ("liter", Text -> Inlines
str "L")
  , ("litre", Text -> Inlines
str "l")
  , ("lumen", Text -> Inlines
str "lm")
  , ("lux", Text -> Inlines
str "lx")
  , ("mega", Text -> Inlines
str "M")
  , ("meter", Text -> Inlines
str "m")
  , ("metre", Text -> Inlines
str "m")
  , ("micro", Text -> Inlines
str "μ")
  , ("milli", Text -> Inlines
str "m")
  , ("minute", Text -> Inlines
str "min")
  , ("mmHg", Text -> Inlines
str "mmHg")
  , ("mole", Text -> Inlines
str "mol")
  , ("nano", Text -> Inlines
str "n")
  , ("nauticalmile", Text -> Inlines
str "M")
  , ("neper", Text -> Inlines
str "Np")
  , ("newton", Text -> Inlines
str "N")
  , ("ohm", Text -> Inlines
str "Ω")
  , ("Pa", Text -> Inlines
str "Pa")
  , ("pascal", Text -> Inlines
str "Pa")
  , ("percent", Text -> Inlines
str "%")
  , ("per", Text -> Inlines
str "/")
  , ("peta", Text -> Inlines
str "P")
  , ("pico", Text -> Inlines
str "p")
  , ("radian", Text -> Inlines
str "rad")
  , ("second", Text -> Inlines
str "s")
  , ("siemens", Text -> Inlines
str "S")
  , ("sievert", Text -> Inlines
str "Sv")
  , ("steradian", Text -> Inlines
str "sr")
  , ("tera", Text -> Inlines
str "T")
  , ("tesla", Text -> Inlines
str "T")
  , ("tonne", Text -> Inlines
str "t")
  , ("volt", Text -> Inlines
str "V")
  , ("watt", Text -> Inlines
str "W")
  , ("weber", Text -> Inlines
str "Wb")
  , ("yocto", Text -> Inlines
str "y")
  , ("yotta", Text -> Inlines
str "Y")
  , ("zepto", Text -> Inlines
str "z")
  , ("zetta", Text -> Inlines
str "Z")
  ]

lit :: Text -> LP m Inlines
lit :: Text -> LP m Inlines
lit = Inlines -> LP m Inlines
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Inlines -> LP m Inlines)
-> (Text -> Inlines) -> Text -> LP m Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Inlines
str

removeDoubleQuotes :: Text -> Text
removeDoubleQuotes :: Text -> Text
removeDoubleQuotes t :: Text
t =
  Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
Data.Maybe.fromMaybe Text
t (Maybe Text -> Text) -> Maybe Text -> Text
forall a b. (a -> b) -> a -> b
$ Text -> Text -> Maybe Text
T.stripPrefix "\"" Text
t Maybe Text -> (Text -> Maybe Text) -> Maybe Text
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> Text -> Maybe Text
T.stripSuffix "\""

doubleQuote :: PandocMonad m => LP m Inlines
doubleQuote :: LP m Inlines
doubleQuote =
       (Inlines -> Inlines) -> LP m [Tok] -> LP m () -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
(Inlines -> Inlines) -> LP m [Tok] -> LP m () -> LP m Inlines
quoted' Inlines -> Inlines
doubleQuoted (LP m [Tok] -> LP m [Tok]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (LP m [Tok] -> LP m [Tok]) -> LP m [Tok] -> LP m [Tok]
forall a b. (a -> b) -> a -> b
$ Int -> ParsecT [Tok] LaTeXState m Tok -> LP m [Tok]
forall s (m :: * -> *) t u a.
Stream s m t =>
Int -> ParsecT s u m a -> ParsecT s u m [a]
count 2 (ParsecT [Tok] LaTeXState m Tok -> LP m [Tok])
-> ParsecT [Tok] LaTeXState m Tok -> LP m [Tok]
forall a b. (a -> b) -> a -> b
$ Char -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '`')
                     (LP m [Tok] -> LP m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (LP m [Tok] -> LP m ()) -> LP m [Tok] -> LP m ()
forall a b. (a -> b) -> a -> b
$ LP m [Tok] -> LP m [Tok]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (LP m [Tok] -> LP m [Tok]) -> LP m [Tok] -> LP m [Tok]
forall a b. (a -> b) -> a -> b
$ Int -> ParsecT [Tok] LaTeXState m Tok -> LP m [Tok]
forall s (m :: * -> *) t u a.
Stream s m t =>
Int -> ParsecT s u m a -> ParsecT s u m [a]
count 2 (ParsecT [Tok] LaTeXState m Tok -> LP m [Tok])
-> ParsecT [Tok] LaTeXState m Tok -> LP m [Tok]
forall a b. (a -> b) -> a -> b
$ Char -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '\'')
   LP m Inlines -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Inlines -> Inlines) -> LP m [Tok] -> LP m () -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
(Inlines -> Inlines) -> LP m [Tok] -> LP m () -> LP m Inlines
quoted' Inlines -> Inlines
doubleQuoted ((Tok -> [Tok] -> [Tok]
forall a. a -> [a] -> [a]
:[]) (Tok -> [Tok]) -> ParsecT [Tok] LaTeXState m Tok -> LP m [Tok]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Char -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '“') (ParsecT [Tok] LaTeXState m Tok -> LP m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT [Tok] LaTeXState m Tok -> LP m ())
-> ParsecT [Tok] LaTeXState m Tok -> LP m ()
forall a b. (a -> b) -> a -> b
$ Char -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '”')
   -- the following is used by babel for localized quotes:
   LP m Inlines -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Inlines -> Inlines) -> LP m [Tok] -> LP m () -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
(Inlines -> Inlines) -> LP m [Tok] -> LP m () -> LP m Inlines
quoted' Inlines -> Inlines
doubleQuoted (LP m [Tok] -> LP m [Tok]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (LP m [Tok] -> LP m [Tok]) -> LP m [Tok] -> LP m [Tok]
forall a b. (a -> b) -> a -> b
$ [ParsecT [Tok] LaTeXState m Tok] -> LP m [Tok]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [Char -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '"', Char -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '`'])
                            (LP m [Tok] -> LP m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (LP m [Tok] -> LP m ()) -> LP m [Tok] -> LP m ()
forall a b. (a -> b) -> a -> b
$ LP m [Tok] -> LP m [Tok]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (LP m [Tok] -> LP m [Tok]) -> LP m [Tok] -> LP m [Tok]
forall a b. (a -> b) -> a -> b
$ [ParsecT [Tok] LaTeXState m Tok] -> LP m [Tok]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [Char -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '"', Char -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '\''])

singleQuote :: PandocMonad m => LP m Inlines
singleQuote :: LP m Inlines
singleQuote =
       (Inlines -> Inlines) -> LP m [Tok] -> LP m () -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
(Inlines -> Inlines) -> LP m [Tok] -> LP m () -> LP m Inlines
quoted' Inlines -> Inlines
singleQuoted ((Tok -> [Tok] -> [Tok]
forall a. a -> [a] -> [a]
:[]) (Tok -> [Tok]) -> ParsecT [Tok] LaTeXState m Tok -> LP m [Tok]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Char -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '`')
                     (LP m () -> LP m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (LP m () -> LP m ()) -> LP m () -> LP m ()
forall a b. (a -> b) -> a -> b
$ Char -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '\'' ParsecT [Tok] LaTeXState m Tok -> LP m () -> LP m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
                           ParsecT [Tok] LaTeXState m Tok -> LP m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ((Tok -> Bool) -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => (Tok -> Bool) -> LP m Tok
satisfyTok Tok -> Bool
startsWithLetter))
   LP m Inlines -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Inlines -> Inlines) -> LP m [Tok] -> LP m () -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
(Inlines -> Inlines) -> LP m [Tok] -> LP m () -> LP m Inlines
quoted' Inlines -> Inlines
singleQuoted ((Tok -> [Tok] -> [Tok]
forall a. a -> [a] -> [a]
:[]) (Tok -> [Tok]) -> ParsecT [Tok] LaTeXState m Tok -> LP m [Tok]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Char -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '‘')
                            (LP m () -> LP m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (LP m () -> LP m ()) -> LP m () -> LP m ()
forall a b. (a -> b) -> a -> b
$ Char -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '’' ParsecT [Tok] LaTeXState m Tok -> LP m () -> LP m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
                                  ParsecT [Tok] LaTeXState m Tok -> LP m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ((Tok -> Bool) -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => (Tok -> Bool) -> LP m Tok
satisfyTok Tok -> Bool
startsWithLetter))
  where startsWithLetter :: Tok -> Bool
startsWithLetter (Tok _ Word t :: Text
t) =
          case Text -> Maybe (Char, Text)
T.uncons Text
t of
               Just (c :: Char
c, _) | Char -> Bool
isLetter Char
c -> Bool
True
               _           -> Bool
False
        startsWithLetter _ = Bool
False

quoted' :: PandocMonad m
        => (Inlines -> Inlines)
        -> LP m [Tok]
        -> LP m ()
        -> LP m Inlines
quoted' :: (Inlines -> Inlines) -> LP m [Tok] -> LP m () -> LP m Inlines
quoted' f :: Inlines -> Inlines
f starter :: LP m [Tok]
starter ender :: LP m ()
ender = do
  Text
startchs <- [Tok] -> Text
untokenize ([Tok] -> Text) -> LP m [Tok] -> ParsecT [Tok] LaTeXState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m [Tok]
starter
  Bool
smart <- Extension -> Extensions -> Bool
extensionEnabled Extension
Ext_smart (Extensions -> Bool)
-> ParsecT [Tok] LaTeXState m Extensions
-> ParsecT [Tok] LaTeXState m Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ReaderOptions -> Extensions)
-> ParsecT [Tok] LaTeXState m Extensions
forall st s (m :: * -> *) t b.
(HasReaderOptions st, Stream s m t) =>
(ReaderOptions -> b) -> ParserT s st m b
getOption ReaderOptions -> Extensions
readerExtensions
  if Bool
smart
     then do
       [Inlines]
ils <- LP m Inlines -> ParsecT [Tok] LaTeXState m [Inlines]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (LP m () -> LP m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy LP m ()
ender LP m () -> LP m Inlines -> LP m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
inline)
       (LP m ()
ender LP m () -> LP m Inlines -> LP m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> Inlines
f ([Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat [Inlines]
ils))) LP m Inlines -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
            (Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat [Inlines]
ils) (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
                    Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit (case Text
startchs of
                              "``" -> "“"
                              "`"  -> "‘"
                              cs :: Text
cs   -> Text
cs)
     else Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit Text
startchs

enquote :: PandocMonad m => Bool -> Maybe Text -> LP m Inlines
enquote :: Bool -> Maybe Text -> LP m Inlines
enquote starred :: Bool
starred mblang :: Maybe Text
mblang = do
  LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts
  let lang :: Maybe Lang
lang = Maybe Text
mblang Maybe Text -> (Text -> Maybe Lang) -> Maybe Lang
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> Maybe Lang
babelLangToBCP47
  let langspan :: Inlines -> Inlines
langspan = case Maybe Lang
lang of
                      Nothing -> Inlines -> Inlines
forall a. a -> a
id
                      Just l :: Lang
l  -> Attr -> Inlines -> Inlines
spanWith ("",[],[("lang", Lang -> Text
renderLang Lang
l)])
  QuoteContext
quoteContext <- LaTeXState -> QuoteContext
sQuoteContext (LaTeXState -> QuoteContext)
-> ParsecT [Tok] LaTeXState m LaTeXState
-> ParsecT [Tok] LaTeXState m QuoteContext
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m LaTeXState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  if Bool
starred Bool -> Bool -> Bool
|| QuoteContext
quoteContext QuoteContext -> QuoteContext -> Bool
forall a. Eq a => a -> a -> Bool
== QuoteContext
InDoubleQuote
     then Inlines -> Inlines
singleQuoted (Inlines -> Inlines) -> (Inlines -> Inlines) -> Inlines -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> Inlines
langspan (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> QuoteContext -> LP m Inlines -> LP m Inlines
forall st (m :: * -> *) s a.
HasQuoteContext st m =>
QuoteContext -> ParsecT s st m a -> ParsecT s st m a
withQuoteContext QuoteContext
InSingleQuote LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok
     else Inlines -> Inlines
doubleQuoted (Inlines -> Inlines) -> (Inlines -> Inlines) -> Inlines -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> Inlines
langspan (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> QuoteContext -> LP m Inlines -> LP m Inlines
forall st (m :: * -> *) s a.
HasQuoteContext st m =>
QuoteContext -> ParsecT s st m a -> ParsecT s st m a
withQuoteContext QuoteContext
InDoubleQuote LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok

blockquote :: PandocMonad m => Bool -> Maybe Text -> LP m Blocks
blockquote :: Bool -> Maybe Text -> LP m Blocks
blockquote citations :: Bool
citations mblang :: Maybe Text
mblang = do
  Blocks
citePar <- if Bool
citations
                then do
                  [Citation]
cs <- CitationMode -> Bool -> LP m [Citation]
forall (m :: * -> *).
PandocMonad m =>
CitationMode -> Bool -> LP m [Citation]
cites CitationMode
NormalCitation Bool
False
                  Blocks -> LP m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return (Blocks -> LP m Blocks) -> Blocks -> LP m Blocks
forall a b. (a -> b) -> a -> b
$ Inlines -> Blocks
para ([Citation] -> Inlines -> Inlines
cite [Citation]
cs Inlines
forall a. Monoid a => a
mempty)
                else Blocks -> LP m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
forall a. Monoid a => a
mempty
  let lang :: Maybe Lang
lang = Maybe Text
mblang Maybe Text -> (Text -> Maybe Lang) -> Maybe Lang
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> Maybe Lang
babelLangToBCP47
  let langdiv :: Blocks -> Blocks
langdiv = case Maybe Lang
lang of
                      Nothing -> Blocks -> Blocks
forall a. a -> a
id
                      Just l :: Lang
l  -> Attr -> Blocks -> Blocks
divWith ("",[],[("lang", Lang -> Text
renderLang Lang
l)])
  Blocks
bs <- LP m Blocks -> LP m Blocks
forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
grouped LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
block
  Blocks -> LP m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return (Blocks -> LP m Blocks) -> Blocks -> LP m Blocks
forall a b. (a -> b) -> a -> b
$ Blocks -> Blocks
blockQuote (Blocks -> Blocks) -> (Blocks -> Blocks) -> Blocks -> Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Blocks -> Blocks
langdiv (Blocks -> Blocks) -> Blocks -> Blocks
forall a b. (a -> b) -> a -> b
$ (Blocks
bs Blocks -> Blocks -> Blocks
forall a. Semigroup a => a -> a -> a
<> Blocks
citePar)

doAcronym :: PandocMonad m => Text -> LP m Inlines
doAcronym :: Text -> LP m Inlines
doAcronym form :: Text
form = do
  [Tok]
acro <- LP m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
  Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> LP m Inlines)
-> ([Inlines] -> Inlines) -> [Inlines] -> LP m Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> LP m Inlines) -> [Inlines] -> LP m Inlines
forall a b. (a -> b) -> a -> b
$ [Attr -> Inlines -> Inlines
spanWith ("",[],[("acronym-label", [Tok] -> Text
untokenize [Tok]
acro),
    ("acronym-form", "singular+" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
form)])
    (Inlines -> Inlines) -> Inlines -> Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
str (Text -> Inlines) -> Text -> Inlines
forall a b. (a -> b) -> a -> b
$ [Tok] -> Text
untokenize [Tok]
acro]

doAcronymPlural :: PandocMonad m => Text -> LP m Inlines
doAcronymPlural :: Text -> LP m Inlines
doAcronymPlural form :: Text
form = do
  [Tok]
acro <- LP m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
  Inlines
plural <- Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "s"
  Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> LP m Inlines)
-> ([Inlines] -> Inlines) -> [Inlines] -> LP m Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> LP m Inlines) -> [Inlines] -> LP m Inlines
forall a b. (a -> b) -> a -> b
$ [Attr -> Inlines -> Inlines
spanWith ("",[],[("acronym-label", [Tok] -> Text
untokenize [Tok]
acro),
    ("acronym-form", "plural+" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
form)]) (Inlines -> Inlines) -> Inlines -> Inlines
forall a b. (a -> b) -> a -> b
$
   [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat [Text -> Inlines
str (Text -> Inlines) -> Text -> Inlines
forall a b. (a -> b) -> a -> b
$ [Tok] -> Text
untokenize [Tok]
acro, Inlines
plural]]

doverb :: PandocMonad m => LP m Inlines
doverb :: LP m Inlines
doverb = do
  Tok _ Symbol t :: Text
t <- LP m Tok
forall (m :: * -> *). PandocMonad m => LP m Tok
anySymbol
  Char
marker <- case Text -> Maybe (Char, Text)
T.uncons Text
t of
              Just (c :: Char
c, ts :: Text
ts) | Text -> Bool
T.null Text
ts -> Char -> ParsecT [Tok] LaTeXState m Char
forall (m :: * -> *) a. Monad m => a -> m a
return Char
c
              _            -> ParsecT [Tok] LaTeXState m Char
forall (m :: * -> *) a. MonadPlus m => m a
mzero
  LP m Inlines -> LP m Inlines
forall (m :: * -> *) a. PandocMonad m => LP m a -> LP m a
withVerbatimMode (LP m Inlines -> LP m Inlines) -> LP m Inlines -> LP m Inlines
forall a b. (a -> b) -> a -> b
$
    (Text -> Inlines
code (Text -> Inlines) -> ([Tok] -> Text) -> [Tok] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize) ([Tok] -> Inlines)
-> ParsecT [Tok] LaTeXState m [Tok] -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
      LP m Tok -> LP m Tok -> ParsecT [Tok] LaTeXState m [Tok]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill (ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
newlineTok ParsecT [Tok] LaTeXState m () -> LP m Tok -> LP m Tok
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Char -> LP m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
verbTok Char
marker) (Char -> LP m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol Char
marker)

verbTok :: PandocMonad m => Char -> LP m Tok
verbTok :: Char -> LP m Tok
verbTok stopchar :: Char
stopchar = do
  t :: Tok
t@(Tok pos :: SourcePos
pos toktype :: TokType
toktype txt :: Text
txt) <- LP m Tok
forall (m :: * -> *). PandocMonad m => LP m Tok
anyTok
  case (Char -> Bool) -> Text -> Maybe Int
T.findIndex (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
stopchar) Text
txt of
       Nothing -> Tok -> LP m Tok
forall (m :: * -> *) a. Monad m => a -> m a
return Tok
t
       Just i :: Int
i  -> do
         let (t1 :: Text
t1, t2 :: Text
t2) = Int -> Text -> (Text, Text)
T.splitAt Int
i Text
txt
         [Tok]
inp <- ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *) s u. Monad m => ParsecT s u m s
getInput
         [Tok] -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) s u. Monad m => s -> ParsecT s u m ()
setInput ([Tok] -> ParsecT [Tok] LaTeXState m ())
-> [Tok] -> ParsecT [Tok] LaTeXState m ()
forall a b. (a -> b) -> a -> b
$ SourcePos -> TokType -> Text -> Tok
Tok (SourcePos -> Int -> SourcePos
incSourceColumn SourcePos
pos Int
i) TokType
Symbol (Char -> Text
T.singleton Char
stopchar)
                  Tok -> [Tok] -> [Tok]
forall a. a -> [a] -> [a]
: SourcePos -> Text -> [Tok]
totoks (SourcePos -> Int -> SourcePos
incSourceColumn SourcePos
pos (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ 1)) (Int -> Text -> Text
T.drop 1 Text
t2) [Tok] -> [Tok] -> [Tok]
forall a. [a] -> [a] -> [a]
++ [Tok]
inp
         Tok -> LP m Tok
forall (m :: * -> *) a. Monad m => a -> m a
return (Tok -> LP m Tok) -> Tok -> LP m Tok
forall a b. (a -> b) -> a -> b
$ SourcePos -> TokType -> Text -> Tok
Tok SourcePos
pos TokType
toktype Text
t1

listingsLanguage :: [(Text, Text)] -> Maybe Text
listingsLanguage :: [(Text, Text)] -> Maybe Text
listingsLanguage opts :: [(Text, Text)]
opts =
  case Text -> [(Text, Text)] -> Maybe Text
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup "language" [(Text, Text)]
opts of
    Nothing  -> Maybe Text
forall a. Maybe a
Nothing
    Just l :: Text
l   -> Text -> Maybe Text
fromListingsLanguage Text
l Maybe Text -> Maybe Text -> Maybe Text
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
`mplus` Text -> Maybe Text
forall a. a -> Maybe a
Just Text
l

dolstinline :: PandocMonad m => LP m Inlines
dolstinline :: LP m Inlines
dolstinline = do
  [(Text, Text)]
options <- [(Text, Text)]
-> ParsecT [Tok] LaTeXState m [(Text, Text)]
-> ParsecT [Tok] LaTeXState m [(Text, Text)]
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option [] ParsecT [Tok] LaTeXState m [(Text, Text)]
forall (m :: * -> *). PandocMonad m => LP m [(Text, Text)]
keyvals
  let classes :: [Text]
classes = Maybe Text -> [Text]
forall a. Maybe a -> [a]
maybeToList (Maybe Text -> [Text]) -> Maybe Text -> [Text]
forall a b. (a -> b) -> a -> b
$ [(Text, Text)] -> Maybe Text
listingsLanguage [(Text, Text)]
options
  [Text] -> LP m Inlines
forall (m :: * -> *). PandocMonad m => [Text] -> LP m Inlines
doinlinecode [Text]
classes

domintinline :: PandocMonad m => LP m Inlines
domintinline :: LP m Inlines
domintinline = do
  LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts
  Text
cls <- [Tok] -> Text
untokenize ([Tok] -> Text)
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
  [Text] -> LP m Inlines
forall (m :: * -> *). PandocMonad m => [Text] -> LP m Inlines
doinlinecode [Text
cls]

doinlinecode :: PandocMonad m => [Text] -> LP m Inlines
doinlinecode :: [Text] -> LP m Inlines
doinlinecode classes :: [Text]
classes = do
  Tok _ Symbol t :: Text
t <- LP m Tok
forall (m :: * -> *). PandocMonad m => LP m Tok
anySymbol
  Char
marker <- case Text -> Maybe (Char, Text)
T.uncons Text
t of
              Just (c :: Char
c, ts :: Text
ts) | Text -> Bool
T.null Text
ts -> Char -> ParsecT [Tok] LaTeXState m Char
forall (m :: * -> *) a. Monad m => a -> m a
return Char
c
              _            -> ParsecT [Tok] LaTeXState m Char
forall (m :: * -> *) a. MonadPlus m => m a
mzero
  let stopchar :: Char
stopchar = if Char
marker Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== '{' then '}' else Char
marker
  LP m Inlines -> LP m Inlines
forall (m :: * -> *) a. PandocMonad m => LP m a -> LP m a
withVerbatimMode (LP m Inlines -> LP m Inlines) -> LP m Inlines -> LP m Inlines
forall a b. (a -> b) -> a -> b
$
    (Attr -> Text -> Inlines
codeWith ("",[Text]
classes,[]) (Text -> Inlines) -> ([Tok] -> Text) -> [Tok] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Char) -> Text -> Text
T.map Char -> Char
nlToSpace (Text -> Text) -> ([Tok] -> Text) -> [Tok] -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize) ([Tok] -> Inlines)
-> ParsecT [Tok] LaTeXState m [Tok] -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
      LP m Tok -> LP m Tok -> ParsecT [Tok] LaTeXState m [Tok]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill (Char -> LP m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
verbTok Char
stopchar) (Char -> LP m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol Char
stopchar)

nlToSpace :: Char -> Char
nlToSpace :: Char -> Char
nlToSpace '\n' = ' '
nlToSpace x :: Char
x    = Char
x

keyval :: PandocMonad m => LP m (Text, Text)
keyval :: LP m (Text, Text)
keyval = LP m (Text, Text) -> LP m (Text, Text)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (LP m (Text, Text) -> LP m (Text, Text))
-> LP m (Text, Text) -> LP m (Text, Text)
forall a b. (a -> b) -> a -> b
$ do
  Tok _ Word key :: Text
key <- (Tok -> Bool) -> LP m Tok
forall (m :: * -> *). PandocMonad m => (Tok -> Bool) -> LP m Tok
satisfyTok Tok -> Bool
isWordTok
  LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
sp
  Text
val <- Text
-> ParsecT [Tok] LaTeXState m Text
-> ParsecT [Tok] LaTeXState m Text
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Text
forall a. Monoid a => a
mempty (ParsecT [Tok] LaTeXState m Text
 -> ParsecT [Tok] LaTeXState m Text)
-> ParsecT [Tok] LaTeXState m Text
-> ParsecT [Tok] LaTeXState m Text
forall a b. (a -> b) -> a -> b
$ do
           Char -> LP m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '='
           LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
sp
           ([Tok] -> Text
untokenize ([Tok] -> Text)
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced) ParsecT [Tok] LaTeXState m Text
-> ParsecT [Tok] LaTeXState m Text
-> ParsecT [Tok] LaTeXState m Text
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
             ([Text] -> Text
forall a. Monoid a => [a] -> a
mconcat ([Text] -> Text)
-> ParsecT [Tok] LaTeXState m [Text]
-> ParsecT [Tok] LaTeXState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m Text
-> ParsecT [Tok] LaTeXState m [Text]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (
                 ([Tok] -> Text
untokenize ([Tok] -> Text)
-> (([Tok], [Tok]) -> [Tok]) -> ([Tok], [Tok]) -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Tok], [Tok]) -> [Tok]
forall a b. (a, b) -> b
snd (([Tok], [Tok]) -> Text)
-> ParsecT [Tok] LaTeXState m ([Tok], [Tok])
-> ParsecT [Tok] LaTeXState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m ([Tok], [Tok])
forall (m :: * -> *) a. PandocMonad m => LP m a -> LP m (a, [Tok])
withRaw ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced)
                 ParsecT [Tok] LaTeXState m Text
-> ParsecT [Tok] LaTeXState m Text
-> ParsecT [Tok] LaTeXState m Text
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
                 ([Tok] -> Text
untokenize ([Tok] -> Text)
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (LP m Tok -> ParsecT [Tok] LaTeXState m [Tok]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1
                      ((Tok -> Bool) -> LP m Tok
forall (m :: * -> *). PandocMonad m => (Tok -> Bool) -> LP m Tok
satisfyTok
                         (\t :: Tok
t -> case Tok
t of
                                Tok _ Symbol "]" -> Bool
False
                                Tok _ Symbol "," -> Bool
False
                                Tok _ Symbol "{" -> Bool
False
                                Tok _ Symbol "}" -> Bool
False
                                _                -> Bool
True))))))
  LP m Tok -> ParsecT [Tok] LaTeXState m (Maybe Tok)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Char -> LP m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol ',')
  LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
sp
  (Text, Text) -> LP m (Text, Text)
forall (m :: * -> *) a. Monad m => a -> m a
return (Text
key, Text -> Text
T.strip Text
val)

keyvals :: PandocMonad m => LP m [(Text, Text)]
keyvals :: LP m [(Text, Text)]
keyvals = LP m [(Text, Text)] -> LP m [(Text, Text)]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (LP m [(Text, Text)] -> LP m [(Text, Text)])
-> LP m [(Text, Text)] -> LP m [(Text, Text)]
forall a b. (a -> b) -> a -> b
$ Char -> LP m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '[' LP m Tok -> LP m [(Text, Text)] -> LP m [(Text, Text)]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT [Tok] LaTeXState m (Text, Text)
-> LP m Tok -> LP m [(Text, Text)]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ParsecT [Tok] LaTeXState m (Text, Text)
forall (m :: * -> *). PandocMonad m => LP m (Text, Text)
keyval (Char -> LP m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol ']') LP m [(Text, Text)]
-> ParsecT [Tok] LaTeXState m () -> LP m [(Text, Text)]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
sp

accent :: PandocMonad m => Char -> Maybe Char -> LP m Inlines
accent :: Char -> Maybe Char -> LP m Inlines
accent combiningAccent :: Char
combiningAccent fallBack :: Maybe Char
fallBack = LP m Inlines -> LP m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (LP m Inlines -> LP m Inlines) -> LP m Inlines -> LP m Inlines
forall a b. (a -> b) -> a -> b
$ do
  Inlines
ils <- LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok
  case Inlines -> [Inline]
forall a. Many a -> [a]
toList Inlines
ils of
       (Str (Text -> Maybe (Char, Text)
T.uncons -> Just (x :: Char
x, xs :: Text
xs)) : ys :: [Inline]
ys) -> Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> LP m Inlines) -> Inlines -> LP m Inlines
forall a b. (a -> b) -> a -> b
$ [Inline] -> Inlines
forall a. [a] -> Many a
fromList ([Inline] -> Inlines) -> [Inline] -> Inlines
forall a b. (a -> b) -> a -> b
$
         -- try to normalize to the combined character:
         Text -> Inline
Str (NormalizationMode -> Text -> Text
Normalize.normalize NormalizationMode
Normalize.NFC
               (SourceName -> Text
T.pack [Char
x, Char
combiningAccent]) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
xs) Inline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
: [Inline]
ys
       [Space]           -> Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> LP m Inlines) -> Inlines -> LP m Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
str (Text -> Inlines) -> Text -> Inlines
forall a b. (a -> b) -> a -> b
$ Char -> Text
T.singleton (Char -> Text) -> Char -> Text
forall a b. (a -> b) -> a -> b
$ Char -> Maybe Char -> Char
forall a. a -> Maybe a -> a
fromMaybe Char
combiningAccent Maybe Char
fallBack
       []                -> Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> LP m Inlines) -> Inlines -> LP m Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
str (Text -> Inlines) -> Text -> Inlines
forall a b. (a -> b) -> a -> b
$ Char -> Text
T.singleton (Char -> Text) -> Char -> Text
forall a b. (a -> b) -> a -> b
$ Char -> Maybe Char -> Char
forall a. a -> Maybe a -> a
fromMaybe Char
combiningAccent Maybe Char
fallBack
       _                 -> Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
ils

mathDisplay :: Text -> Inlines
mathDisplay :: Text -> Inlines
mathDisplay = Text -> Inlines
displayMath (Text -> Inlines) -> (Text -> Text) -> Text -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
trimMath

mathInline :: Text -> Inlines
mathInline :: Text -> Inlines
mathInline = Text -> Inlines
math (Text -> Inlines) -> (Text -> Text) -> Text -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
trimMath

dollarsMath :: PandocMonad m => LP m Inlines
dollarsMath :: LP m Inlines
dollarsMath = do
  Char -> LP m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '$'
  Bool
display <- Bool
-> ParsecT [Tok] LaTeXState m Bool
-> ParsecT [Tok] LaTeXState m Bool
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Bool
False (Bool
True Bool -> LP m Tok -> ParsecT [Tok] LaTeXState m Bool
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> LP m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '$')
  (do Text
contents <- ParsecT [Tok] LaTeXState m Text -> ParsecT [Tok] LaTeXState m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT [Tok] LaTeXState m Text
 -> ParsecT [Tok] LaTeXState m Text)
-> ParsecT [Tok] LaTeXState m Text
-> ParsecT [Tok] LaTeXState m Text
forall a b. (a -> b) -> a -> b
$ [Tok] -> Text
untokenize ([Tok] -> Text)
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => Int -> LP m [Tok]
pDollarsMath 0
      if Bool
display
         then (Text -> Inlines
mathDisplay Text
contents Inlines -> LP m Tok -> LP m Inlines
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> LP m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '$')
         else Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> LP m Inlines) -> Inlines -> LP m Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
mathInline Text
contents)
   LP m Inlines -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Bool -> ParsecT [Tok] LaTeXState m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard Bool
display ParsecT [Tok] LaTeXState m () -> LP m Inlines -> LP m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> Inlines
mathInline ""))

-- Int is number of embedded groupings
pDollarsMath :: PandocMonad m => Int -> LP m [Tok]
pDollarsMath :: Int -> LP m [Tok]
pDollarsMath n :: Int
n = do
  tk :: Tok
tk@(Tok _ toktype :: TokType
toktype t :: Text
t) <- LP m Tok
forall (m :: * -> *). PandocMonad m => LP m Tok
anyTok
  case TokType
toktype of
       Symbol | Text
t Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== "$"
              , Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== 0 -> [Tok] -> LP m [Tok]
forall (m :: * -> *) a. Monad m => a -> m a
return []
              | Text
t Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== "\\" -> do
                  Tok
tk' <- LP m Tok
forall (m :: * -> *). PandocMonad m => LP m Tok
anyTok
                  ((Tok
tk Tok -> [Tok] -> [Tok]
forall a. a -> [a] -> [a]
:) ([Tok] -> [Tok]) -> ([Tok] -> [Tok]) -> [Tok] -> [Tok]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Tok
tk' Tok -> [Tok] -> [Tok]
forall a. a -> [a] -> [a]
:)) ([Tok] -> [Tok]) -> LP m [Tok] -> LP m [Tok]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> LP m [Tok]
forall (m :: * -> *). PandocMonad m => Int -> LP m [Tok]
pDollarsMath Int
n
              | Text
t Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== "{" -> (Tok
tk Tok -> [Tok] -> [Tok]
forall a. a -> [a] -> [a]
:) ([Tok] -> [Tok]) -> LP m [Tok] -> LP m [Tok]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> LP m [Tok]
forall (m :: * -> *). PandocMonad m => Int -> LP m [Tok]
pDollarsMath (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
+1)
              | Text
t Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== "}" ->
                if Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 0
                then (Tok
tk Tok -> [Tok] -> [Tok]
forall a. a -> [a] -> [a]
:) ([Tok] -> [Tok]) -> LP m [Tok] -> LP m [Tok]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> LP m [Tok]
forall (m :: * -> *). PandocMonad m => Int -> LP m [Tok]
pDollarsMath (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-1)
                else LP m [Tok]
forall (m :: * -> *) a. MonadPlus m => m a
mzero
       _ -> (Tok
tk Tok -> [Tok] -> [Tok]
forall a. a -> [a] -> [a]
:) ([Tok] -> [Tok]) -> LP m [Tok] -> LP m [Tok]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> LP m [Tok]
forall (m :: * -> *). PandocMonad m => Int -> LP m [Tok]
pDollarsMath Int
n

-- citations

addPrefix :: [Inline] -> [Citation] -> [Citation]
addPrefix :: [Inline] -> [Citation] -> [Citation]
addPrefix p :: [Inline]
p (k :: Citation
k:ks :: [Citation]
ks) = Citation
k {citationPrefix :: [Inline]
citationPrefix = [Inline]
p [Inline] -> [Inline] -> [Inline]
forall a. [a] -> [a] -> [a]
++ Citation -> [Inline]
citationPrefix Citation
k} Citation -> [Citation] -> [Citation]
forall a. a -> [a] -> [a]
: [Citation]
ks
addPrefix _ _      = []

addSuffix :: [Inline] -> [Citation] -> [Citation]
addSuffix :: [Inline] -> [Citation] -> [Citation]
addSuffix s :: [Inline]
s ks :: [Citation]
ks@(_:_) =
  let k :: Citation
k = [Citation] -> Citation
forall a. [a] -> a
last [Citation]
ks
  in  [Citation] -> [Citation]
forall a. [a] -> [a]
init [Citation]
ks [Citation] -> [Citation] -> [Citation]
forall a. [a] -> [a] -> [a]
++ [Citation
k {citationSuffix :: [Inline]
citationSuffix = Citation -> [Inline]
citationSuffix Citation
k [Inline] -> [Inline] -> [Inline]
forall a. [a] -> [a] -> [a]
++ [Inline]
s}]
addSuffix _ _ = []

simpleCiteArgs :: PandocMonad m => LP m [Citation]
simpleCiteArgs :: LP m [Citation]
simpleCiteArgs = LP m [Citation] -> LP m [Citation]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (LP m [Citation] -> LP m [Citation])
-> LP m [Citation] -> LP m [Citation]
forall a b. (a -> b) -> a -> b
$ do
  Maybe [Inline]
first  <- ParsecT [Tok] LaTeXState m [Inline]
-> ParsecT [Tok] LaTeXState m (Maybe [Inline])
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe (ParsecT [Tok] LaTeXState m [Inline]
 -> ParsecT [Tok] LaTeXState m (Maybe [Inline]))
-> ParsecT [Tok] LaTeXState m [Inline]
-> ParsecT [Tok] LaTeXState m (Maybe [Inline])
forall a b. (a -> b) -> a -> b
$ Inlines -> [Inline]
forall a. Many a -> [a]
toList (Inlines -> [Inline])
-> ParsecT [Tok] LaTeXState m Inlines
-> ParsecT [Tok] LaTeXState m [Inline]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
opt
  Maybe [Inline]
second <- ParsecT [Tok] LaTeXState m [Inline]
-> ParsecT [Tok] LaTeXState m (Maybe [Inline])
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe (ParsecT [Tok] LaTeXState m [Inline]
 -> ParsecT [Tok] LaTeXState m (Maybe [Inline]))
-> ParsecT [Tok] LaTeXState m [Inline]
-> ParsecT [Tok] LaTeXState m (Maybe [Inline])
forall a b. (a -> b) -> a -> b
$ Inlines -> [Inline]
forall a. Many a -> [a]
toList (Inlines -> [Inline])
-> ParsecT [Tok] LaTeXState m Inlines
-> ParsecT [Tok] LaTeXState m [Inline]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
opt
  [Text]
keys <- ParsecT [Tok] LaTeXState m [Text]
-> ParsecT [Tok] LaTeXState m [Text]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT [Tok] LaTeXState m [Text]
 -> ParsecT [Tok] LaTeXState m [Text])
-> ParsecT [Tok] LaTeXState m [Text]
-> ParsecT [Tok] LaTeXState m [Text]
forall a b. (a -> b) -> a -> b
$ LP m Tok
forall (m :: * -> *). PandocMonad m => LP m Tok
bgroup LP m Tok
-> ParsecT [Tok] LaTeXState m [Text]
-> ParsecT [Tok] LaTeXState m [Text]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT [Tok] LaTeXState m Text
-> LP m Tok -> ParsecT [Tok] LaTeXState m [Text]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ParsecT [Tok] LaTeXState m Text
forall (m :: * -> *). PandocMonad m => LP m Text
citationLabel LP m Tok
forall (m :: * -> *). PandocMonad m => LP m Tok
egroup
  let (pre :: [Inline]
pre, suf :: [Inline]
suf) = case (Maybe [Inline]
first  , Maybe [Inline]
second ) of
        (Just s :: [Inline]
s , Nothing) -> ([Inline]
forall a. Monoid a => a
mempty, [Inline]
s )
        (Just s :: [Inline]
s , Just t :: [Inline]
t ) -> ([Inline]
s , [Inline]
t )
        _                  -> ([Inline]
forall a. Monoid a => a
mempty, [Inline]
forall a. Monoid a => a
mempty)
      conv :: Text -> Citation
conv k :: Text
k = Citation :: Text
-> [Inline] -> [Inline] -> CitationMode -> Int -> Int -> Citation
Citation { citationId :: Text
citationId      = Text
k
                        , citationPrefix :: [Inline]
citationPrefix  = []
                        , citationSuffix :: [Inline]
citationSuffix  = []
                        , citationMode :: CitationMode
citationMode    = CitationMode
NormalCitation
                        , citationHash :: Int
citationHash    = 0
                        , citationNoteNum :: Int
citationNoteNum = 0
                        }
  [Citation] -> LP m [Citation]
forall (m :: * -> *) a. Monad m => a -> m a
return ([Citation] -> LP m [Citation]) -> [Citation] -> LP m [Citation]
forall a b. (a -> b) -> a -> b
$ [Inline] -> [Citation] -> [Citation]
addPrefix [Inline]
pre ([Citation] -> [Citation]) -> [Citation] -> [Citation]
forall a b. (a -> b) -> a -> b
$ [Inline] -> [Citation] -> [Citation]
addSuffix [Inline]
suf ([Citation] -> [Citation]) -> [Citation] -> [Citation]
forall a b. (a -> b) -> a -> b
$ (Text -> Citation) -> [Text] -> [Citation]
forall a b. (a -> b) -> [a] -> [b]
map Text -> Citation
conv [Text]
keys

citationLabel :: PandocMonad m => LP m Text
citationLabel :: LP m Text
citationLabel  = do
  LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
sp
  [Tok] -> Text
untokenize ([Tok] -> Text) -> ParsecT [Tok] LaTeXState m [Tok] -> LP m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
    (ParsecT [Tok] LaTeXState m Tok -> ParsecT [Tok] LaTeXState m [Tok]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ((Tok -> Bool) -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => (Tok -> Bool) -> LP m Tok
satisfyTok Tok -> Bool
isWordTok ParsecT [Tok] LaTeXState m Tok
-> ParsecT [Tok] LaTeXState m Tok -> ParsecT [Tok] LaTeXState m Tok
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> SourceName -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => SourceName -> LP m Tok
symbolIn SourceName
bibtexKeyChar)
          ParsecT [Tok] LaTeXState m [Tok]
-> LP m () -> ParsecT [Tok] LaTeXState m [Tok]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
sp
          ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m (Maybe Tok)
-> ParsecT [Tok] LaTeXState m [Tok]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT [Tok] LaTeXState m Tok
-> ParsecT [Tok] LaTeXState m (Maybe Tok)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Char -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol ',')
          ParsecT [Tok] LaTeXState m [Tok]
-> LP m () -> ParsecT [Tok] LaTeXState m [Tok]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
sp)
  where bibtexKeyChar :: SourceName
bibtexKeyChar = ".:;?!`'()/*@_+=-&[]" :: [Char]

cites :: PandocMonad m => CitationMode -> Bool -> LP m [Citation]
cites :: CitationMode -> Bool -> LP m [Citation]
cites mode :: CitationMode
mode multi :: Bool
multi = LP m [Citation] -> LP m [Citation]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (LP m [Citation] -> LP m [Citation])
-> LP m [Citation] -> LP m [Citation]
forall a b. (a -> b) -> a -> b
$ do
  [[Citation]]
cits <- if Bool
multi
             then do
               Maybe [Inline]
multiprenote <- ParsecT [Tok] LaTeXState m [Inline]
-> ParsecT [Tok] LaTeXState m (Maybe [Inline])
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe (ParsecT [Tok] LaTeXState m [Inline]
 -> ParsecT [Tok] LaTeXState m (Maybe [Inline]))
-> ParsecT [Tok] LaTeXState m [Inline]
-> ParsecT [Tok] LaTeXState m (Maybe [Inline])
forall a b. (a -> b) -> a -> b
$ Inlines -> [Inline]
forall a. Many a -> [a]
toList (Inlines -> [Inline])
-> ParsecT [Tok] LaTeXState m Inlines
-> ParsecT [Tok] LaTeXState m [Inline]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
paropt
               Maybe [Inline]
multipostnote <- ParsecT [Tok] LaTeXState m [Inline]
-> ParsecT [Tok] LaTeXState m (Maybe [Inline])
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m (Maybe a)
optionMaybe (ParsecT [Tok] LaTeXState m [Inline]
 -> ParsecT [Tok] LaTeXState m (Maybe [Inline]))
-> ParsecT [Tok] LaTeXState m [Inline]
-> ParsecT [Tok] LaTeXState m (Maybe [Inline])
forall a b. (a -> b) -> a -> b
$ Inlines -> [Inline]
forall a. Many a -> [a]
toList (Inlines -> [Inline])
-> ParsecT [Tok] LaTeXState m Inlines
-> ParsecT [Tok] LaTeXState m [Inline]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
paropt
               let (pre :: [Inline]
pre, suf :: [Inline]
suf) = case (Maybe [Inline]
multiprenote, Maybe [Inline]
multipostnote) of
                     (Just s :: [Inline]
s , Nothing) -> ([Inline]
forall a. Monoid a => a
mempty, [Inline]
s)
                     (Nothing , Just t :: [Inline]
t) -> ([Inline]
forall a. Monoid a => a
mempty, [Inline]
t)
                     (Just s :: [Inline]
s , Just t :: [Inline]
t ) -> ([Inline]
s, [Inline]
t)
                     _                  -> ([Inline]
forall a. Monoid a => a
mempty, [Inline]
forall a. Monoid a => a
mempty)
               [[Citation]]
tempCits <- LP m [Citation] -> ParsecT [Tok] LaTeXState m [[Citation]]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 LP m [Citation]
forall (m :: * -> *). PandocMonad m => LP m [Citation]
simpleCiteArgs
               case [[Citation]]
tempCits of
                 (k :: [Citation]
k:ks :: [[Citation]]
ks) -> case [[Citation]]
ks of
                             (_:_) -> [[Citation]] -> ParsecT [Tok] LaTeXState m [[Citation]]
forall (m :: * -> *) a. Monad m => a -> m a
return ([[Citation]] -> ParsecT [Tok] LaTeXState m [[Citation]])
-> [[Citation]] -> ParsecT [Tok] LaTeXState m [[Citation]]
forall a b. (a -> b) -> a -> b
$ (([Inline] -> [Citation] -> [Citation]
addMprenote [Inline]
pre [Citation]
k)[Citation] -> [[Citation]] -> [[Citation]]
forall a. a -> [a] -> [a]
:[[Citation]] -> [[Citation]]
forall a. [a] -> [a]
init [[Citation]]
ks) [[Citation]] -> [[Citation]] -> [[Citation]]
forall a. [a] -> [a] -> [a]
++
                                                 [[Inline] -> [Citation] -> [Citation]
addMpostnote [Inline]
suf ([[Citation]] -> [Citation]
forall a. [a] -> a
last [[Citation]]
ks)]
                             _ -> [[Citation]] -> ParsecT [Tok] LaTeXState m [[Citation]]
forall (m :: * -> *) a. Monad m => a -> m a
return [[Inline] -> [Citation] -> [Citation]
addMprenote [Inline]
pre ([Inline] -> [Citation] -> [Citation]
addMpostnote [Inline]
suf [Citation]
k)]
                 _ -> [[Citation]] -> ParsecT [Tok] LaTeXState m [[Citation]]
forall (m :: * -> *) a. Monad m => a -> m a
return [[]]
             else Int -> LP m [Citation] -> ParsecT [Tok] LaTeXState m [[Citation]]
forall s (m :: * -> *) t u a.
Stream s m t =>
Int -> ParsecT s u m a -> ParsecT s u m [a]
count 1 LP m [Citation]
forall (m :: * -> *). PandocMonad m => LP m [Citation]
simpleCiteArgs
  let cs :: [Citation]
cs = [[Citation]] -> [Citation]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[Citation]]
cits
  [Citation] -> LP m [Citation]
forall (m :: * -> *) a. Monad m => a -> m a
return ([Citation] -> LP m [Citation]) -> [Citation] -> LP m [Citation]
forall a b. (a -> b) -> a -> b
$ case CitationMode
mode of
        AuthorInText -> case [Citation]
cs of
                             (c :: Citation
c:rest :: [Citation]
rest) -> Citation
c {citationMode :: CitationMode
citationMode = CitationMode
mode} Citation -> [Citation] -> [Citation]
forall a. a -> [a] -> [a]
: [Citation]
rest
                             []       -> []
        _            -> (Citation -> Citation) -> [Citation] -> [Citation]
forall a b. (a -> b) -> [a] -> [b]
map (\a :: Citation
a -> Citation
a {citationMode :: CitationMode
citationMode = CitationMode
mode}) [Citation]
cs
  where mprenote :: [Inline] -> [Inline]
mprenote (k :: Inline
k:ks :: [Inline]
ks) = (Inline
kInline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
:[Inline]
ks) [Inline] -> [Inline] -> [Inline]
forall a. [a] -> [a] -> [a]
++ [Inline
Space]
        mprenote _ = [Inline]
forall a. Monoid a => a
mempty
        mpostnote :: [Inline] -> [Inline]
mpostnote (k :: Inline
k:ks :: [Inline]
ks) = [Text -> Inline
Str ",", Inline
Space] [Inline] -> [Inline] -> [Inline]
forall a. [a] -> [a] -> [a]
++ (Inline
kInline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
:[Inline]
ks)
        mpostnote _ = [Inline]
forall a. Monoid a => a
mempty
        addMprenote :: [Inline] -> [Citation] -> [Citation]
addMprenote mpn :: [Inline]
mpn (k :: Citation
k:ks :: [Citation]
ks) =
          let mpnfinal :: [Inline]
mpnfinal = case Citation -> [Inline]
citationPrefix Citation
k of
                           (_:_) -> [Inline] -> [Inline]
mprenote [Inline]
mpn
                           _ -> [Inline]
mpn
          in [Inline] -> [Citation] -> [Citation]
addPrefix [Inline]
mpnfinal (Citation
kCitation -> [Citation] -> [Citation]
forall a. a -> [a] -> [a]
:[Citation]
ks)
        addMprenote _ _ = []
        addMpostnote :: [Inline] -> [Citation] -> [Citation]
addMpostnote = [Inline] -> [Citation] -> [Citation]
addSuffix ([Inline] -> [Citation] -> [Citation])
-> ([Inline] -> [Inline]) -> [Inline] -> [Citation] -> [Citation]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inline] -> [Inline]
mpostnote

citation :: PandocMonad m => Text -> CitationMode -> Bool -> LP m Inlines
citation :: Text -> CitationMode -> Bool -> LP m Inlines
citation name :: Text
name mode :: CitationMode
mode multi :: Bool
multi = do
  (c :: [Citation]
c,raw :: [Tok]
raw) <- LP m [Citation] -> LP m ([Citation], [Tok])
forall (m :: * -> *) a. PandocMonad m => LP m a -> LP m (a, [Tok])
withRaw (LP m [Citation] -> LP m ([Citation], [Tok]))
-> LP m [Citation] -> LP m ([Citation], [Tok])
forall a b. (a -> b) -> a -> b
$ CitationMode -> Bool -> LP m [Citation]
forall (m :: * -> *).
PandocMonad m =>
CitationMode -> Bool -> LP m [Citation]
cites CitationMode
mode Bool
multi
  Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> LP m Inlines) -> Inlines -> LP m Inlines
forall a b. (a -> b) -> a -> b
$ [Citation] -> Inlines -> Inlines
cite [Citation]
c (Text -> Text -> Inlines
rawInline "latex" (Text -> Inlines) -> Text -> Inlines
forall a b. (a -> b) -> a -> b
$ "\\" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
name Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> [Tok] -> Text
untokenize [Tok]
raw)

handleCitationPart :: Inlines -> [Citation]
handleCitationPart :: Inlines -> [Citation]
handleCitationPart ils :: Inlines
ils =
  let isCite :: Inline -> Bool
isCite Cite{} = Bool
True
      isCite _      = Bool
False
      (pref :: [Inline]
pref, rest :: [Inline]
rest) = (Inline -> Bool) -> [Inline] -> ([Inline], [Inline])
forall a. (a -> Bool) -> [a] -> ([a], [a])
break Inline -> Bool
isCite (Inlines -> [Inline]
forall a. Many a -> [a]
toList Inlines
ils)
  in case [Inline]
rest of
          (Cite cs :: [Citation]
cs _:suff :: [Inline]
suff) -> [Inline] -> [Citation] -> [Citation]
addPrefix [Inline]
pref ([Citation] -> [Citation]) -> [Citation] -> [Citation]
forall a b. (a -> b) -> a -> b
$ [Inline] -> [Citation] -> [Citation]
addSuffix [Inline]
suff [Citation]
cs
          _                -> []

complexNatbibCitation :: PandocMonad m => CitationMode -> LP m Inlines
complexNatbibCitation :: CitationMode -> LP m Inlines
complexNatbibCitation mode :: CitationMode
mode = LP m Inlines -> LP m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (LP m Inlines -> LP m Inlines) -> LP m Inlines -> LP m Inlines
forall a b. (a -> b) -> a -> b
$ do
  (cs :: [Citation]
cs, raw :: [Tok]
raw) <-
    LP m [Citation] -> LP m ([Citation], [Tok])
forall (m :: * -> *) a. PandocMonad m => LP m a -> LP m (a, [Tok])
withRaw (LP m [Citation] -> LP m ([Citation], [Tok]))
-> LP m [Citation] -> LP m ([Citation], [Tok])
forall a b. (a -> b) -> a -> b
$ [[Citation]] -> [Citation]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[Citation]] -> [Citation])
-> ParsecT [Tok] LaTeXState m [[Citation]] -> LP m [Citation]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> do
      LP m Tok
forall (m :: * -> *). PandocMonad m => LP m Tok
bgroup
      [Inlines]
items <- [[Inlines]] -> [Inlines]
forall a. Monoid a => [a] -> a
mconcat ([[Inlines]] -> [Inlines])
-> ParsecT [Tok] LaTeXState m [[Inlines]]
-> ParsecT [Tok] LaTeXState m [Inlines]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
                LP m Inlines -> ParsecT [Tok] LaTeXState m [Inlines]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (LP m Tok -> ParsecT [Tok] LaTeXState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (Char -> LP m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol ';') ParsecT [Tok] LaTeXState m () -> LP m Inlines -> LP m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
inline)
                  ParsecT [Tok] LaTeXState m [Inlines]
-> LP m Tok -> ParsecT [Tok] LaTeXState m [[Inlines]]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
`sepBy1` (Char -> LP m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol ';')
      LP m Tok
forall (m :: * -> *). PandocMonad m => LP m Tok
egroup
      [[Citation]] -> ParsecT [Tok] LaTeXState m [[Citation]]
forall (m :: * -> *) a. Monad m => a -> m a
return ([[Citation]] -> ParsecT [Tok] LaTeXState m [[Citation]])
-> [[Citation]] -> ParsecT [Tok] LaTeXState m [[Citation]]
forall a b. (a -> b) -> a -> b
$ (Inlines -> [Citation]) -> [Inlines] -> [[Citation]]
forall a b. (a -> b) -> [a] -> [b]
map Inlines -> [Citation]
handleCitationPart [Inlines]
items
  case [Citation]
cs of
       []       -> LP m Inlines
forall (m :: * -> *) a. MonadPlus m => m a
mzero
       (c :: Citation
c:cits :: [Citation]
cits) -> Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> LP m Inlines) -> Inlines -> LP m Inlines
forall a b. (a -> b) -> a -> b
$ [Citation] -> Inlines -> Inlines
cite (Citation
c{ citationMode :: CitationMode
citationMode = CitationMode
mode }Citation -> [Citation] -> [Citation]
forall a. a -> [a] -> [a]
:[Citation]
cits)
                      (Text -> Text -> Inlines
rawInline "latex" (Text -> Inlines) -> Text -> Inlines
forall a b. (a -> b) -> a -> b
$ "\\citetext" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> [Tok] -> Text
untokenize [Tok]
raw)

inNote :: Inlines -> Inlines
inNote :: Inlines -> Inlines
inNote ils :: Inlines
ils =
  Blocks -> Inlines
note (Blocks -> Inlines) -> Blocks -> Inlines
forall a b. (a -> b) -> a -> b
$ Inlines -> Blocks
para (Inlines -> Blocks) -> Inlines -> Blocks
forall a b. (a -> b) -> a -> b
$ Inlines
ils Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Text -> Inlines
str "."

inlineCommand' :: PandocMonad m => LP m Inlines
inlineCommand' :: LP m Inlines
inlineCommand' = LP m Inlines -> LP m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (LP m Inlines -> LP m Inlines) -> LP m Inlines -> LP m Inlines
forall a b. (a -> b) -> a -> b
$ do
  Tok _ (CtrlSeq name :: Text
name) cmd :: Text
cmd <- LP m Tok
forall (m :: * -> *). PandocMonad m => LP m Tok
anyControlSeq
  Bool -> ParsecT [Tok] LaTeXState m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT [Tok] LaTeXState m ())
-> Bool -> ParsecT [Tok] LaTeXState m ()
forall a b. (a -> b) -> a -> b
$ Text
name Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
/= "begin" Bool -> Bool -> Bool
&& Text
name Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
/= "end"
  Text
star <- Text
-> ParsecT [Tok] LaTeXState m Text
-> ParsecT [Tok] LaTeXState m Text
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option "" ("*" Text -> LP m Tok -> ParsecT [Tok] LaTeXState m Text
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> LP m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '*' ParsecT [Tok] LaTeXState m Text
-> ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
sp)
  Text
overlay <- Text
-> ParsecT [Tok] LaTeXState m Text
-> ParsecT [Tok] LaTeXState m Text
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option "" ParsecT [Tok] LaTeXState m Text
forall (m :: * -> *). PandocMonad m => LP m Text
overlaySpecification
  let name' :: Text
name' = Text
name Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
star Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
overlay
  let names :: [Text]
names = [Text] -> [Text]
forall a. Ord a => [a] -> [a]
ordNub [Text
name', Text
name] -- check non-starred as fallback
  let raw :: LP m Inlines
raw = do
       Bool -> ParsecT [Tok] LaTeXState m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT [Tok] LaTeXState m ())
-> Bool -> ParsecT [Tok] LaTeXState m ()
forall a b. (a -> b) -> a -> b
$ Text -> Bool
isInlineCommand Text
name Bool -> Bool -> Bool
|| Bool -> Bool
not (Text -> Bool
isBlockCommand Text
name)
       Text
rawcommand <- Text -> Text -> ParsecT [Tok] LaTeXState m Text
forall (m :: * -> *). PandocMonad m => Text -> Text -> LP m Text
getRawCommand Text
name (Text
cmd Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
star)
       (Extension -> ParsecT [Tok] LaTeXState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParserT s st m ()
guardEnabled Extension
Ext_raw_tex ParsecT [Tok] LaTeXState m () -> LP m Inlines -> LP m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> Text -> Inlines
rawInline "latex" Text
rawcommand))
         LP m Inlines -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Text -> LP m Inlines
forall a (m :: * -> *) s u.
(Monoid a, PandocMonad m) =>
Text -> ParserT s u m a
ignore Text
rawcommand
  LP m Inlines -> [Text] -> Map Text (LP m Inlines) -> LP m Inlines
forall k v. Ord k => v -> [k] -> Map k v -> v
lookupListDefault LP m Inlines
raw [Text]
names Map Text (LP m Inlines)
forall (m :: * -> *). PandocMonad m => Map Text (LP m Inlines)
inlineCommands

tok :: PandocMonad m => LP m Inlines
tok :: LP m Inlines
tok = LP m Inlines -> LP m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (LP m Inlines -> LP m Inlines) -> LP m Inlines -> LP m Inlines
forall a b. (a -> b) -> a -> b
$ LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces LP m () -> LP m Inlines -> LP m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> LP m Inlines -> LP m Inlines
forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
grouped LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
inline LP m Inlines -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
inlineCommand' LP m Inlines -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> LP m Inlines
singleChar'
  where singleChar' :: LP m Inlines
singleChar' = do
          Tok _ _ t :: Text
t <- LP m Tok
forall (m :: * -> *). PandocMonad m => LP m Tok
singleChar
          Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> LP m Inlines) -> Inlines -> LP m Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
str Text
t

opt :: PandocMonad m => LP m Inlines
opt :: LP m Inlines
opt = LP m Inlines -> LP m Inlines
forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
bracketed LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
inline LP m Inlines -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Text -> Inlines
str (Text -> Inlines)
-> ParsecT [Tok] LaTeXState m Text -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m Text
forall (m :: * -> *). PandocMonad m => LP m Text
rawopt)

paropt :: PandocMonad m => LP m Inlines
paropt :: LP m Inlines
paropt = LP m Inlines -> LP m Inlines
forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
parenWrapped LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
inline

rawopt :: PandocMonad m => LP m Text
rawopt :: LP m Text
rawopt = LP m Text -> LP m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (LP m Text -> LP m Text) -> LP m Text -> LP m Text
forall a b. (a -> b) -> a -> b
$ do
  LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
sp
  Text
inner <- [Tok] -> Text
untokenize ([Tok] -> Text) -> ParsecT [Tok] LaTeXState m [Tok] -> LP m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
bracketedToks
  LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
sp
  Text -> LP m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> LP m Text) -> Text -> LP m Text
forall a b. (a -> b) -> a -> b
$ "[" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
inner Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> "]"

skipopts :: PandocMonad m => LP m ()
skipopts :: LP m ()
skipopts = LP m () -> LP m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany (ParsecT [Tok] LaTeXState m Text -> LP m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void ParsecT [Tok] LaTeXState m Text
forall (m :: * -> *). PandocMonad m => LP m Text
overlaySpecification LP m () -> LP m () -> LP m ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ParsecT [Tok] LaTeXState m Text -> LP m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void ParsecT [Tok] LaTeXState m Text
forall (m :: * -> *). PandocMonad m => LP m Text
rawopt)

-- opts in angle brackets are used in beamer
overlaySpecification :: PandocMonad m => LP m Text
overlaySpecification :: LP m Text
overlaySpecification = LP m Text -> LP m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (LP m Text -> LP m Text) -> LP m Text -> LP m Text
forall a b. (a -> b) -> a -> b
$ do
  Char -> LP m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '<'
  Text
t <- [Tok] -> Text
untokenize ([Tok] -> Text) -> ParsecT [Tok] LaTeXState m [Tok] -> LP m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Tok -> LP m Tok -> ParsecT [Tok] LaTeXState m [Tok]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill LP m Tok
forall (m :: * -> *). PandocMonad m => LP m Tok
overlayTok (Char -> LP m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '>')
  -- see issue #3368
  Bool -> ParsecT [Tok] LaTeXState m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT [Tok] LaTeXState m ())
-> Bool -> ParsecT [Tok] LaTeXState m ()
forall a b. (a -> b) -> a -> b
$ Bool -> Bool
not ((Char -> Bool) -> Text -> Bool
T.all Char -> Bool
isLetter Text
t) Bool -> Bool -> Bool
||
          Text
t Text -> [Text] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` ["beamer","presentation", "trans",
                    "handout","article", "second"]
  Text -> LP m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> LP m Text) -> Text -> LP m Text
forall a b. (a -> b) -> a -> b
$ "<" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
t Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> ">"

overlayTok :: PandocMonad m => LP m Tok
overlayTok :: LP m Tok
overlayTok =
  (Tok -> Bool) -> LP m Tok
forall (m :: * -> *). PandocMonad m => (Tok -> Bool) -> LP m Tok
satisfyTok (\t :: Tok
t ->
                  case Tok
t of
                    Tok _ Word _       -> Bool
True
                    Tok _ Spaces _     -> Bool
True
                    Tok _ Symbol c :: Text
c     -> Text
c Text -> [Text] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` ["-","+","@","|",":",","]
                    _                  -> Bool
False)

inBrackets :: Inlines -> Inlines
inBrackets :: Inlines -> Inlines
inBrackets x :: Inlines
x = Text -> Inlines
str "[" Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
x Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Text -> Inlines
str "]"

unescapeURL :: Text -> Text
unescapeURL :: Text -> Text
unescapeURL = [Text] -> Text
T.concat ([Text] -> Text) -> (Text -> [Text]) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Text] -> [Text]
go ([Text] -> [Text]) -> (Text -> [Text]) -> Text -> [Text]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> [Text]
T.splitOn "\\"
  where
    isEscapable :: Char -> Bool
isEscapable c :: Char
c = Char
c Char -> Text -> Bool
`elemText` "#$%&~_^\\{}"
    go :: [Text] -> [Text]
go (x :: Text
x:xs :: [Text]
xs) = Text
x Text -> [Text] -> [Text]
forall a. a -> [a] -> [a]
: (Text -> Text) -> [Text] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map Text -> Text
unescapeInterior [Text]
xs
    go []     = []
    unescapeInterior :: Text -> Text
unescapeInterior t :: Text
t
      | Just (c :: Char
c, _) <- Text -> Maybe (Char, Text)
T.uncons Text
t
      , Char -> Bool
isEscapable Char
c = Text
t
      | Bool
otherwise = "\\" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
t

mathEnvWith :: PandocMonad m
            => (Inlines -> a) -> Maybe Text -> Text -> LP m a
mathEnvWith :: (Inlines -> a) -> Maybe Text -> Text -> LP m a
mathEnvWith f :: Inlines -> a
f innerEnv :: Maybe Text
innerEnv name :: Text
name = Inlines -> a
f (Inlines -> a) -> (Text -> Inlines) -> Text -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Inlines
mathDisplay (Text -> Inlines) -> (Text -> Text) -> Text -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
inner (Text -> a) -> ParsecT [Tok] LaTeXState m Text -> LP m a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> ParsecT [Tok] LaTeXState m Text
forall (m :: * -> *). PandocMonad m => Text -> LP m Text
mathEnv Text
name
   where inner :: Text -> Text
inner x :: Text
x = case Maybe Text
innerEnv of
                        Nothing -> Text
x
                        Just y :: Text
y  -> "\\begin{" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
y Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> "}\n" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
x Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
                                   "\\end{" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
y Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> "}"

mathEnv :: PandocMonad m => Text -> LP m Text
mathEnv :: Text -> LP m Text
mathEnv name :: Text
name = do
  LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts
  LP m () -> ParsecT [Tok] LaTeXState m (Maybe ())
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
blankline
  [Tok]
res <- ParsecT [Tok] LaTeXState m Tok
-> LP m () -> ParsecT [Tok] LaTeXState m [Tok]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => LP m Tok
anyTok (Text -> LP m ()
forall (m :: * -> *). PandocMonad m => Text -> LP m ()
end_ Text
name)
  Text -> LP m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> LP m Text) -> Text -> LP m Text
forall a b. (a -> b) -> a -> b
$ Text -> Text
stripTrailingNewlines (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ [Tok] -> Text
untokenize [Tok]
res

inlineEnvironment :: PandocMonad m => LP m Inlines
inlineEnvironment :: LP m Inlines
inlineEnvironment = LP m Inlines -> LP m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (LP m Inlines -> LP m Inlines) -> LP m Inlines -> LP m Inlines
forall a b. (a -> b) -> a -> b
$ do
  Text -> LP m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "begin"
  Text
name <- [Tok] -> Text
untokenize ([Tok] -> Text)
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
  LP m Inlines -> Text -> Map Text (LP m Inlines) -> LP m Inlines
forall k a. Ord k => a -> k -> Map k a -> a
M.findWithDefault LP m Inlines
forall (m :: * -> *) a. MonadPlus m => m a
mzero Text
name Map Text (LP m Inlines)
forall (m :: * -> *). PandocMonad m => Map Text (LP m Inlines)
inlineEnvironments

inlineEnvironments :: PandocMonad m => M.Map Text (LP m Inlines)
inlineEnvironments :: Map Text (LP m Inlines)
inlineEnvironments = [(Text, LP m Inlines)] -> Map Text (LP m Inlines)
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [
    ("displaymath", (Inlines -> Inlines) -> Maybe Text -> Text -> LP m Inlines
forall (m :: * -> *) a.
PandocMonad m =>
(Inlines -> a) -> Maybe Text -> Text -> LP m a
mathEnvWith Inlines -> Inlines
forall a. a -> a
id Maybe Text
forall a. Maybe a
Nothing "displaymath")
  , ("math", Text -> Inlines
math (Text -> Inlines)
-> ParsecT [Tok] LaTeXState m Text -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> ParsecT [Tok] LaTeXState m Text
forall (m :: * -> *). PandocMonad m => Text -> LP m Text
mathEnv "math")
  , ("equation", (Inlines -> Inlines) -> Maybe Text -> Text -> LP m Inlines
forall (m :: * -> *) a.
PandocMonad m =>
(Inlines -> a) -> Maybe Text -> Text -> LP m a
mathEnvWith Inlines -> Inlines
forall a. a -> a
id Maybe Text
forall a. Maybe a
Nothing "equation")
  , ("equation*", (Inlines -> Inlines) -> Maybe Text -> Text -> LP m Inlines
forall (m :: * -> *) a.
PandocMonad m =>
(Inlines -> a) -> Maybe Text -> Text -> LP m a
mathEnvWith Inlines -> Inlines
forall a. a -> a
id Maybe Text
forall a. Maybe a
Nothing "equation*")
  , ("gather", (Inlines -> Inlines) -> Maybe Text -> Text -> LP m Inlines
forall (m :: * -> *) a.
PandocMonad m =>
(Inlines -> a) -> Maybe Text -> Text -> LP m a
mathEnvWith Inlines -> Inlines
forall a. a -> a
id (Text -> Maybe Text
forall a. a -> Maybe a
Just "gathered") "gather")
  , ("gather*", (Inlines -> Inlines) -> Maybe Text -> Text -> LP m Inlines
forall (m :: * -> *) a.
PandocMonad m =>
(Inlines -> a) -> Maybe Text -> Text -> LP m a
mathEnvWith Inlines -> Inlines
forall a. a -> a
id (Text -> Maybe Text
forall a. a -> Maybe a
Just "gathered") "gather*")
  , ("multline", (Inlines -> Inlines) -> Maybe Text -> Text -> LP m Inlines
forall (m :: * -> *) a.
PandocMonad m =>
(Inlines -> a) -> Maybe Text -> Text -> LP m a
mathEnvWith Inlines -> Inlines
forall a. a -> a
id (Text -> Maybe Text
forall a. a -> Maybe a
Just "gathered") "multline")
  , ("multline*", (Inlines -> Inlines) -> Maybe Text -> Text -> LP m Inlines
forall (m :: * -> *) a.
PandocMonad m =>
(Inlines -> a) -> Maybe Text -> Text -> LP m a
mathEnvWith Inlines -> Inlines
forall a. a -> a
id (Text -> Maybe Text
forall a. a -> Maybe a
Just "gathered") "multline*")
  , ("eqnarray", (Inlines -> Inlines) -> Maybe Text -> Text -> LP m Inlines
forall (m :: * -> *) a.
PandocMonad m =>
(Inlines -> a) -> Maybe Text -> Text -> LP m a
mathEnvWith Inlines -> Inlines
forall a. a -> a
id (Text -> Maybe Text
forall a. a -> Maybe a
Just "aligned") "eqnarray")
  , ("eqnarray*", (Inlines -> Inlines) -> Maybe Text -> Text -> LP m Inlines
forall (m :: * -> *) a.
PandocMonad m =>
(Inlines -> a) -> Maybe Text -> Text -> LP m a
mathEnvWith Inlines -> Inlines
forall a. a -> a
id (Text -> Maybe Text
forall a. a -> Maybe a
Just "aligned") "eqnarray*")
  , ("align", (Inlines -> Inlines) -> Maybe Text -> Text -> LP m Inlines
forall (m :: * -> *) a.
PandocMonad m =>
(Inlines -> a) -> Maybe Text -> Text -> LP m a
mathEnvWith Inlines -> Inlines
forall a. a -> a
id (Text -> Maybe Text
forall a. a -> Maybe a
Just "aligned") "align")
  , ("align*", (Inlines -> Inlines) -> Maybe Text -> Text -> LP m Inlines
forall (m :: * -> *) a.
PandocMonad m =>
(Inlines -> a) -> Maybe Text -> Text -> LP m a
mathEnvWith Inlines -> Inlines
forall a. a -> a
id (Text -> Maybe Text
forall a. a -> Maybe a
Just "aligned") "align*")
  , ("alignat", (Inlines -> Inlines) -> Maybe Text -> Text -> LP m Inlines
forall (m :: * -> *) a.
PandocMonad m =>
(Inlines -> a) -> Maybe Text -> Text -> LP m a
mathEnvWith Inlines -> Inlines
forall a. a -> a
id (Text -> Maybe Text
forall a. a -> Maybe a
Just "aligned") "alignat")
  , ("alignat*", (Inlines -> Inlines) -> Maybe Text -> Text -> LP m Inlines
forall (m :: * -> *) a.
PandocMonad m =>
(Inlines -> a) -> Maybe Text -> Text -> LP m a
mathEnvWith Inlines -> Inlines
forall a. a -> a
id (Text -> Maybe Text
forall a. a -> Maybe a
Just "aligned") "alignat*")
  , ("dmath", (Inlines -> Inlines) -> Maybe Text -> Text -> LP m Inlines
forall (m :: * -> *) a.
PandocMonad m =>
(Inlines -> a) -> Maybe Text -> Text -> LP m a
mathEnvWith Inlines -> Inlines
forall a. a -> a
id Maybe Text
forall a. Maybe a
Nothing "dmath")
  , ("dmath*", (Inlines -> Inlines) -> Maybe Text -> Text -> LP m Inlines
forall (m :: * -> *) a.
PandocMonad m =>
(Inlines -> a) -> Maybe Text -> Text -> LP m a
mathEnvWith Inlines -> Inlines
forall a. a -> a
id Maybe Text
forall a. Maybe a
Nothing "dmath*")
  , ("dgroup", (Inlines -> Inlines) -> Maybe Text -> Text -> LP m Inlines
forall (m :: * -> *) a.
PandocMonad m =>
(Inlines -> a) -> Maybe Text -> Text -> LP m a
mathEnvWith Inlines -> Inlines
forall a. a -> a
id (Text -> Maybe Text
forall a. a -> Maybe a
Just "aligned") "dgroup")
  , ("dgroup*", (Inlines -> Inlines) -> Maybe Text -> Text -> LP m Inlines
forall (m :: * -> *) a.
PandocMonad m =>
(Inlines -> a) -> Maybe Text -> Text -> LP m a
mathEnvWith Inlines -> Inlines
forall a. a -> a
id (Text -> Maybe Text
forall a. a -> Maybe a
Just "aligned") "dgroup*")
  , ("darray", (Inlines -> Inlines) -> Maybe Text -> Text -> LP m Inlines
forall (m :: * -> *) a.
PandocMonad m =>
(Inlines -> a) -> Maybe Text -> Text -> LP m a
mathEnvWith Inlines -> Inlines
forall a. a -> a
id (Text -> Maybe Text
forall a. a -> Maybe a
Just "aligned") "darray")
  , ("darray*", (Inlines -> Inlines) -> Maybe Text -> Text -> LP m Inlines
forall (m :: * -> *) a.
PandocMonad m =>
(Inlines -> a) -> Maybe Text -> Text -> LP m a
mathEnvWith Inlines -> Inlines
forall a. a -> a
id (Text -> Maybe Text
forall a. a -> Maybe a
Just "aligned") "darray*")
  ]

inlineCommands :: PandocMonad m => M.Map Text (LP m Inlines)
inlineCommands :: Map Text (LP m Inlines)
inlineCommands = Map Text (LP m Inlines)
-> Map Text (LP m Inlines) -> Map Text (LP m Inlines)
forall k a. Ord k => Map k a -> Map k a -> Map k a
M.union Map Text (LP m Inlines)
forall (m :: * -> *). PandocMonad m => Map Text (LP m Inlines)
inlineLanguageCommands (Map Text (LP m Inlines) -> Map Text (LP m Inlines))
-> Map Text (LP m Inlines) -> Map Text (LP m Inlines)
forall a b. (a -> b) -> a -> b
$ [(Text, LP m Inlines)] -> Map Text (LP m Inlines)
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList
  [ ("emph", (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces Inlines -> Inlines
emph (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
  , ("textit", (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces Inlines -> Inlines
emph (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
  , ("textsl", (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces Inlines -> Inlines
emph (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
  , ("textsc", (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces Inlines -> Inlines
smallcaps (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
  , ("textsf", (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces (Attr -> Inlines -> Inlines
spanWith ("",["sans-serif"],[])) (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
  , ("textmd", (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces (Attr -> Inlines -> Inlines
spanWith ("",["medium"],[])) (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
  , ("textrm", (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces (Attr -> Inlines -> Inlines
spanWith ("",["roman"],[])) (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
  , ("textup", (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces (Attr -> Inlines -> Inlines
spanWith ("",["upright"],[])) (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
  , ("texttt", LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
ttfamily)
  , ("sout", (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces Inlines -> Inlines
strikeout (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
  , ("alert", LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts LP m () -> LP m Inlines -> LP m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Attr -> Inlines -> Inlines
spanWith ("",["alert"],[]) (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok) -- beamer
  , ("lq", Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> Inlines
str "‘"))
  , ("rq", Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> Inlines
str "’"))
  , ("textquoteleft", Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> Inlines
str "‘"))
  , ("textquoteright", Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> Inlines
str "’"))
  , ("textquotedblleft", Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> Inlines
str "“"))
  , ("textquotedblright", Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> Inlines
str "”"))
  , ("textsuperscript", (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces Inlines -> Inlines
superscript (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
  , ("textsubscript", (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces Inlines -> Inlines
subscript (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
  , ("textbackslash", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "\\")
  , ("backslash", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "\\")
  , ("slash", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "/")
  , ("textbf", (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces Inlines -> Inlines
strong (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
  , ("textnormal", (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces (Attr -> Inlines -> Inlines
spanWith ("",["nodecor"],[])) (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
  , ("underline", Inlines -> Inlines
underlineSpan (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
  , ("ldots", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "…")
  , ("vdots", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "\8942")
  , ("dots", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "…")
  , ("mdots", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "…")
  , ("sim", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "~")
  , ("sep", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit ",")
  , ("label", Text -> LP m Inlines -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> LP m Inlines -> LP m Inlines
rawInlineOr "label" LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
dolabel)
  , ("ref", Text -> LP m Inlines -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> LP m Inlines -> LP m Inlines
rawInlineOr "ref" (LP m Inlines -> LP m Inlines) -> LP m Inlines -> LP m Inlines
forall a b. (a -> b) -> a -> b
$ Text -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Text -> LP m Inlines
doref "ref")
  , ("cref", Text -> LP m Inlines -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> LP m Inlines -> LP m Inlines
rawInlineOr "cref" (LP m Inlines -> LP m Inlines) -> LP m Inlines -> LP m Inlines
forall a b. (a -> b) -> a -> b
$ Text -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Text -> LP m Inlines
doref "ref")       -- from cleveref.sty
  , ("vref", Text -> LP m Inlines -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> LP m Inlines -> LP m Inlines
rawInlineOr "vref" (LP m Inlines -> LP m Inlines) -> LP m Inlines -> LP m Inlines
forall a b. (a -> b) -> a -> b
$ Text -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Text -> LP m Inlines
doref "ref+page")  -- from varioref.sty
  , ("eqref", Text -> LP m Inlines -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> LP m Inlines -> LP m Inlines
rawInlineOr "eqref" (LP m Inlines -> LP m Inlines) -> LP m Inlines -> LP m Inlines
forall a b. (a -> b) -> a -> b
$ Text -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Text -> LP m Inlines
doref "eqref")   -- from amsmath.sty
  , ("mbox", Text -> LP m Inlines -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> LP m Inlines -> LP m Inlines
rawInlineOr "mbox" (LP m Inlines -> LP m Inlines) -> LP m Inlines -> LP m Inlines
forall a b. (a -> b) -> a -> b
$ Inlines -> Inlines
processHBox (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
  , ("hbox", Text -> LP m Inlines -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> LP m Inlines -> LP m Inlines
rawInlineOr "hbox" (LP m Inlines -> LP m Inlines) -> LP m Inlines -> LP m Inlines
forall a b. (a -> b) -> a -> b
$ Inlines -> Inlines
processHBox (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
  , ("lettrine", LP m Inlines -> ParsecT [Tok] LaTeXState m (Maybe Inlines)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
opt ParsecT [Tok] LaTeXState m (Maybe Inlines)
-> LP m Inlines -> LP m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces (Attr -> Inlines -> Inlines
spanWith ("",["lettrine"],[])) (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
  , ("(", Text -> Inlines
mathInline (Text -> Inlines) -> ([Tok] -> Text) -> [Tok] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize ([Tok] -> Inlines)
-> ParsecT [Tok] LaTeXState m [Tok] -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m Tok
-> ParsecT [Tok] LaTeXState m Tok
-> ParsecT [Tok] LaTeXState m [Tok]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => LP m Tok
anyTok (Text -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq ")"))
  , ("[", Text -> Inlines
mathDisplay (Text -> Inlines) -> ([Tok] -> Text) -> [Tok] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize ([Tok] -> Inlines)
-> ParsecT [Tok] LaTeXState m [Tok] -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m Tok
-> ParsecT [Tok] LaTeXState m Tok
-> ParsecT [Tok] LaTeXState m [Tok]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => LP m Tok
anyTok (Text -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "]"))
  , ("ensuremath", Text -> Inlines
mathInline (Text -> Inlines) -> ([Tok] -> Text) -> [Tok] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize ([Tok] -> Inlines)
-> ParsecT [Tok] LaTeXState m [Tok] -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced)
  , ("texorpdfstring", Inlines -> Inlines -> Inlines
forall a b. a -> b -> a
const (Inlines -> Inlines -> Inlines)
-> LP m Inlines -> ParsecT [Tok] LaTeXState m (Inlines -> Inlines)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok ParsecT [Tok] LaTeXState m (Inlines -> Inlines)
-> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
  , ("P", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "¶")
  , ("S", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "§")
  , ("$", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "$")
  , ("%", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "%")
  , ("&", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "&")
  , ("#", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "#")
  , ("_", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "_")
  , ("{", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "{")
  , ("}", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "}")
  -- old TeX commands
  , ("em", (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces Inlines -> Inlines
emph (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
inlines)
  , ("it", (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces Inlines -> Inlines
emph (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
inlines)
  , ("sl", (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces Inlines -> Inlines
emph (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
inlines)
  , ("bf", (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces Inlines -> Inlines
strong (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
inlines)
  , ("tt", Text -> Inlines
code (Text -> Inlines) -> (Inlines -> Text) -> Inlines -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inline] -> Text
forall a. Walkable Inline a => a -> Text
stringify ([Inline] -> Text) -> (Inlines -> [Inline]) -> Inlines -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> [Inline]
forall a. Many a -> [a]
toList (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
inlines)
  , ("rm", LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
inlines)
  , ("itshape", (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces Inlines -> Inlines
emph (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
inlines)
  , ("slshape", (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces Inlines -> Inlines
emph (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
inlines)
  , ("scshape", (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces Inlines -> Inlines
smallcaps (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
inlines)
  , ("bfseries", (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces Inlines -> Inlines
strong (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
inlines)
  , ("MakeUppercase", Inlines -> Inlines
makeUppercase (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
  , ("MakeTextUppercase", Inlines -> Inlines
makeUppercase (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok) -- textcase
  , ("uppercase", Inlines -> Inlines
makeUppercase (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
  , ("MakeLowercase", Inlines -> Inlines
makeLowercase (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
  , ("MakeTextLowercase", Inlines -> Inlines
makeLowercase (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
  , ("lowercase", Inlines -> Inlines
makeLowercase (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
  , ("/", Inlines -> LP m Inlines
forall (f :: * -> *) a. Applicative f => a -> f a
pure Inlines
forall a. Monoid a => a
mempty) -- italic correction
  , ("aa", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "å")
  , ("AA", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "Å")
  , ("ss", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "ß")
  , ("o", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "ø")
  , ("O", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "Ø")
  , ("L", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "Ł")
  , ("l", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "ł")
  , ("ae", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "æ")
  , ("AE", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "Æ")
  , ("oe", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "œ")
  , ("OE", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "Œ")
  , ("pounds", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "£")
  , ("euro", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "€")
  , ("copyright", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "©")
  , ("textasciicircum", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "^")
  , ("textasciitilde", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "~")
  , ("H", Char -> Maybe Char -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Char -> Maybe Char -> LP m Inlines
accent '\779' Maybe Char
forall a. Maybe a
Nothing) -- hungarumlaut
  , ("`", Char -> Maybe Char -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Char -> Maybe Char -> LP m Inlines
accent '\768' (Char -> Maybe Char
forall a. a -> Maybe a
Just '`')) -- grave
  , ("'", Char -> Maybe Char -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Char -> Maybe Char -> LP m Inlines
accent '\769' (Char -> Maybe Char
forall a. a -> Maybe a
Just '\'')) -- acute
  , ("^", Char -> Maybe Char -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Char -> Maybe Char -> LP m Inlines
accent '\770' (Char -> Maybe Char
forall a. a -> Maybe a
Just '^')) -- circ
  , ("~", Char -> Maybe Char -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Char -> Maybe Char -> LP m Inlines
accent '\771' (Char -> Maybe Char
forall a. a -> Maybe a
Just '~')) -- tilde
  , ("\"", Char -> Maybe Char -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Char -> Maybe Char -> LP m Inlines
accent '\776' Maybe Char
forall a. Maybe a
Nothing) -- umlaut
  , (".", Char -> Maybe Char -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Char -> Maybe Char -> LP m Inlines
accent '\775' Maybe Char
forall a. Maybe a
Nothing) -- dot
  , ("=", Char -> Maybe Char -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Char -> Maybe Char -> LP m Inlines
accent '\772' Maybe Char
forall a. Maybe a
Nothing) -- macron
  , ("|", Char -> Maybe Char -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Char -> Maybe Char -> LP m Inlines
accent '\781' Maybe Char
forall a. Maybe a
Nothing) -- vertical line above
  , ("b", Char -> Maybe Char -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Char -> Maybe Char -> LP m Inlines
accent '\817' Maybe Char
forall a. Maybe a
Nothing) -- macron below
  , ("c", Char -> Maybe Char -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Char -> Maybe Char -> LP m Inlines
accent '\807' Maybe Char
forall a. Maybe a
Nothing) -- cedilla
  , ("G", Char -> Maybe Char -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Char -> Maybe Char -> LP m Inlines
accent '\783' Maybe Char
forall a. Maybe a
Nothing) -- doublegrave
  , ("h", Char -> Maybe Char -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Char -> Maybe Char -> LP m Inlines
accent '\777' Maybe Char
forall a. Maybe a
Nothing) -- hookabove
  , ("d", Char -> Maybe Char -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Char -> Maybe Char -> LP m Inlines
accent '\803' Maybe Char
forall a. Maybe a
Nothing) -- dotbelow
  , ("f", Char -> Maybe Char -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Char -> Maybe Char -> LP m Inlines
accent '\785' Maybe Char
forall a. Maybe a
Nothing)  -- inverted breve
  , ("r", Char -> Maybe Char -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Char -> Maybe Char -> LP m Inlines
accent '\778' Maybe Char
forall a. Maybe a
Nothing)  -- ringabove
  , ("t", Char -> Maybe Char -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Char -> Maybe Char -> LP m Inlines
accent '\865' Maybe Char
forall a. Maybe a
Nothing)  -- double inverted breve
  , ("U", Char -> Maybe Char -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Char -> Maybe Char -> LP m Inlines
accent '\782' Maybe Char
forall a. Maybe a
Nothing)  -- double vertical line above
  , ("v", Char -> Maybe Char -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Char -> Maybe Char -> LP m Inlines
accent '\780' Maybe Char
forall a. Maybe a
Nothing) -- hacek
  , ("u", Char -> Maybe Char -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Char -> Maybe Char -> LP m Inlines
accent '\774' Maybe Char
forall a. Maybe a
Nothing) -- breve
  , ("k", Char -> Maybe Char -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Char -> Maybe Char -> LP m Inlines
accent '\808' Maybe Char
forall a. Maybe a
Nothing) -- ogonek
  , ("textogonekcentered", Char -> Maybe Char -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Char -> Maybe Char -> LP m Inlines
accent '\808' Maybe Char
forall a. Maybe a
Nothing) -- ogonek
  , ("i", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "ı")  -- dotless i
  , ("j", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "ȷ")  -- dotless j
  , ("newtie", Char -> Maybe Char -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Char -> Maybe Char -> LP m Inlines
accent '\785' Maybe Char
forall a. Maybe a
Nothing) -- inverted breve
  , ("textcircled", Char -> Maybe Char -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Char -> Maybe Char -> LP m Inlines
accent '\8413' Maybe Char
forall a. Maybe a
Nothing) -- combining circle
  , ("\\", Inlines
linebreak Inlines -> LP m () -> LP m Inlines
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (do Bool
inTableCell <- LaTeXState -> Bool
sInTableCell (LaTeXState -> Bool)
-> ParsecT [Tok] LaTeXState m LaTeXState
-> ParsecT [Tok] LaTeXState m Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m LaTeXState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
                            Bool -> LP m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> LP m ()) -> Bool -> LP m ()
forall a b. (a -> b) -> a -> b
$ Bool -> Bool
not Bool
inTableCell
                            LP m Inlines -> ParsecT [Tok] LaTeXState m (Maybe Inlines)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
opt
                            LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces))
  , (",", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "\8198")
  , ("@", Inlines -> LP m Inlines
forall (f :: * -> *) a. Applicative f => a -> f a
pure Inlines
forall a. Monoid a => a
mempty)
  , (" ", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "\160")
  , ("ps", Inlines -> LP m Inlines
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Inlines -> LP m Inlines) -> Inlines -> LP m Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
str "PS." Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
space)
  , ("TeX", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "TeX")
  , ("LaTeX", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "LaTeX")
  , ("bar", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "|")
  , ("textless", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "<")
  , ("textgreater", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit ">")
  , ("thanks", LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts LP m () -> LP m Inlines -> LP m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Blocks -> Inlines
note (Blocks -> Inlines)
-> ParsecT [Tok] LaTeXState m Blocks -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m Blocks
-> ParsecT [Tok] LaTeXState m Blocks
forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
grouped ParsecT [Tok] LaTeXState m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
block)
  , ("footnote", LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts LP m () -> LP m Inlines -> LP m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Blocks -> Inlines
note (Blocks -> Inlines)
-> ParsecT [Tok] LaTeXState m Blocks -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m Blocks
-> ParsecT [Tok] LaTeXState m Blocks
forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
grouped ParsecT [Tok] LaTeXState m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
block)
  , ("passthrough", LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok) -- \passthrough macro used by latex writer
                         -- for listings
  , ("verb", LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
doverb)
  , ("lstinline", LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
dolstinline)
  , ("mintinline", LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
domintinline)
  , ("Verb", LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
doverb)
  , ("url", ((Text -> Text
unescapeURL (Text -> Text) -> ([Tok] -> Text) -> [Tok] -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize) ([Tok] -> Text)
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
bracedUrl) ParsecT [Tok] LaTeXState m Text
-> (Text -> LP m Inlines) -> LP m Inlines
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \url :: Text
url ->
                  Inlines -> LP m Inlines
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Text -> Text -> Inlines -> Inlines
link Text
url "" (Text -> Inlines
str Text
url)))
  , ("nolinkurl", ((Text -> Text
unescapeURL (Text -> Text) -> ([Tok] -> Text) -> [Tok] -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize) ([Tok] -> Text)
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
bracedUrl) ParsecT [Tok] LaTeXState m Text
-> (Text -> LP m Inlines) -> LP m Inlines
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \url :: Text
url ->
                  Inlines -> LP m Inlines
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Text -> Inlines
code Text
url))
  , ("href", (Text -> Text
unescapeURL (Text -> Text) -> ([Tok] -> Text) -> [Tok] -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize ([Tok] -> Text)
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
                 ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
bracedUrl ParsecT [Tok] LaTeXState m Text
-> LP m () -> ParsecT [Tok] LaTeXState m Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
sp) ParsecT [Tok] LaTeXState m Text
-> (Text -> LP m Inlines) -> LP m Inlines
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \url :: Text
url ->
                   LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok LP m Inlines -> (Inlines -> LP m Inlines) -> LP m Inlines
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \lab :: Inlines
lab -> Inlines -> LP m Inlines
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Text -> Text -> Inlines -> Inlines
link Text
url "" Inlines
lab))
  , ("includegraphics", do [(Text, Text)]
options <- [(Text, Text)]
-> ParsecT [Tok] LaTeXState m [(Text, Text)]
-> ParsecT [Tok] LaTeXState m [(Text, Text)]
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option [] ParsecT [Tok] LaTeXState m [(Text, Text)]
forall (m :: * -> *). PandocMonad m => LP m [(Text, Text)]
keyvals
                           Text
src <- Text -> Text
unescapeURL (Text -> Text) -> ([Tok] -> Text) -> [Tok] -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
removeDoubleQuotes (Text -> Text) -> ([Tok] -> Text) -> [Tok] -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize ([Tok] -> Text)
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
                           [(Text, Text)] -> Text -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
[(Text, Text)] -> Text -> LP m Inlines
mkImage [(Text, Text)]
options Text
src)
  , ("enquote*", Bool -> Maybe Text -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Bool -> Maybe Text -> LP m Inlines
enquote Bool
True Maybe Text
forall a. Maybe a
Nothing)
  , ("enquote", Bool -> Maybe Text -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Bool -> Maybe Text -> LP m Inlines
enquote Bool
False Maybe Text
forall a. Maybe a
Nothing)
  -- foreignquote is supposed to use native quote marks
  , ("foreignquote*", ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced ParsecT [Tok] LaTeXState m [Tok]
-> ([Tok] -> LP m Inlines) -> LP m Inlines
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Bool -> Maybe Text -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Bool -> Maybe Text -> LP m Inlines
enquote Bool
True (Maybe Text -> LP m Inlines)
-> ([Tok] -> Maybe Text) -> [Tok] -> LP m Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Maybe Text
forall a. a -> Maybe a
Just (Text -> Maybe Text) -> ([Tok] -> Text) -> [Tok] -> Maybe Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize)
  , ("foreignquote", ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced ParsecT [Tok] LaTeXState m [Tok]
-> ([Tok] -> LP m Inlines) -> LP m Inlines
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Bool -> Maybe Text -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Bool -> Maybe Text -> LP m Inlines
enquote Bool
False (Maybe Text -> LP m Inlines)
-> ([Tok] -> Maybe Text) -> [Tok] -> LP m Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Maybe Text
forall a. a -> Maybe a
Just (Text -> Maybe Text) -> ([Tok] -> Text) -> [Tok] -> Maybe Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize)
  -- hypehnquote uses regular quotes
  , ("hyphenquote*", ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced ParsecT [Tok] LaTeXState m [Tok]
-> ([Tok] -> LP m Inlines) -> LP m Inlines
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Bool -> Maybe Text -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Bool -> Maybe Text -> LP m Inlines
enquote Bool
True (Maybe Text -> LP m Inlines)
-> ([Tok] -> Maybe Text) -> [Tok] -> LP m Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Maybe Text
forall a. a -> Maybe a
Just (Text -> Maybe Text) -> ([Tok] -> Text) -> [Tok] -> Maybe Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize)
  , ("hyphenquote", ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced ParsecT [Tok] LaTeXState m [Tok]
-> ([Tok] -> LP m Inlines) -> LP m Inlines
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Bool -> Maybe Text -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Bool -> Maybe Text -> LP m Inlines
enquote Bool
False (Maybe Text -> LP m Inlines)
-> ([Tok] -> Maybe Text) -> [Tok] -> LP m Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Maybe Text
forall a. a -> Maybe a
Just (Text -> Maybe Text) -> ([Tok] -> Text) -> [Tok] -> Maybe Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize)
  , ("figurename", Term -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Term -> LP m Inlines
doTerm Term
Translations.Figure)
  , ("prefacename", Term -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Term -> LP m Inlines
doTerm Term
Translations.Preface)
  , ("refname", Term -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Term -> LP m Inlines
doTerm Term
Translations.References)
  , ("bibname", Term -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Term -> LP m Inlines
doTerm Term
Translations.Bibliography)
  , ("chaptername", Term -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Term -> LP m Inlines
doTerm Term
Translations.Chapter)
  , ("partname", Term -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Term -> LP m Inlines
doTerm Term
Translations.Part)
  , ("contentsname", Term -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Term -> LP m Inlines
doTerm Term
Translations.Contents)
  , ("listfigurename", Term -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Term -> LP m Inlines
doTerm Term
Translations.ListOfFigures)
  , ("listtablename", Term -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Term -> LP m Inlines
doTerm Term
Translations.ListOfTables)
  , ("indexname", Term -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Term -> LP m Inlines
doTerm Term
Translations.Index)
  , ("abstractname", Term -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Term -> LP m Inlines
doTerm Term
Translations.Abstract)
  , ("tablename", Term -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Term -> LP m Inlines
doTerm Term
Translations.Table)
  , ("enclname", Term -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Term -> LP m Inlines
doTerm Term
Translations.Encl)
  , ("ccname", Term -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Term -> LP m Inlines
doTerm Term
Translations.Cc)
  , ("headtoname", Term -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Term -> LP m Inlines
doTerm Term
Translations.To)
  , ("pagename", Term -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Term -> LP m Inlines
doTerm Term
Translations.Page)
  , ("seename", Term -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Term -> LP m Inlines
doTerm Term
Translations.See)
  , ("seealsoname", Term -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Term -> LP m Inlines
doTerm Term
Translations.SeeAlso)
  , ("proofname", Term -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Term -> LP m Inlines
doTerm Term
Translations.Proof)
  , ("glossaryname", Term -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Term -> LP m Inlines
doTerm Term
Translations.Glossary)
  , ("lstlistingname", Term -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Term -> LP m Inlines
doTerm Term
Translations.Listing)
  , ("cite", Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "cite" CitationMode
NormalCitation Bool
False)
  , ("Cite", Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "Cite" CitationMode
NormalCitation Bool
False)
  , ("citep", Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "citep" CitationMode
NormalCitation Bool
False)
  , ("citep*", Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "citep*" CitationMode
NormalCitation Bool
False)
  , ("citeal", Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "citeal" CitationMode
NormalCitation Bool
False)
  , ("citealp", Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "citealp" CitationMode
NormalCitation Bool
False)
  , ("citealp*", Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "citealp*" CitationMode
NormalCitation Bool
False)
  , ("autocite", Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "autocite" CitationMode
NormalCitation Bool
False)
  , ("smartcite", Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "smartcite" CitationMode
NormalCitation Bool
False)
  , ("footcite", Inlines -> Inlines
inNote (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "footcite" CitationMode
NormalCitation Bool
False)
  , ("parencite", Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "parencite" CitationMode
NormalCitation Bool
False)
  , ("supercite", Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "supercite" CitationMode
NormalCitation Bool
False)
  , ("footcitetext", Inlines -> Inlines
inNote (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "footcitetext" CitationMode
NormalCitation Bool
False)
  , ("citeyearpar", Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "citeyearpar" CitationMode
SuppressAuthor Bool
False)
  , ("citeyear", Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "citeyear" CitationMode
SuppressAuthor Bool
False)
  , ("autocite*", Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "autocite*" CitationMode
SuppressAuthor Bool
False)
  , ("cite*", Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "cite*" CitationMode
SuppressAuthor Bool
False)
  , ("parencite*", Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "parencite*" CitationMode
SuppressAuthor Bool
False)
  , ("textcite", Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "textcite" CitationMode
AuthorInText Bool
False)
  , ("citet", Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "citet" CitationMode
AuthorInText Bool
False)
  , ("citet*", Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "citet*" CitationMode
AuthorInText Bool
False)
  , ("citealt", Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "citealt" CitationMode
AuthorInText Bool
False)
  , ("citealt*", Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "citealt*" CitationMode
AuthorInText Bool
False)
  , ("textcites", Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "textcites" CitationMode
AuthorInText Bool
True)
  , ("cites", Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "cites" CitationMode
NormalCitation Bool
True)
  , ("autocites", Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "autocites" CitationMode
NormalCitation Bool
True)
  , ("footcites", Inlines -> Inlines
inNote (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "footcites" CitationMode
NormalCitation Bool
True)
  , ("parencites", Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "parencites" CitationMode
NormalCitation Bool
True)
  , ("supercites", Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "supercites" CitationMode
NormalCitation Bool
True)
  , ("footcitetexts", Inlines -> Inlines
inNote (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "footcitetexts" CitationMode
NormalCitation Bool
True)
  , ("Autocite", Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "Autocite" CitationMode
NormalCitation Bool
False)
  , ("Smartcite", Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "Smartcite" CitationMode
NormalCitation Bool
False)
  , ("Footcite", Inlines -> Inlines
inNote (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "Footcite" CitationMode
NormalCitation Bool
False)
  , ("Parencite", Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "Parencite" CitationMode
NormalCitation Bool
False)
  , ("Supercite", Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "Supercite" CitationMode
NormalCitation Bool
False)
  , ("Footcitetext", Inlines -> Inlines
inNote (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "Footcitetext" CitationMode
NormalCitation Bool
False)
  , ("Citeyearpar", Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "Citeyearpar" CitationMode
SuppressAuthor Bool
False)
  , ("Citeyear", Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "Citeyear" CitationMode
SuppressAuthor Bool
False)
  , ("Autocite*", Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "Autocite*" CitationMode
SuppressAuthor Bool
False)
  , ("Cite*", Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "Cite*" CitationMode
SuppressAuthor Bool
False)
  , ("Parencite*", Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "Parencite*" CitationMode
SuppressAuthor Bool
False)
  , ("Textcite", Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "Textcite" CitationMode
AuthorInText Bool
False)
  , ("Textcites", Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "Textcites" CitationMode
AuthorInText Bool
True)
  , ("Cites", Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "Cites" CitationMode
NormalCitation Bool
True)
  , ("Autocites", Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "Autocites" CitationMode
NormalCitation Bool
True)
  , ("Footcites", Inlines -> Inlines
inNote (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "Footcites" CitationMode
NormalCitation Bool
True)
  , ("Parencites", Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "Parencites" CitationMode
NormalCitation Bool
True)
  , ("Supercites", Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "Supercites" CitationMode
NormalCitation Bool
True)
  , ("Footcitetexts", Inlines -> Inlines
inNote (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "Footcitetexts" CitationMode
NormalCitation Bool
True)
  , ("citetext", CitationMode -> LP m Inlines
forall (m :: * -> *). PandocMonad m => CitationMode -> LP m Inlines
complexNatbibCitation CitationMode
NormalCitation)
  , ("citeauthor", (ParsecT [Tok] LaTeXState m Tok -> ParsecT [Tok] LaTeXState m Tok
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok LP m Inlines -> LP m () -> LP m ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
sp LP m ()
-> ParsecT [Tok] LaTeXState m Tok -> ParsecT [Tok] LaTeXState m Tok
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Text -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "citetext") ParsecT [Tok] LaTeXState m Tok -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
                        CitationMode -> LP m Inlines
forall (m :: * -> *). PandocMonad m => CitationMode -> LP m Inlines
complexNatbibCitation CitationMode
AuthorInText)
                   LP m Inlines -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "citeauthor" CitationMode
AuthorInText Bool
False)
  , ("nocite", Inlines
forall a. Monoid a => a
mempty Inlines -> LP m () -> LP m Inlines
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (Text -> CitationMode -> Bool -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> CitationMode -> Bool -> LP m Inlines
citation "nocite" CitationMode
NormalCitation Bool
False LP m Inlines -> (Inlines -> LP m ()) -> LP m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
                          Text -> Inlines -> LP m ()
forall (m :: * -> *) a.
(PandocMonad m, ToMetaValue a) =>
Text -> a -> LP m ()
addMeta "nocite"))
  , ("hyperlink", LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
hyperlink)
  , ("hypertarget", LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
hypertargetInline)
  -- glossaries package
  , ("gls", Text -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Text -> LP m Inlines
doAcronym "short")
  , ("Gls", Text -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Text -> LP m Inlines
doAcronym "short")
  , ("glsdesc", Text -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Text -> LP m Inlines
doAcronym "long")
  , ("Glsdesc", Text -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Text -> LP m Inlines
doAcronym "long")
  , ("GLSdesc", Text -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Text -> LP m Inlines
doAcronym "long")
  , ("acrlong", Text -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Text -> LP m Inlines
doAcronym "long")
  , ("Acrlong", Text -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Text -> LP m Inlines
doAcronym "long")
  , ("acrfull", Text -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Text -> LP m Inlines
doAcronym "full")
  , ("Acrfull", Text -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Text -> LP m Inlines
doAcronym "full")
  , ("acrshort", Text -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Text -> LP m Inlines
doAcronym "abbrv")
  , ("Acrshort", Text -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Text -> LP m Inlines
doAcronym "abbrv")
  , ("glspl", Text -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Text -> LP m Inlines
doAcronymPlural "short")
  , ("Glspl", Text -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Text -> LP m Inlines
doAcronymPlural "short")
  , ("glsdescplural", Text -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Text -> LP m Inlines
doAcronymPlural "long")
  , ("Glsdescplural", Text -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Text -> LP m Inlines
doAcronymPlural "long")
  , ("GLSdescplural", Text -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Text -> LP m Inlines
doAcronymPlural "long")
  -- acronyms package
  , ("ac", Text -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Text -> LP m Inlines
doAcronym "short")
  , ("acf", Text -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Text -> LP m Inlines
doAcronym "full")
  , ("acs", Text -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Text -> LP m Inlines
doAcronym "abbrv")
  , ("acp", Text -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Text -> LP m Inlines
doAcronymPlural "short")
  , ("acfp", Text -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Text -> LP m Inlines
doAcronymPlural "full")
  , ("acsp", Text -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Text -> LP m Inlines
doAcronymPlural "abbrv")
  -- siuntix
  , ("SI", LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
dosiunitx)
  -- hyphenat
  , ("bshyp", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "\\\173")
  , ("fshyp", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "/\173")
  , ("dothyp", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit ".\173")
  , ("colonhyp", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit ":\173")
  , ("hyp", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "-")
  , ("nohyphens", LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
  , ("textnhtt", LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
ttfamily)
  , ("nhttfamily", LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
ttfamily)
  -- LaTeX colors
  , ("textcolor", Text -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Text -> LP m Inlines
coloredInline "color")
  , ("colorbox", Text -> LP m Inlines
forall (m :: * -> *). PandocMonad m => Text -> LP m Inlines
coloredInline "background-color")
  -- fontawesome
  , ("faCheck", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "\10003")
  , ("faClose", Text -> LP m Inlines
forall (m :: * -> *). Text -> LP m Inlines
lit "\10007")
  -- xspace
  , ("xspace", LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
doxspace)
  -- etoolbox
  , ("ifstrequal", LP m Inlines
forall (m :: * -> *) a. (PandocMonad m, Monoid a) => LP m a
ifstrequal)
  , ("newtoggle", ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced ParsecT [Tok] LaTeXState m [Tok]
-> ([Tok] -> LP m Inlines) -> LP m Inlines
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= [Tok] -> LP m Inlines
forall a (m :: * -> *).
(Monoid a, PandocMonad m) =>
[Tok] -> LP m a
newToggle)
  , ("toggletrue", ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced ParsecT [Tok] LaTeXState m [Tok]
-> ([Tok] -> LP m Inlines) -> LP m Inlines
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Bool -> [Tok] -> LP m Inlines
forall a (m :: * -> *).
(Monoid a, PandocMonad m) =>
Bool -> [Tok] -> LP m a
setToggle Bool
True)
  , ("togglefalse", ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced ParsecT [Tok] LaTeXState m [Tok]
-> ([Tok] -> LP m Inlines) -> LP m Inlines
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Bool -> [Tok] -> LP m Inlines
forall a (m :: * -> *).
(Monoid a, PandocMonad m) =>
Bool -> [Tok] -> LP m a
setToggle Bool
False)
  , ("iftoggle", LP m Inlines -> LP m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (LP m Inlines -> LP m Inlines) -> LP m Inlines -> LP m Inlines
forall a b. (a -> b) -> a -> b
$ LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
ifToggle LP m () -> LP m Inlines -> LP m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
inline)
  -- biblatex misc
  , ("RN", LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
romanNumeralUpper)
  , ("Rn", LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
romanNumeralLower)
  -- babel
  , ("foreignlanguage", LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
foreignlanguage)
  -- include
  , ("input", Text -> LP m Inlines -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Text -> LP m Inlines -> LP m Inlines
rawInlineOr "input" (LP m Inlines -> LP m Inlines) -> LP m Inlines -> LP m Inlines
forall a b. (a -> b) -> a -> b
$ Text -> LP m Inlines
forall (m :: * -> *) a. (PandocMonad m, Monoid a) => Text -> LP m a
include "input")
  -- soul package
  , ("ul", Inlines -> Inlines
underlineSpan (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
  -- ulem package
  , ("uline", Inlines -> Inlines
underlineSpan (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
  -- plain tex stuff that should just be passed through as raw tex
  , ("ifdim", LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
ifdim)
  ]

ifdim :: PandocMonad m => LP m Inlines
ifdim :: LP m Inlines
ifdim = do
  [Tok]
contents <- ParsecT [Tok] LaTeXState m Tok
-> ParsecT [Tok] LaTeXState m Tok
-> ParsecT [Tok] LaTeXState m [Tok]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => LP m Tok
anyTok (Text -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "fi")
  Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> LP m Inlines) -> Inlines -> LP m Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Text -> Inlines
rawInline "latex" (Text -> Inlines) -> Text -> Inlines
forall a b. (a -> b) -> a -> b
$ "\\ifdim" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> [Tok] -> Text
untokenize [Tok]
contents Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> "\\fi"

makeUppercase :: Inlines -> Inlines
makeUppercase :: Inlines -> Inlines
makeUppercase = [Inline] -> Inlines
forall a. [a] -> Many a
fromList ([Inline] -> Inlines)
-> (Inlines -> [Inline]) -> Inlines -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Inline -> Inline) -> [Inline] -> [Inline]
forall a b. Walkable a b => (a -> a) -> b -> b
walk ((Text -> Text) -> Inline -> Inline
alterStr Text -> Text
T.toUpper) ([Inline] -> [Inline])
-> (Inlines -> [Inline]) -> Inlines -> [Inline]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> [Inline]
forall a. Many a -> [a]
toList

makeLowercase :: Inlines -> Inlines
makeLowercase :: Inlines -> Inlines
makeLowercase = [Inline] -> Inlines
forall a. [a] -> Many a
fromList ([Inline] -> Inlines)
-> (Inlines -> [Inline]) -> Inlines -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Inline -> Inline) -> [Inline] -> [Inline]
forall a b. Walkable a b => (a -> a) -> b -> b
walk ((Text -> Text) -> Inline -> Inline
alterStr Text -> Text
T.toLower) ([Inline] -> [Inline])
-> (Inlines -> [Inline]) -> Inlines -> [Inline]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> [Inline]
forall a. Many a -> [a]
toList

alterStr :: (Text -> Text) -> Inline -> Inline
alterStr :: (Text -> Text) -> Inline -> Inline
alterStr f :: Text -> Text
f (Str xs :: Text
xs) = Text -> Inline
Str (Text -> Text
f Text
xs)
alterStr _ x :: Inline
x = Inline
x

foreignlanguage :: PandocMonad m => LP m Inlines
foreignlanguage :: LP m Inlines
foreignlanguage = do
  Text
babelLang <- [Tok] -> Text
untokenize ([Tok] -> Text)
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
  case Text -> Maybe Lang
babelLangToBCP47 Text
babelLang of
       Just lang :: Lang
lang -> Attr -> Inlines -> Inlines
spanWith ("", [], [("lang",  Lang -> Text
renderLang Lang
lang)]) (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok
       _ -> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok

inlineLanguageCommands :: PandocMonad m => M.Map Text (LP m Inlines)
inlineLanguageCommands :: Map Text (LP m Inlines)
inlineLanguageCommands = [(Text, LP m Inlines)] -> Map Text (LP m Inlines)
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList ([(Text, LP m Inlines)] -> Map Text (LP m Inlines))
-> [(Text, LP m Inlines)] -> Map Text (LP m Inlines)
forall a b. (a -> b) -> a -> b
$ (Text, Text -> Lang) -> (Text, LP m Inlines)
forall a (m :: * -> *).
(Semigroup a, IsString a, PandocMonad m) =>
(a, Text -> Lang) -> (a, LP m Inlines)
mk ((Text, Text -> Lang) -> (Text, LP m Inlines))
-> [(Text, Text -> Lang)] -> [(Text, LP m Inlines)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Map Text (Text -> Lang) -> [(Text, Text -> Lang)]
forall k a. Map k a -> [(k, a)]
M.toList Map Text (Text -> Lang)
polyglossiaLangToBCP47
  where
    mk :: (a, Text -> Lang) -> (a, LP m Inlines)
mk (polyglossia :: a
polyglossia, bcp47Func :: Text -> Lang
bcp47Func) =
      ("text" a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
polyglossia, (Text -> Lang) -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
(Text -> Lang) -> LP m Inlines
inlineLanguage Text -> Lang
bcp47Func)

inlineLanguage :: PandocMonad m => (Text -> Lang) -> LP m Inlines
inlineLanguage :: (Text -> Lang) -> LP m Inlines
inlineLanguage bcp47Func :: Text -> Lang
bcp47Func = do
  Text
o <- Text
-> ParsecT [Tok] LaTeXState m Text
-> ParsecT [Tok] LaTeXState m Text
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option "" (ParsecT [Tok] LaTeXState m Text
 -> ParsecT [Tok] LaTeXState m Text)
-> ParsecT [Tok] LaTeXState m Text
-> ParsecT [Tok] LaTeXState m Text
forall a b. (a -> b) -> a -> b
$ (Char -> Bool) -> Text -> Text
T.filter (\c :: Char
c -> Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= '[' Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= ']')
                (Text -> Text)
-> ParsecT [Tok] LaTeXState m Text
-> ParsecT [Tok] LaTeXState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m Text
forall (m :: * -> *). PandocMonad m => LP m Text
rawopt
  let lang :: Text
lang = Lang -> Text
renderLang (Lang -> Text) -> Lang -> Text
forall a b. (a -> b) -> a -> b
$ Text -> Lang
bcp47Func Text
o
  (Inlines -> Inlines) -> Inlines -> Inlines
extractSpaces (Attr -> Inlines -> Inlines
spanWith ("", [], [("lang", Text
lang)])) (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok

hyperlink :: PandocMonad m => LP m Inlines
hyperlink :: LP m Inlines
hyperlink = LP m Inlines -> LP m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (LP m Inlines -> LP m Inlines) -> LP m Inlines -> LP m Inlines
forall a b. (a -> b) -> a -> b
$ do
  Text
src <- [Tok] -> Text
untokenize ([Tok] -> Text)
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
  Inlines
lab <- LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok
  Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> LP m Inlines) -> Inlines -> LP m Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Text -> Inlines -> Inlines
link ("#" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
src) "" Inlines
lab

hypertargetBlock :: PandocMonad m => LP m Blocks
hypertargetBlock :: LP m Blocks
hypertargetBlock = LP m Blocks -> LP m Blocks
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (LP m Blocks -> LP m Blocks) -> LP m Blocks -> LP m Blocks
forall a b. (a -> b) -> a -> b
$ do
  Text
ref <- [Tok] -> Text
untokenize ([Tok] -> Text)
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
  Blocks
bs <- LP m Blocks -> LP m Blocks
forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
grouped LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
block
  case Blocks -> [Block]
forall a. Many a -> [a]
toList Blocks
bs of
       [Header 1 (ident :: Text
ident,_,_) _] | Text
ident Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
ref -> Blocks -> LP m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
bs
       _                        -> Blocks -> LP m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return (Blocks -> LP m Blocks) -> Blocks -> LP m Blocks
forall a b. (a -> b) -> a -> b
$ Attr -> Blocks -> Blocks
divWith (Text
ref, [], []) Blocks
bs

hypertargetInline :: PandocMonad m => LP m Inlines
hypertargetInline :: LP m Inlines
hypertargetInline = LP m Inlines -> LP m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (LP m Inlines -> LP m Inlines) -> LP m Inlines -> LP m Inlines
forall a b. (a -> b) -> a -> b
$ do
  Text
ref <- [Tok] -> Text
untokenize ([Tok] -> Text)
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
  Inlines
ils <- LP m Inlines -> LP m Inlines
forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
grouped LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
inline
  Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> LP m Inlines) -> Inlines -> LP m Inlines
forall a b. (a -> b) -> a -> b
$ Attr -> Inlines -> Inlines
spanWith (Text
ref, [], []) Inlines
ils

romanNumeralUpper :: (PandocMonad m) => LP m Inlines
romanNumeralUpper :: LP m Inlines
romanNumeralUpper =
  Text -> Inlines
str (Text -> Inlines) -> (Int -> Text) -> Int -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Text
toRomanNumeral (Int -> Inlines) -> ParsecT [Tok] LaTeXState m Int -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m Int
forall (m :: * -> *). PandocMonad m => LP m Int
romanNumeralArg

romanNumeralLower :: (PandocMonad m) => LP m Inlines
romanNumeralLower :: LP m Inlines
romanNumeralLower =
  Text -> Inlines
str (Text -> Inlines) -> (Int -> Text) -> Int -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
T.toLower (Text -> Text) -> (Int -> Text) -> Int -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Text
toRomanNumeral (Int -> Inlines) -> ParsecT [Tok] LaTeXState m Int -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m Int
forall (m :: * -> *). PandocMonad m => LP m Int
romanNumeralArg

romanNumeralArg :: (PandocMonad m) => LP m Int
romanNumeralArg :: LP m Int
romanNumeralArg = LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces LP m () -> LP m Int -> LP m Int
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (LP m Int
parser LP m Int -> LP m Int -> LP m Int
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> LP m Int
inBraces)
  where
    inBraces :: LP m Int
inBraces = do
      Char -> LP m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '{'
      LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces
      Int
res <- LP m Int
parser
      LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces
      Char -> LP m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '}'
      Int -> LP m Int
forall (m :: * -> *) a. Monad m => a -> m a
return Int
res
    parser :: LP m Int
parser = do
      Tok _ Word s :: Text
s <- (Tok -> Bool) -> LP m Tok
forall (m :: * -> *). PandocMonad m => (Tok -> Bool) -> LP m Tok
satisfyTok Tok -> Bool
isWordTok
      let (digits :: Text
digits, rest :: Text
rest) = (Char -> Bool) -> Text -> (Text, Text)
T.span Char -> Bool
isDigit Text
s
      Bool -> LP m () -> LP m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Text -> Bool
T.null Text
rest) (LP m () -> LP m ()) -> LP m () -> LP m ()
forall a b. (a -> b) -> a -> b
$
        SourceName -> LP m ()
forall (m :: * -> *) a. MonadFail m => SourceName -> m a
Prelude.fail "Non-digits in argument to \\Rn or \\RN"
      Text -> LP m Int
forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
safeRead Text
digits

newToggle :: (Monoid a, PandocMonad m) => [Tok] -> LP m a
newToggle :: [Tok] -> LP m a
newToggle name :: [Tok]
name = do
  (LaTeXState -> LaTeXState) -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((LaTeXState -> LaTeXState) -> ParsecT [Tok] LaTeXState m ())
-> (LaTeXState -> LaTeXState) -> ParsecT [Tok] LaTeXState m ()
forall a b. (a -> b) -> a -> b
$ \st :: LaTeXState
st ->
    LaTeXState
st{ sToggles :: Map Text Bool
sToggles = Text -> Bool -> Map Text Bool -> Map Text Bool
forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert ([Tok] -> Text
untokenize [Tok]
name) Bool
False (LaTeXState -> Map Text Bool
sToggles LaTeXState
st) }
  a -> LP m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
forall a. Monoid a => a
mempty

setToggle :: (Monoid a, PandocMonad m) => Bool -> [Tok] -> LP m a
setToggle :: Bool -> [Tok] -> LP m a
setToggle on :: Bool
on name :: [Tok]
name = do
  (LaTeXState -> LaTeXState) -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((LaTeXState -> LaTeXState) -> ParsecT [Tok] LaTeXState m ())
-> (LaTeXState -> LaTeXState) -> ParsecT [Tok] LaTeXState m ()
forall a b. (a -> b) -> a -> b
$ \st :: LaTeXState
st ->
    LaTeXState
st{ sToggles :: Map Text Bool
sToggles = (Bool -> Bool) -> Text -> Map Text Bool -> Map Text Bool
forall k a. Ord k => (a -> a) -> k -> Map k a -> Map k a
M.adjust (Bool -> Bool -> Bool
forall a b. a -> b -> a
const Bool
on) ([Tok] -> Text
untokenize [Tok]
name) (LaTeXState -> Map Text Bool
sToggles LaTeXState
st) }
  a -> LP m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
forall a. Monoid a => a
mempty

ifToggle :: PandocMonad m => LP m ()
ifToggle :: LP m ()
ifToggle = do
  [Tok]
name <- LP m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
  LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces
  [Tok]
yes <- LP m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
  LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces
  [Tok]
no <- LP m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
  Map Text Bool
toggles <- LaTeXState -> Map Text Bool
sToggles (LaTeXState -> Map Text Bool)
-> ParsecT [Tok] LaTeXState m LaTeXState
-> ParsecT [Tok] LaTeXState m (Map Text Bool)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m LaTeXState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  [Tok]
inp <- LP m [Tok]
forall (m :: * -> *) s u. Monad m => ParsecT s u m s
getInput
  let name' :: Text
name' = [Tok] -> Text
untokenize [Tok]
name
  case Text -> Map Text Bool -> Maybe Bool
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Text
name' Map Text Bool
toggles of
                Just True  -> [Tok] -> LP m ()
forall (m :: * -> *) s u. Monad m => s -> ParsecT s u m ()
setInput ([Tok]
yes [Tok] -> [Tok] -> [Tok]
forall a. [a] -> [a] -> [a]
++ [Tok]
inp)
                Just False -> [Tok] -> LP m ()
forall (m :: * -> *) s u. Monad m => s -> ParsecT s u m ()
setInput ([Tok]
no  [Tok] -> [Tok] -> [Tok]
forall a. [a] -> [a] -> [a]
++ [Tok]
inp)
                Nothing    -> do
                  SourcePos
pos <- ParsecT [Tok] LaTeXState m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
                  LogMessage -> LP m ()
forall (m :: * -> *). PandocMonad m => LogMessage -> m ()
report (LogMessage -> LP m ()) -> LogMessage -> LP m ()
forall a b. (a -> b) -> a -> b
$ Text -> SourcePos -> LogMessage
UndefinedToggle Text
name' SourcePos
pos
  () -> LP m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

doTerm :: PandocMonad m => Translations.Term -> LP m Inlines
doTerm :: Term -> LP m Inlines
doTerm term :: Term
term = Text -> Inlines
str (Text -> Inlines)
-> ParsecT [Tok] LaTeXState m Text -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Term -> ParsecT [Tok] LaTeXState m Text
forall (m :: * -> *). PandocMonad m => Term -> m Text
translateTerm Term
term

ifstrequal :: (PandocMonad m, Monoid a) => LP m a
ifstrequal :: LP m a
ifstrequal = do
  Inlines
str1 <- LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok
  Inlines
str2 <- LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok
  [Tok]
ifequal <- LP m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
  [Tok]
ifnotequal <- LP m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
  if Inlines
str1 Inlines -> Inlines -> Bool
forall a. Eq a => a -> a -> Bool
== Inlines
str2
     then LP m [Tok]
forall (m :: * -> *) s u. Monad m => ParsecT s u m s
getInput LP m [Tok]
-> ([Tok] -> ParsecT [Tok] LaTeXState m ())
-> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= [Tok] -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) s u. Monad m => s -> ParsecT s u m ()
setInput ([Tok] -> ParsecT [Tok] LaTeXState m ())
-> ([Tok] -> [Tok]) -> [Tok] -> ParsecT [Tok] LaTeXState m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Tok]
ifequal [Tok] -> [Tok] -> [Tok]
forall a. [a] -> [a] -> [a]
++)
     else LP m [Tok]
forall (m :: * -> *) s u. Monad m => ParsecT s u m s
getInput LP m [Tok]
-> ([Tok] -> ParsecT [Tok] LaTeXState m ())
-> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= [Tok] -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) s u. Monad m => s -> ParsecT s u m ()
setInput ([Tok] -> ParsecT [Tok] LaTeXState m ())
-> ([Tok] -> [Tok]) -> [Tok] -> ParsecT [Tok] LaTeXState m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Tok]
ifnotequal [Tok] -> [Tok] -> [Tok]
forall a. [a] -> [a] -> [a]
++)
  a -> LP m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
forall a. Monoid a => a
mempty

coloredInline :: PandocMonad m => Text -> LP m Inlines
coloredInline :: Text -> LP m Inlines
coloredInline stylename :: Text
stylename = do
  LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts
  [Tok]
color <- LP m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
  Attr -> Inlines -> Inlines
spanWith ("",[],[("style",Text
stylename Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> ": " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> [Tok] -> Text
untokenize [Tok]
color)]) (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok

ttfamily :: PandocMonad m => LP m Inlines
ttfamily :: LP m Inlines
ttfamily = (Text -> Inlines
code (Text -> Inlines) -> (Inlines -> Text) -> Inlines -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inline] -> Text
forall a. Walkable Inline a => a -> Text
stringify ([Inline] -> Text) -> (Inlines -> [Inline]) -> Inlines -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> [Inline]
forall a. Many a -> [a]
toList) (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok

rawInlineOr :: PandocMonad m => Text -> LP m Inlines -> LP m Inlines
rawInlineOr :: Text -> LP m Inlines -> LP m Inlines
rawInlineOr name' :: Text
name' fallback :: LP m Inlines
fallback = do
  Bool
parseRaw <- Extension -> Extensions -> Bool
extensionEnabled Extension
Ext_raw_tex (Extensions -> Bool)
-> ParsecT [Tok] LaTeXState m Extensions
-> ParsecT [Tok] LaTeXState m Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ReaderOptions -> Extensions)
-> ParsecT [Tok] LaTeXState m Extensions
forall st s (m :: * -> *) t b.
(HasReaderOptions st, Stream s m t) =>
(ReaderOptions -> b) -> ParserT s st m b
getOption ReaderOptions -> Extensions
readerExtensions
  if Bool
parseRaw
     then Text -> Text -> Inlines
rawInline "latex" (Text -> Inlines)
-> ParsecT [Tok] LaTeXState m Text -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> Text -> ParsecT [Tok] LaTeXState m Text
forall (m :: * -> *). PandocMonad m => Text -> Text -> LP m Text
getRawCommand Text
name' ("\\" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
name')
     else LP m Inlines
fallback

processHBox :: Inlines -> Inlines
processHBox :: Inlines -> Inlines
processHBox = (Inline -> Inline) -> Inlines -> Inlines
forall a b. Walkable a b => (a -> a) -> b -> b
walk Inline -> Inline
convert
  where
    convert :: Inline -> Inline
convert Space     = Text -> Inline
Str (Text -> Inline) -> Text -> Inline
forall a b. (a -> b) -> a -> b
$ Char -> Text
T.singleton (Char -> Text) -> Char -> Text
forall a b. (a -> b) -> a -> b
$ Int -> Char
chr 160 -- non-breakable space
    convert SoftBreak = Text -> Inline
Str (Text -> Inline) -> Text -> Inline
forall a b. (a -> b) -> a -> b
$ Char -> Text
T.singleton (Char -> Text) -> Char -> Text
forall a b. (a -> b) -> a -> b
$ Int -> Char
chr 160 -- non-breakable space
    convert LineBreak = Text -> Inline
Str ""
    convert x :: Inline
x         = Inline
x

getRawCommand :: PandocMonad m => Text -> Text -> LP m Text
getRawCommand :: Text -> Text -> LP m Text
getRawCommand name :: Text
name txt :: Text
txt = do
  (_, rawargs :: [Tok]
rawargs) <- LP m () -> LP m ((), [Tok])
forall (m :: * -> *) a. PandocMonad m => LP m a -> LP m (a, [Tok])
withRaw (LP m () -> LP m ((), [Tok])) -> LP m () -> LP m ((), [Tok])
forall a b. (a -> b) -> a -> b
$
      case Text
name of
           "write" -> do
             ParsecT [Tok] LaTeXState m Tok -> LP m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT [Tok] LaTeXState m Tok -> LP m ())
-> ParsecT [Tok] LaTeXState m Tok -> LP m ()
forall a b. (a -> b) -> a -> b
$ (Tok -> Bool) -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => (Tok -> Bool) -> LP m Tok
satisfyTok Tok -> Bool
isWordTok -- digits
             ParsecT [Tok] LaTeXState m [Tok] -> LP m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
           "titleformat" -> do
             ParsecT [Tok] LaTeXState m [Tok] -> LP m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
             LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts
             ParsecT [Tok] LaTeXState m [[Tok]] -> LP m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT [Tok] LaTeXState m [[Tok]] -> LP m ())
-> ParsecT [Tok] LaTeXState m [[Tok]] -> LP m ()
forall a b. (a -> b) -> a -> b
$ Int
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m [[Tok]]
forall s (m :: * -> *) t u a.
Stream s m t =>
Int -> ParsecT s u m a -> ParsecT s u m [a]
count 4 ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
           "def" ->
             ParsecT [Tok] LaTeXState m [Tok] -> LP m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT [Tok] LaTeXState m [Tok] -> LP m ())
-> ParsecT [Tok] LaTeXState m [Tok] -> LP m ()
forall a b. (a -> b) -> a -> b
$ ParsecT [Tok] LaTeXState m Tok
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m [Tok]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => LP m Tok
anyTok ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
           _ | Text -> Bool
isFontSizeCommand Text
name -> () -> LP m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
             | Bool
otherwise -> do
               LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts
               Text -> LP m Text -> LP m Text
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option "" (LP m Text -> LP m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try LP m Text
forall (m :: * -> *). PandocMonad m => LP m Text
dimenarg)
               ParsecT [Tok] LaTeXState m [[Tok]] -> LP m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT [Tok] LaTeXState m [[Tok]] -> LP m ())
-> ParsecT [Tok] LaTeXState m [[Tok]] -> LP m ()
forall a b. (a -> b) -> a -> b
$ ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m [[Tok]]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
  Text -> LP m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> LP m Text) -> Text -> LP m Text
forall a b. (a -> b) -> a -> b
$ Text
txt Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> [Tok] -> Text
untokenize [Tok]
rawargs

isFontSizeCommand :: Text -> Bool
isFontSizeCommand :: Text -> Bool
isFontSizeCommand "tiny" = Bool
True
isFontSizeCommand "scriptsize" = Bool
True
isFontSizeCommand "footnotesize" = Bool
True
isFontSizeCommand "small" = Bool
True
isFontSizeCommand "normalsize" = Bool
True
isFontSizeCommand "large" = Bool
True
isFontSizeCommand "Large" = Bool
True
isFontSizeCommand "LARGE" = Bool
True
isFontSizeCommand "huge" = Bool
True
isFontSizeCommand "Huge" = Bool
True
isFontSizeCommand _ = Bool
False

isBlockCommand :: Text -> Bool
isBlockCommand :: Text -> Bool
isBlockCommand s :: Text
s =
  Text
s Text -> Map Text (LP PandocPure Blocks) -> Bool
forall k a. Ord k => k -> Map k a -> Bool
`M.member` (Map Text (LP PandocPure Blocks)
forall (m :: * -> *). PandocMonad m => Map Text (LP m Blocks)
blockCommands :: M.Map Text (LP PandocPure Blocks))
  Bool -> Bool -> Bool
|| Text
s Text -> Set Text -> Bool
forall a. Ord a => a -> Set a -> Bool
`Set.member` Set Text
treatAsBlock

treatAsBlock :: Set.Set Text
treatAsBlock :: Set Text
treatAsBlock = [Text] -> Set Text
forall a. Ord a => [a] -> Set a
Set.fromList
   [ "special", "pdfannot", "pdfstringdef"
   , "bibliographystyle"
   , "maketitle", "makeindex", "makeglossary"
   , "addcontentsline", "addtocontents", "addtocounter"
      -- \ignore{} is used conventionally in literate haskell for definitions
      -- that are to be processed by the compiler but not printed.
   , "ignore"
   , "hyperdef"
   , "markboth", "markright", "markleft"
   , "hspace", "vspace"
   , "newpage"
   , "clearpage"
   , "pagebreak"
   , "titleformat"
   , "listoffigures"
   , "listoftables"
   , "write"
   ]

isInlineCommand :: Text -> Bool
isInlineCommand :: Text -> Bool
isInlineCommand s :: Text
s =
  Text
s Text -> Map Text (LP PandocPure Inlines) -> Bool
forall k a. Ord k => k -> Map k a -> Bool
`M.member` (Map Text (LP PandocPure Inlines)
forall (m :: * -> *). PandocMonad m => Map Text (LP m Inlines)
inlineCommands :: M.Map Text (LP PandocPure Inlines))
  Bool -> Bool -> Bool
|| Text
s Text -> Set Text -> Bool
forall a. Ord a => a -> Set a -> Bool
`Set.member` Set Text
treatAsInline

treatAsInline :: Set.Set Text
treatAsInline :: Set Text
treatAsInline = [Text] -> Set Text
forall a. Ord a => [a] -> Set a
Set.fromList
  [ "index"
  , "hspace"
  , "vspace"
  , "noindent"
  , "newpage"
  , "clearpage"
  , "pagebreak"
  ]

label :: PandocMonad m => LP m ()
label :: LP m ()
label = do
  Text -> LP m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "label"
  [Tok]
t <- LP m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
  (LaTeXState -> LaTeXState) -> LP m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((LaTeXState -> LaTeXState) -> LP m ())
-> (LaTeXState -> LaTeXState) -> LP m ()
forall a b. (a -> b) -> a -> b
$ \st :: LaTeXState
st -> LaTeXState
st{ sLastLabel :: Maybe Text
sLastLabel = Text -> Maybe Text
forall a. a -> Maybe a
Just (Text -> Maybe Text) -> Text -> Maybe Text
forall a b. (a -> b) -> a -> b
$ [Tok] -> Text
untokenize [Tok]
t }

dolabel :: PandocMonad m => LP m Inlines
dolabel :: LP m Inlines
dolabel = do
  [Tok]
v <- LP m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
  let refstr :: Text
refstr = [Tok] -> Text
untokenize [Tok]
v
  (LaTeXState -> LaTeXState) -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((LaTeXState -> LaTeXState) -> ParsecT [Tok] LaTeXState m ())
-> (LaTeXState -> LaTeXState) -> ParsecT [Tok] LaTeXState m ()
forall a b. (a -> b) -> a -> b
$ \st :: LaTeXState
st ->
    LaTeXState
st{ sLastLabel :: Maybe Text
sLastLabel = Text -> Maybe Text
forall a. a -> Maybe a
Just Text
refstr }
  Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> LP m Inlines) -> Inlines -> LP m Inlines
forall a b. (a -> b) -> a -> b
$ Attr -> Inlines -> Inlines
spanWith (Text
refstr,[],[("label", Text
refstr)])
    (Inlines -> Inlines) -> Inlines -> Inlines
forall a b. (a -> b) -> a -> b
$ Inlines -> Inlines
inBrackets (Inlines -> Inlines) -> Inlines -> Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
str (Text -> Inlines) -> Text -> Inlines
forall a b. (a -> b) -> a -> b
$ [Tok] -> Text
untokenize [Tok]
v

doref :: PandocMonad m => Text -> LP m Inlines
doref :: Text -> LP m Inlines
doref cls :: Text
cls = do
  [Tok]
v <- LP m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
  let refstr :: Text
refstr = [Tok] -> Text
untokenize [Tok]
v
  Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> LP m Inlines) -> Inlines -> LP m Inlines
forall a b. (a -> b) -> a -> b
$ Attr -> Text -> Text -> Inlines -> Inlines
linkWith ("",[],[ ("reference-type", Text
cls)
                           , ("reference", Text
refstr)])
                    ("#" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
refstr)
                    ""
                    (Inlines -> Inlines
inBrackets (Inlines -> Inlines) -> Inlines -> Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
str Text
refstr)

lookupListDefault :: (Ord k) => v -> [k] -> M.Map k v -> v
lookupListDefault :: v -> [k] -> Map k v -> v
lookupListDefault d :: v
d = (v -> Maybe v -> v
forall a. a -> Maybe a -> a
fromMaybe v
d (Maybe v -> v) -> (Map k v -> Maybe v) -> Map k v -> v
forall b c a. (b -> c) -> (a -> b) -> a -> c
.) ((Map k v -> Maybe v) -> Map k v -> v)
-> ([k] -> Map k v -> Maybe v) -> [k] -> Map k v -> v
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [k] -> Map k v -> Maybe v
forall k a. Ord k => [k] -> Map k a -> Maybe a
lookupList
  where lookupList :: [k] -> Map k a -> Maybe a
lookupList l :: [k]
l m :: Map k a
m = [Maybe a] -> Maybe a
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, MonadPlus m) =>
t (m a) -> m a
msum ([Maybe a] -> Maybe a) -> [Maybe a] -> Maybe a
forall a b. (a -> b) -> a -> b
$ (k -> Maybe a) -> [k] -> [Maybe a]
forall a b. (a -> b) -> [a] -> [b]
map (k -> Map k a -> Maybe a
forall k a. Ord k => k -> Map k a -> Maybe a
`M.lookup` Map k a
m) [k]
l

inline :: PandocMonad m => LP m Inlines
inline :: LP m Inlines
inline = (Inlines
forall a. Monoid a => a
mempty Inlines -> ParsecT [Tok] LaTeXState m () -> LP m Inlines
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
comment)
     LP m Inlines -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Inlines
space  Inlines -> ParsecT [Tok] LaTeXState m () -> LP m Inlines
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
whitespace)
     LP m Inlines -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Inlines
softbreak Inlines -> ParsecT [Tok] LaTeXState m () -> LP m Inlines
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
endline)
     LP m Inlines -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
word
     LP m Inlines -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Text -> Inlines) -> LP m Inlines
forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
(Text -> a) -> LP m a
macroDef (Text -> Text -> Inlines
rawInline "latex")
     LP m Inlines -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
inlineCommand'
     LP m Inlines -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
inlineEnvironment
     LP m Inlines -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
inlineGroup
     LP m Inlines -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Char -> LP m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '-' LP m Tok -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
           Inlines -> LP m Inlines -> LP m Inlines
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option (Text -> Inlines
str "-") (Char -> LP m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '-' LP m Tok -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
             Inlines -> LP m Inlines -> LP m Inlines
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option (Text -> Inlines
str "–") (Text -> Inlines
str "—" Inlines -> LP m Tok -> LP m Inlines
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> LP m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '-')))
     LP m Inlines -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
doubleQuote
     LP m Inlines -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
singleQuote
     LP m Inlines -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Text -> Inlines
str "”" Inlines -> LP m Tok -> LP m Inlines
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ LP m Tok -> LP m Tok
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (Char -> LP m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '\'' LP m Tok -> LP m Tok -> LP m Tok
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Char -> LP m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '\''))
     LP m Inlines -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Text -> Inlines
str "”" Inlines -> LP m Tok -> LP m Inlines
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> LP m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '”')
     LP m Inlines -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Text -> Inlines
str "’" Inlines -> LP m Tok -> LP m Inlines
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> LP m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '\'')
     LP m Inlines -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Text -> Inlines
str "’" Inlines -> LP m Tok -> LP m Inlines
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> LP m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '’')
     LP m Inlines -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Text -> Inlines
str "\160" Inlines -> LP m Tok -> LP m Inlines
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> LP m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '~')
     LP m Inlines -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
dollarsMath
     LP m Inlines -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Extension -> ParsecT [Tok] LaTeXState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParserT s st m ()
guardEnabled Extension
Ext_literate_haskell ParsecT [Tok] LaTeXState m () -> LP m Tok -> LP m Tok
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Char -> LP m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '|' LP m Tok -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
doLHSverb)
     LP m Inlines -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Text -> Inlines
str (Text -> Inlines) -> (Char -> Text) -> Char -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Text
T.singleton (Char -> Inlines)
-> ParsecT [Tok] LaTeXState m Char -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m Char
forall (m :: * -> *). PandocMonad m => LP m Char
primEscape)
     LP m Inlines -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
regularSymbol
     LP m Inlines -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (do Tok
res <- SourceName -> LP m Tok
forall (m :: * -> *). PandocMonad m => SourceName -> LP m Tok
symbolIn "#^'`\"[]&"
             SourcePos
pos <- ParsecT [Tok] LaTeXState m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
             let s :: Text
s = Tok -> Text
untoken Tok
res
             LogMessage -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LogMessage -> m ()
report (LogMessage -> ParsecT [Tok] LaTeXState m ())
-> LogMessage -> ParsecT [Tok] LaTeXState m ()
forall a b. (a -> b) -> a -> b
$ Text -> SourcePos -> LogMessage
ParsingUnescaped Text
s SourcePos
pos
             Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> LP m Inlines) -> Inlines -> LP m Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
str Text
s)

inlines :: PandocMonad m => LP m Inlines
inlines :: LP m Inlines
inlines = [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines)
-> ParsecT [Tok] LaTeXState m [Inlines] -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines -> ParsecT [Tok] LaTeXState m [Inlines]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
inline

-- block elements:

begin_ :: PandocMonad m => Text -> LP m ()
begin_ :: Text -> LP m ()
begin_ t :: Text
t = LP m () -> LP m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (do
  Text -> LP m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "begin"
  LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces
  Text
txt <- [Tok] -> Text
untokenize ([Tok] -> Text)
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
  Bool -> LP m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Text
t Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
txt)) LP m () -> SourceName -> LP m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> SourceName -> ParsecT s u m a
<?> ("\\begin{" SourceName -> SourceName -> SourceName
forall a. [a] -> [a] -> [a]
++ Text -> SourceName
T.unpack Text
t SourceName -> SourceName -> SourceName
forall a. [a] -> [a] -> [a]
++ "}")

end_ :: PandocMonad m => Text -> LP m ()
end_ :: Text -> LP m ()
end_ t :: Text
t = LP m () -> LP m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (do
  Text -> LP m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "end"
  LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces
  Text
txt <- [Tok] -> Text
untokenize ([Tok] -> Text)
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
  Bool -> LP m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> LP m ()) -> Bool -> LP m ()
forall a b. (a -> b) -> a -> b
$ Text
t Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
txt) LP m () -> SourceName -> LP m ()
forall s u (m :: * -> *) a.
ParsecT s u m a -> SourceName -> ParsecT s u m a
<?> ("\\end{" SourceName -> SourceName -> SourceName
forall a. [a] -> [a] -> [a]
++ Text -> SourceName
T.unpack Text
t SourceName -> SourceName -> SourceName
forall a. [a] -> [a] -> [a]
++ "}")

preamble :: PandocMonad m => LP m Blocks
preamble :: LP m Blocks
preamble = [Blocks] -> Blocks
forall a. Monoid a => [a] -> a
mconcat ([Blocks] -> Blocks)
-> ParsecT [Tok] LaTeXState m [Blocks] -> LP m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Blocks -> ParsecT [Tok] LaTeXState m [Blocks]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many LP m Blocks
preambleBlock
  where preambleBlock :: LP m Blocks
preambleBlock =  (Blocks
forall a. Monoid a => a
mempty Blocks -> ParsecT [Tok] LaTeXState m () -> LP m Blocks
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces1)
                     LP m Blocks -> LP m Blocks -> LP m Blocks
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Text -> Blocks) -> LP m Blocks
forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
(Text -> a) -> LP m a
macroDef (Text -> Text -> Blocks
rawBlock "latex")
                     LP m Blocks -> LP m Blocks -> LP m Blocks
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Blocks
forall a. Monoid a => a
mempty Blocks -> LP m Blocks -> LP m Blocks
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
blockCommand)
                     LP m Blocks -> LP m Blocks -> LP m Blocks
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Blocks
forall a. Monoid a => a
mempty Blocks -> ParsecT [Tok] LaTeXState m [Tok] -> LP m Blocks
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced)
                     LP m Blocks -> LP m Blocks -> LP m Blocks
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (do ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (Text -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => Text -> LP m ()
begin_ "document")
                             LP m Tok
forall (m :: * -> *). PandocMonad m => LP m Tok
anyTok
                             Blocks -> LP m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
forall a. Monoid a => a
mempty)

paragraph :: PandocMonad m => LP m Blocks
paragraph :: LP m Blocks
paragraph = do
  Inlines
x <- Inlines -> Inlines
trimInlines (Inlines -> Inlines)
-> ([Inlines] -> Inlines) -> [Inlines] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines)
-> ParsecT [Tok] LaTeXState m [Inlines]
-> ParsecT [Tok] LaTeXState m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m Inlines
-> ParsecT [Tok] LaTeXState m [Inlines]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT [Tok] LaTeXState m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
inline
  if Inlines
x Inlines -> Inlines -> Bool
forall a. Eq a => a -> a -> Bool
== Inlines
forall a. Monoid a => a
mempty
     then Blocks -> LP m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
forall a. Monoid a => a
mempty
     else Blocks -> LP m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return (Blocks -> LP m Blocks) -> Blocks -> LP m Blocks
forall a b. (a -> b) -> a -> b
$ Inlines -> Blocks
para Inlines
x

rawBlockOr :: PandocMonad m => Text -> LP m Blocks -> LP m Blocks
rawBlockOr :: Text -> LP m Blocks -> LP m Blocks
rawBlockOr name :: Text
name fallback :: LP m Blocks
fallback = do
  -- if raw_tex allowed, don't process
  Bool
parseRaw <- Extension -> Extensions -> Bool
extensionEnabled Extension
Ext_raw_tex (Extensions -> Bool)
-> ParsecT [Tok] LaTeXState m Extensions
-> ParsecT [Tok] LaTeXState m Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ReaderOptions -> Extensions)
-> ParsecT [Tok] LaTeXState m Extensions
forall st s (m :: * -> *) t b.
(HasReaderOptions st, Stream s m t) =>
(ReaderOptions -> b) -> ParserT s st m b
getOption ReaderOptions -> Extensions
readerExtensions
  if Bool
parseRaw
     then Text -> Text -> Blocks
rawBlock "latex" (Text -> Blocks) -> ParsecT [Tok] LaTeXState m Text -> LP m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> Text -> ParsecT [Tok] LaTeXState m Text
forall (m :: * -> *). PandocMonad m => Text -> Text -> LP m Text
getRawCommand Text
name ("\\" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
name)
     else LP m Blocks
fallback

include :: (PandocMonad m, Monoid a) => Text -> LP m a
include :: Text -> LP m a
include name :: Text
name = do
  ParsecT [Tok] LaTeXState m Inlines -> ParsecT [Tok] LaTeXState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ParsecT [Tok] LaTeXState m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
opt
  [SourceName]
fs <- ((Text -> SourceName) -> [Text] -> [SourceName]
forall a b. (a -> b) -> [a] -> [b]
map (Text -> SourceName
T.unpack (Text -> SourceName) -> (Text -> Text) -> Text -> SourceName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
removeDoubleQuotes (Text -> Text) -> (Text -> Text) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
T.strip) ([Text] -> [SourceName])
-> ([Tok] -> [Text]) -> [Tok] -> [SourceName]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> [Text]
T.splitOn "," (Text -> [Text]) -> ([Tok] -> Text) -> [Tok] -> [Text]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
         [Tok] -> Text
untokenize) ([Tok] -> [SourceName])
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m [SourceName]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
  let addExt :: SourceName -> SourceName
addExt f :: SourceName
f = case SourceName -> SourceName
takeExtension SourceName
f of
                      ".tex" -> SourceName
f
                      ".sty" -> SourceName
f
                      -- note, we can have cc_by_4.0 for example...
                      _ | Text
name Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== "usepackage" -> SourceName -> SourceName -> SourceName
addExtension SourceName
f ".sty"
                        | Bool
otherwise -> SourceName -> SourceName -> SourceName
addExtension SourceName
f ".tex"
  [SourceName]
dirs <- ((Text -> SourceName) -> [Text] -> [SourceName]
forall a b. (a -> b) -> [a] -> [b]
map Text -> SourceName
T.unpack ([Text] -> [SourceName])
-> (Maybe Text -> [Text]) -> Maybe Text -> [SourceName]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> Text -> [Text]
splitTextBy (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
==':') (Text -> [Text]) -> (Maybe Text -> Text) -> Maybe Text -> [Text]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe ".") (Maybe Text -> [SourceName])
-> ParsecT [Tok] LaTeXState m (Maybe Text)
-> ParsecT [Tok] LaTeXState m [SourceName]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> ParsecT [Tok] LaTeXState m (Maybe Text)
forall (m :: * -> *). PandocMonad m => Text -> m (Maybe Text)
lookupEnv "TEXINPUTS"
  (SourceName -> ParsecT [Tok] LaTeXState m ())
-> [SourceName] -> ParsecT [Tok] LaTeXState m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ ([SourceName] -> SourceName -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *).
PandocMonad m =>
[SourceName] -> SourceName -> LP m ()
insertIncluded [SourceName]
dirs (SourceName -> ParsecT [Tok] LaTeXState m ())
-> (SourceName -> SourceName)
-> SourceName
-> ParsecT [Tok] LaTeXState m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SourceName -> SourceName
addExt) [SourceName]
fs
  a -> LP m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
forall a. Monoid a => a
mempty

insertIncluded :: PandocMonad m
               => [FilePath]
               -> FilePath
               -> LP m ()
insertIncluded :: [SourceName] -> SourceName -> LP m ()
insertIncluded dirs :: [SourceName]
dirs f :: SourceName
f = do
  SourcePos
pos <- ParsecT [Tok] LaTeXState m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
  [Text]
containers <- LaTeXState -> [Text]
forall st. HasIncludeFiles st => st -> [Text]
getIncludeFiles (LaTeXState -> [Text])
-> ParsecT [Tok] LaTeXState m LaTeXState
-> ParsecT [Tok] LaTeXState m [Text]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m LaTeXState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  Bool -> LP m () -> LP m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (SourceName -> Text
T.pack SourceName
f Text -> [Text] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Text]
containers) (LP m () -> LP m ()) -> LP m () -> LP m ()
forall a b. (a -> b) -> a -> b
$
    PandocError -> LP m ()
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (PandocError -> LP m ()) -> PandocError -> LP m ()
forall a b. (a -> b) -> a -> b
$ Text -> PandocError
PandocParseError (Text -> PandocError) -> Text -> PandocError
forall a b. (a -> b) -> a -> b
$ SourceName -> Text
T.pack (SourceName -> Text) -> SourceName -> Text
forall a b. (a -> b) -> a -> b
$ "Include file loop at " SourceName -> SourceName -> SourceName
forall a. [a] -> [a] -> [a]
++ SourcePos -> SourceName
forall a. Show a => a -> SourceName
show SourcePos
pos
  (LaTeXState -> LaTeXState) -> LP m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((LaTeXState -> LaTeXState) -> LP m ())
-> (LaTeXState -> LaTeXState) -> LP m ()
forall a b. (a -> b) -> a -> b
$ Text -> LaTeXState -> LaTeXState
forall st. HasIncludeFiles st => Text -> st -> st
addIncludeFile (Text -> LaTeXState -> LaTeXState)
-> Text -> LaTeXState -> LaTeXState
forall a b. (a -> b) -> a -> b
$ SourceName -> Text
T.pack SourceName
f
  Maybe Text
mbcontents <- [SourceName]
-> SourceName -> ParsecT [Tok] LaTeXState m (Maybe Text)
forall (m :: * -> *).
PandocMonad m =>
[SourceName] -> SourceName -> m (Maybe Text)
readFileFromDirs [SourceName]
dirs SourceName
f
  Text
contents <- case Maybe Text
mbcontents of
                   Just s :: Text
s -> Text -> ParsecT [Tok] LaTeXState m Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
s
                   Nothing -> do
                     LogMessage -> LP m ()
forall (m :: * -> *). PandocMonad m => LogMessage -> m ()
report (LogMessage -> LP m ()) -> LogMessage -> LP m ()
forall a b. (a -> b) -> a -> b
$ Text -> SourcePos -> LogMessage
CouldNotLoadIncludeFile (SourceName -> Text
T.pack SourceName
f) SourcePos
pos
                     Text -> ParsecT [Tok] LaTeXState m Text
forall (m :: * -> *) a. Monad m => a -> m a
return ""
  ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *) s u. Monad m => ParsecT s u m s
getInput ParsecT [Tok] LaTeXState m [Tok] -> ([Tok] -> LP m ()) -> LP m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= [Tok] -> LP m ()
forall (m :: * -> *) s u. Monad m => s -> ParsecT s u m ()
setInput ([Tok] -> LP m ()) -> ([Tok] -> [Tok]) -> [Tok] -> LP m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (SourceName -> Text -> [Tok]
tokenize SourceName
f Text
contents [Tok] -> [Tok] -> [Tok]
forall a. [a] -> [a] -> [a]
++)
  (LaTeXState -> LaTeXState) -> LP m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState LaTeXState -> LaTeXState
forall st. HasIncludeFiles st => st -> st
dropLatestIncludeFile

addMeta :: PandocMonad m => ToMetaValue a => Text -> a -> LP m ()
addMeta :: Text -> a -> LP m ()
addMeta field :: Text
field val :: a
val = (LaTeXState -> LaTeXState) -> LP m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((LaTeXState -> LaTeXState) -> LP m ())
-> (LaTeXState -> LaTeXState) -> LP m ()
forall a b. (a -> b) -> a -> b
$ \st :: LaTeXState
st ->
   LaTeXState
st{ sMeta :: Meta
sMeta = Text -> a -> Meta -> Meta
forall a. ToMetaValue a => Text -> a -> Meta -> Meta
addMetaField Text
field a
val (Meta -> Meta) -> Meta -> Meta
forall a b. (a -> b) -> a -> b
$ LaTeXState -> Meta
sMeta LaTeXState
st }

authors :: PandocMonad m => LP m ()
authors :: LP m ()
authors = LP m () -> LP m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (LP m () -> LP m ()) -> LP m () -> LP m ()
forall a b. (a -> b) -> a -> b
$ do
  LP m Tok
forall (m :: * -> *). PandocMonad m => LP m Tok
bgroup
  let oneAuthor :: ParsecT [Tok] LaTeXState m Inlines
oneAuthor = [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines)
-> ParsecT [Tok] LaTeXState m [Inlines]
-> ParsecT [Tok] LaTeXState m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
       ParsecT [Tok] LaTeXState m Inlines
-> ParsecT [Tok] LaTeXState m [Inlines]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (LP m Tok -> LP m ()
forall b s (m :: * -> *) a st.
(Show b, Stream s m a) =>
ParserT s st m b -> ParserT s st m ()
notFollowedBy' (Text -> LP m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "and") LP m ()
-> ParsecT [Tok] LaTeXState m Inlines
-> ParsecT [Tok] LaTeXState m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
               (ParsecT [Tok] LaTeXState m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
inline ParsecT [Tok] LaTeXState m Inlines
-> ParsecT [Tok] LaTeXState m Inlines
-> ParsecT [Tok] LaTeXState m Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Inlines
forall a. Monoid a => a
mempty Inlines
-> ParsecT [Tok] LaTeXState m Blocks
-> ParsecT [Tok] LaTeXState m Inlines
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT [Tok] LaTeXState m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
blockCommand))
               -- skip e.g. \vspace{10pt}
  [Inlines]
auths <- ParsecT [Tok] LaTeXState m Inlines
-> LP m Tok -> ParsecT [Tok] LaTeXState m [Inlines]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
sepBy ParsecT [Tok] LaTeXState m Inlines
oneAuthor (Text -> LP m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "and")
  LP m Tok
forall (m :: * -> *). PandocMonad m => LP m Tok
egroup
  Text -> [Inlines] -> LP m ()
forall (m :: * -> *) a.
(PandocMonad m, ToMetaValue a) =>
Text -> a -> LP m ()
addMeta "author" ((Inlines -> Inlines) -> [Inlines] -> [Inlines]
forall a b. (a -> b) -> [a] -> [b]
map Inlines -> Inlines
trimInlines [Inlines]
auths)

macroDef :: (PandocMonad m, Monoid a) => (Text -> a) -> LP m a
macroDef :: (Text -> a) -> LP m a
macroDef constructor :: Text -> a
constructor = do
    (_, s :: [Tok]
s) <- LP m () -> LP m ((), [Tok])
forall (m :: * -> *) a. PandocMonad m => LP m a -> LP m (a, [Tok])
withRaw (LP m ()
commandDef LP m () -> LP m () -> LP m ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> LP m ()
environmentDef)
    (Text -> a
constructor ([Tok] -> Text
untokenize [Tok]
s) a -> LP m () -> LP m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$
      Extension -> LP m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParserT s st m ()
guardDisabled Extension
Ext_latex_macros)
     LP m a -> LP m a -> LP m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> a -> LP m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
forall a. Monoid a => a
mempty
  where commandDef :: LP m ()
commandDef = do
          (name :: Text
name, macro' :: Macro
macro') <- LP m (Text, Macro)
forall (m :: * -> *). PandocMonad m => LP m (Text, Macro)
newcommand LP m (Text, Macro) -> LP m (Text, Macro) -> LP m (Text, Macro)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> LP m (Text, Macro)
forall (m :: * -> *). PandocMonad m => LP m (Text, Macro)
letmacro LP m (Text, Macro) -> LP m (Text, Macro) -> LP m (Text, Macro)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> LP m (Text, Macro)
forall (m :: * -> *). PandocMonad m => LP m (Text, Macro)
defmacro
          Extension -> LP m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParserT s st m ()
guardDisabled Extension
Ext_latex_macros LP m () -> LP m () -> LP m ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
           (LaTeXState -> LaTeXState) -> LP m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState (\s :: LaTeXState
s -> LaTeXState
s{ sMacros :: Map Text Macro
sMacros = Text -> Macro -> Map Text Macro -> Map Text Macro
forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert Text
name Macro
macro' (LaTeXState -> Map Text Macro
sMacros LaTeXState
s) })
        environmentDef :: LP m ()
environmentDef = do
          Maybe (Text, Macro, Macro)
mbenv <- LP m (Maybe (Text, Macro, Macro))
forall (m :: * -> *).
PandocMonad m =>
LP m (Maybe (Text, Macro, Macro))
newenvironment
          case Maybe (Text, Macro, Macro)
mbenv of
            Nothing -> () -> LP m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
            Just (name :: Text
name, macro1 :: Macro
macro1, macro2 :: Macro
macro2) ->
              Extension -> LP m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParserT s st m ()
guardDisabled Extension
Ext_latex_macros LP m () -> LP m () -> LP m ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
                do (LaTeXState -> LaTeXState) -> LP m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((LaTeXState -> LaTeXState) -> LP m ())
-> (LaTeXState -> LaTeXState) -> LP m ()
forall a b. (a -> b) -> a -> b
$ \s :: LaTeXState
s -> LaTeXState
s{ sMacros :: Map Text Macro
sMacros =
                    Text -> Macro -> Map Text Macro -> Map Text Macro
forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert Text
name Macro
macro1 (LaTeXState -> Map Text Macro
sMacros LaTeXState
s) }
                   (LaTeXState -> LaTeXState) -> LP m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((LaTeXState -> LaTeXState) -> LP m ())
-> (LaTeXState -> LaTeXState) -> LP m ()
forall a b. (a -> b) -> a -> b
$ \s :: LaTeXState
s -> LaTeXState
s{ sMacros :: Map Text Macro
sMacros =
                    Text -> Macro -> Map Text Macro -> Map Text Macro
forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert ("end" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
name) Macro
macro2 (LaTeXState -> Map Text Macro
sMacros LaTeXState
s) }
        -- @\newenvironment{envname}[n-args][default]{begin}{end}@
        -- is equivalent to
        -- @\newcommand{\envname}[n-args][default]{begin}@
        -- @\newcommand{\endenvname}@

letmacro :: PandocMonad m => LP m (Text, Macro)
letmacro :: LP m (Text, Macro)
letmacro = do
  Text -> LP m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "let"
  (name :: Text
name, contents :: [Tok]
contents) <- LP m (Text, [Tok]) -> LP m (Text, [Tok])
forall (m :: * -> *) a. PandocMonad m => LP m a -> LP m a
withVerbatimMode (LP m (Text, [Tok]) -> LP m (Text, [Tok]))
-> LP m (Text, [Tok]) -> LP m (Text, [Tok])
forall a b. (a -> b) -> a -> b
$ do
    Tok _ (CtrlSeq name :: Text
name) _ <- LP m Tok
forall (m :: * -> *). PandocMonad m => LP m Tok
anyControlSeq
    LP m Tok -> ParsecT [Tok] LaTeXState m (Maybe Tok)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (LP m Tok -> ParsecT [Tok] LaTeXState m (Maybe Tok))
-> LP m Tok -> ParsecT [Tok] LaTeXState m (Maybe Tok)
forall a b. (a -> b) -> a -> b
$ Char -> LP m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '='
    LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces
    -- we first parse in verbatim mode, and then expand macros,
    -- because we don't want \let\foo\bar to turn into
    -- \let\foo hello if we have previously \def\bar{hello}
    [Tok]
contents <- LP m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
bracedOrToken
    (Text, [Tok]) -> LP m (Text, [Tok])
forall (m :: * -> *) a. Monad m => a -> m a
return (Text
name, [Tok]
contents)
  [Tok]
contents' <- Int -> [Tok] -> LP m [Tok]
forall (m :: * -> *). PandocMonad m => Int -> [Tok] -> LP m [Tok]
doMacros' 0 [Tok]
contents
  (Text, Macro) -> LP m (Text, Macro)
forall (m :: * -> *) a. Monad m => a -> m a
return (Text
name, ExpansionPoint -> [ArgSpec] -> Maybe [Tok] -> [Tok] -> Macro
Macro ExpansionPoint
ExpandWhenDefined [] Maybe [Tok]
forall a. Maybe a
Nothing [Tok]
contents')

defmacro :: PandocMonad m => LP m (Text, Macro)
defmacro :: LP m (Text, Macro)
defmacro = LP m (Text, Macro) -> LP m (Text, Macro)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (LP m (Text, Macro) -> LP m (Text, Macro))
-> LP m (Text, Macro) -> LP m (Text, Macro)
forall a b. (a -> b) -> a -> b
$
  -- we use withVerbatimMode, because macros are to be expanded
  -- at point of use, not point of definition
  LP m (Text, Macro) -> LP m (Text, Macro)
forall (m :: * -> *) a. PandocMonad m => LP m a -> LP m a
withVerbatimMode (LP m (Text, Macro) -> LP m (Text, Macro))
-> LP m (Text, Macro) -> LP m (Text, Macro)
forall a b. (a -> b) -> a -> b
$ do
    Text -> LP m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "def"
    Tok _ (CtrlSeq name :: Text
name) _ <- LP m Tok
forall (m :: * -> *). PandocMonad m => LP m Tok
anyControlSeq
    [ArgSpec]
argspecs <- ParsecT [Tok] LaTeXState m ArgSpec
-> ParsecT [Tok] LaTeXState m [ArgSpec]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (ParsecT [Tok] LaTeXState m ArgSpec
forall (m :: * -> *). PandocMonad m => LP m ArgSpec
argspecArg ParsecT [Tok] LaTeXState m ArgSpec
-> ParsecT [Tok] LaTeXState m ArgSpec
-> ParsecT [Tok] LaTeXState m ArgSpec
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ParsecT [Tok] LaTeXState m ArgSpec
forall (m :: * -> *). PandocMonad m => LP m ArgSpec
argspecPattern)
    [Tok]
contents <- LP m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
bracedOrToken
    (Text, Macro) -> LP m (Text, Macro)
forall (m :: * -> *) a. Monad m => a -> m a
return (Text
name, ExpansionPoint -> [ArgSpec] -> Maybe [Tok] -> [Tok] -> Macro
Macro ExpansionPoint
ExpandWhenUsed [ArgSpec]
argspecs Maybe [Tok]
forall a. Maybe a
Nothing [Tok]
contents)

argspecArg :: PandocMonad m => LP m ArgSpec
argspecArg :: LP m ArgSpec
argspecArg = do
  Tok _ (Arg i :: Int
i) _ <- (Tok -> Bool) -> LP m Tok
forall (m :: * -> *). PandocMonad m => (Tok -> Bool) -> LP m Tok
satisfyTok Tok -> Bool
isArgTok
  ArgSpec -> LP m ArgSpec
forall (m :: * -> *) a. Monad m => a -> m a
return (ArgSpec -> LP m ArgSpec) -> ArgSpec -> LP m ArgSpec
forall a b. (a -> b) -> a -> b
$ Int -> ArgSpec
ArgNum Int
i

argspecPattern :: PandocMonad m => LP m ArgSpec
argspecPattern :: LP m ArgSpec
argspecPattern =
  [Tok] -> ArgSpec
Pattern ([Tok] -> ArgSpec)
-> ParsecT [Tok] LaTeXState m [Tok] -> LP m ArgSpec
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m Tok -> ParsecT [Tok] LaTeXState m [Tok]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ((Tok -> Bool) -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => (Tok -> Bool) -> LP m Tok
satisfyTok (\(Tok _ toktype' :: TokType
toktype' txt :: Text
txt) ->
                              (TokType
toktype' TokType -> TokType -> Bool
forall a. Eq a => a -> a -> Bool
== TokType
Symbol Bool -> Bool -> Bool
|| TokType
toktype' TokType -> TokType -> Bool
forall a. Eq a => a -> a -> Bool
== TokType
Word) Bool -> Bool -> Bool
&&
                              (Text
txt Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
/= "{" Bool -> Bool -> Bool
&& Text
txt Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
/= "\\" Bool -> Bool -> Bool
&& Text
txt Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
/= "}")))

newcommand :: PandocMonad m => LP m (Text, Macro)
newcommand :: LP m (Text, Macro)
newcommand = do
  SourcePos
pos <- ParsecT [Tok] LaTeXState m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
  Tok _ (CtrlSeq mtype :: Text
mtype) _ <- Text -> LP m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "newcommand" LP m Tok -> LP m Tok -> LP m Tok
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
                             Text -> LP m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "renewcommand" LP m Tok -> LP m Tok -> LP m Tok
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
                             Text -> LP m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "providecommand" LP m Tok -> LP m Tok -> LP m Tok
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
                             Text -> LP m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "DeclareMathOperator" LP m Tok -> LP m Tok -> LP m Tok
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
                             Text -> LP m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "DeclareRobustCommand"
  LP m (Text, Macro) -> LP m (Text, Macro)
forall (m :: * -> *) a. PandocMonad m => LP m a -> LP m a
withVerbatimMode (LP m (Text, Macro) -> LP m (Text, Macro))
-> LP m (Text, Macro) -> LP m (Text, Macro)
forall a b. (a -> b) -> a -> b
$ do
    Tok _ (CtrlSeq name :: Text
name) txt :: Text
txt <- do
      LP m Tok -> ParsecT [Tok] LaTeXState m (Maybe Tok)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Char -> LP m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '*')
      LP m Tok
forall (m :: * -> *). PandocMonad m => LP m Tok
anyControlSeq LP m Tok -> LP m Tok -> LP m Tok
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
        (Char -> LP m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '{' LP m Tok
-> ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces ParsecT [Tok] LaTeXState m () -> LP m Tok -> LP m Tok
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> LP m Tok
forall (m :: * -> *). PandocMonad m => LP m Tok
anyControlSeq LP m Tok -> ParsecT [Tok] LaTeXState m () -> LP m Tok
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces LP m Tok -> LP m Tok -> LP m Tok
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Char -> LP m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '}')
    ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces
    Int
numargs <- Int
-> ParsecT [Tok] LaTeXState m Int -> ParsecT [Tok] LaTeXState m Int
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option 0 (ParsecT [Tok] LaTeXState m Int -> ParsecT [Tok] LaTeXState m Int)
-> ParsecT [Tok] LaTeXState m Int -> ParsecT [Tok] LaTeXState m Int
forall a b. (a -> b) -> a -> b
$ ParsecT [Tok] LaTeXState m Int -> ParsecT [Tok] LaTeXState m Int
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT [Tok] LaTeXState m Int
forall (m :: * -> *). PandocMonad m => LP m Int
bracketedNum
    let argspecs :: [ArgSpec]
argspecs = (Int -> ArgSpec) -> [Int] -> [ArgSpec]
forall a b. (a -> b) -> [a] -> [b]
map Int -> ArgSpec
ArgNum [1..Int
numargs]
    ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces
    Maybe [Tok]
optarg <- Maybe [Tok]
-> ParsecT [Tok] LaTeXState m (Maybe [Tok])
-> ParsecT [Tok] LaTeXState m (Maybe [Tok])
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Maybe [Tok]
forall a. Maybe a
Nothing (ParsecT [Tok] LaTeXState m (Maybe [Tok])
 -> ParsecT [Tok] LaTeXState m (Maybe [Tok]))
-> ParsecT [Tok] LaTeXState m (Maybe [Tok])
-> ParsecT [Tok] LaTeXState m (Maybe [Tok])
forall a b. (a -> b) -> a -> b
$ [Tok] -> Maybe [Tok]
forall a. a -> Maybe a
Just ([Tok] -> Maybe [Tok])
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m (Maybe [Tok])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m [Tok]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
bracketedToks
    ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces
    [Tok]
contents' <- ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
bracedOrToken
    let contents :: [Tok]
contents =
         case Text
mtype of
              "DeclareMathOperator" ->
                 SourcePos -> TokType -> Text -> Tok
Tok SourcePos
pos (Text -> TokType
CtrlSeq "mathop") "\\mathop"
                 Tok -> [Tok] -> [Tok]
forall a. a -> [a] -> [a]
: SourcePos -> TokType -> Text -> Tok
Tok SourcePos
pos TokType
Symbol "{"
                 Tok -> [Tok] -> [Tok]
forall a. a -> [a] -> [a]
: SourcePos -> TokType -> Text -> Tok
Tok SourcePos
pos (Text -> TokType
CtrlSeq "mathrm") "\\mathrm"
                 Tok -> [Tok] -> [Tok]
forall a. a -> [a] -> [a]
: SourcePos -> TokType -> Text -> Tok
Tok SourcePos
pos TokType
Symbol "{"
                 Tok -> [Tok] -> [Tok]
forall a. a -> [a] -> [a]
: ([Tok]
contents' [Tok] -> [Tok] -> [Tok]
forall a. [a] -> [a] -> [a]
++
                   [ SourcePos -> TokType -> Text -> Tok
Tok SourcePos
pos TokType
Symbol "}", SourcePos -> TokType -> Text -> Tok
Tok SourcePos
pos TokType
Symbol "}" ])
              _                     -> [Tok]
contents'
    Map Text Macro
macros <- LaTeXState -> Map Text Macro
sMacros (LaTeXState -> Map Text Macro)
-> ParsecT [Tok] LaTeXState m LaTeXState
-> ParsecT [Tok] LaTeXState m (Map Text Macro)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m LaTeXState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
    case Text -> Map Text Macro -> Maybe Macro
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Text
name Map Text Macro
macros of
        Just macro :: Macro
macro
          | Text
mtype Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== "newcommand" -> do
              LogMessage -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LogMessage -> m ()
report (LogMessage -> ParsecT [Tok] LaTeXState m ())
-> LogMessage -> ParsecT [Tok] LaTeXState m ()
forall a b. (a -> b) -> a -> b
$ Text -> SourcePos -> LogMessage
MacroAlreadyDefined Text
txt SourcePos
pos
              (Text, Macro) -> LP m (Text, Macro)
forall (m :: * -> *) a. Monad m => a -> m a
return (Text
name, Macro
macro)
          | Text
mtype Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== "providecommand" -> (Text, Macro) -> LP m (Text, Macro)
forall (m :: * -> *) a. Monad m => a -> m a
return (Text
name, Macro
macro)
        _ -> (Text, Macro) -> LP m (Text, Macro)
forall (m :: * -> *) a. Monad m => a -> m a
return (Text
name, ExpansionPoint -> [ArgSpec] -> Maybe [Tok] -> [Tok] -> Macro
Macro ExpansionPoint
ExpandWhenUsed [ArgSpec]
argspecs Maybe [Tok]
optarg [Tok]
contents)

newenvironment :: PandocMonad m => LP m (Maybe (Text, Macro, Macro))
newenvironment :: LP m (Maybe (Text, Macro, Macro))
newenvironment = do
  SourcePos
pos <- ParsecT [Tok] LaTeXState m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
  Tok _ (CtrlSeq mtype :: Text
mtype) _ <- Text -> LP m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "newenvironment" LP m Tok -> LP m Tok -> LP m Tok
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
                             Text -> LP m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "renewenvironment" LP m Tok -> LP m Tok -> LP m Tok
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
                             Text -> LP m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "provideenvironment"
  LP m (Maybe (Text, Macro, Macro))
-> LP m (Maybe (Text, Macro, Macro))
forall (m :: * -> *) a. PandocMonad m => LP m a -> LP m a
withVerbatimMode (LP m (Maybe (Text, Macro, Macro))
 -> LP m (Maybe (Text, Macro, Macro)))
-> LP m (Maybe (Text, Macro, Macro))
-> LP m (Maybe (Text, Macro, Macro))
forall a b. (a -> b) -> a -> b
$ do
    LP m Tok -> ParsecT [Tok] LaTeXState m (Maybe Tok)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (LP m Tok -> ParsecT [Tok] LaTeXState m (Maybe Tok))
-> LP m Tok -> ParsecT [Tok] LaTeXState m (Maybe Tok)
forall a b. (a -> b) -> a -> b
$ Char -> LP m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '*'
    LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces
    Text
name <- [Tok] -> Text
untokenize ([Tok] -> Text)
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
    LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces
    Int
numargs <- Int
-> ParsecT [Tok] LaTeXState m Int -> ParsecT [Tok] LaTeXState m Int
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option 0 (ParsecT [Tok] LaTeXState m Int -> ParsecT [Tok] LaTeXState m Int)
-> ParsecT [Tok] LaTeXState m Int -> ParsecT [Tok] LaTeXState m Int
forall a b. (a -> b) -> a -> b
$ ParsecT [Tok] LaTeXState m Int -> ParsecT [Tok] LaTeXState m Int
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT [Tok] LaTeXState m Int
forall (m :: * -> *). PandocMonad m => LP m Int
bracketedNum
    LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces
    Maybe [Tok]
optarg <- Maybe [Tok]
-> ParsecT [Tok] LaTeXState m (Maybe [Tok])
-> ParsecT [Tok] LaTeXState m (Maybe [Tok])
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Maybe [Tok]
forall a. Maybe a
Nothing (ParsecT [Tok] LaTeXState m (Maybe [Tok])
 -> ParsecT [Tok] LaTeXState m (Maybe [Tok]))
-> ParsecT [Tok] LaTeXState m (Maybe [Tok])
-> ParsecT [Tok] LaTeXState m (Maybe [Tok])
forall a b. (a -> b) -> a -> b
$ [Tok] -> Maybe [Tok]
forall a. a -> Maybe a
Just ([Tok] -> Maybe [Tok])
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m (Maybe [Tok])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m [Tok]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
bracketedToks
    let argspecs :: [ArgSpec]
argspecs = (Int -> ArgSpec) -> [Int] -> [ArgSpec]
forall a b. (a -> b) -> [a] -> [b]
map (\i :: Int
i -> Int -> ArgSpec
ArgNum Int
i) [1..Int
numargs]
    [Tok]
startcontents <- LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces LP m ()
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
bracedOrToken
    [Tok]
endcontents <- LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces LP m ()
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
bracedOrToken
    Map Text Macro
macros <- LaTeXState -> Map Text Macro
sMacros (LaTeXState -> Map Text Macro)
-> ParsecT [Tok] LaTeXState m LaTeXState
-> ParsecT [Tok] LaTeXState m (Map Text Macro)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m LaTeXState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
    case Text -> Map Text Macro -> Maybe Macro
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Text
name Map Text Macro
macros of
         Just _
           | Text
mtype Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== "newenvironment" -> do
               LogMessage -> LP m ()
forall (m :: * -> *). PandocMonad m => LogMessage -> m ()
report (LogMessage -> LP m ()) -> LogMessage -> LP m ()
forall a b. (a -> b) -> a -> b
$ Text -> SourcePos -> LogMessage
MacroAlreadyDefined Text
name SourcePos
pos
               Maybe (Text, Macro, Macro) -> LP m (Maybe (Text, Macro, Macro))
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (Text, Macro, Macro)
forall a. Maybe a
Nothing
           | Text
mtype Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== "provideenvironment" ->
               Maybe (Text, Macro, Macro) -> LP m (Maybe (Text, Macro, Macro))
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (Text, Macro, Macro)
forall a. Maybe a
Nothing
         _ -> Maybe (Text, Macro, Macro) -> LP m (Maybe (Text, Macro, Macro))
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (Text, Macro, Macro) -> LP m (Maybe (Text, Macro, Macro)))
-> Maybe (Text, Macro, Macro) -> LP m (Maybe (Text, Macro, Macro))
forall a b. (a -> b) -> a -> b
$ (Text, Macro, Macro) -> Maybe (Text, Macro, Macro)
forall a. a -> Maybe a
Just (Text
name,
                      ExpansionPoint -> [ArgSpec] -> Maybe [Tok] -> [Tok] -> Macro
Macro ExpansionPoint
ExpandWhenUsed [ArgSpec]
argspecs Maybe [Tok]
optarg [Tok]
startcontents,
                      ExpansionPoint -> [ArgSpec] -> Maybe [Tok] -> [Tok] -> Macro
Macro ExpansionPoint
ExpandWhenUsed [] Maybe [Tok]
forall a. Maybe a
Nothing [Tok]
endcontents)

bracketedNum :: PandocMonad m => LP m Int
bracketedNum :: LP m Int
bracketedNum = do
  Text
ds <- [Tok] -> Text
untokenize ([Tok] -> Text)
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
bracketedToks
  case Text -> Maybe Int
forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
safeRead Text
ds of
       Just i :: Int
i -> Int -> LP m Int
forall (m :: * -> *) a. Monad m => a -> m a
return Int
i
       _      -> Int -> LP m Int
forall (m :: * -> *) a. Monad m => a -> m a
return 0

setCaption :: PandocMonad m => LP m ()
setCaption :: LP m ()
setCaption = LP m () -> LP m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (LP m () -> LP m ()) -> LP m () -> LP m ()
forall a b. (a -> b) -> a -> b
$ do
  LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts
  Inlines
ils <- LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok
  LP m () -> ParsecT [Tok] LaTeXState m (Maybe ())
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (LP m () -> ParsecT [Tok] LaTeXState m (Maybe ()))
-> LP m () -> ParsecT [Tok] LaTeXState m (Maybe ())
forall a b. (a -> b) -> a -> b
$ LP m () -> LP m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (LP m () -> LP m ()) -> LP m () -> LP m ()
forall a b. (a -> b) -> a -> b
$ LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces LP m () -> LP m () -> LP m ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
label
  (LaTeXState -> LaTeXState) -> LP m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((LaTeXState -> LaTeXState) -> LP m ())
-> (LaTeXState -> LaTeXState) -> LP m ()
forall a b. (a -> b) -> a -> b
$ \st :: LaTeXState
st -> LaTeXState
st{ sCaption :: Maybe Inlines
sCaption = Inlines -> Maybe Inlines
forall a. a -> Maybe a
Just Inlines
ils }

looseItem :: PandocMonad m => LP m Blocks
looseItem :: LP m Blocks
looseItem = do
  Bool
inListItem <- LaTeXState -> Bool
sInListItem (LaTeXState -> Bool)
-> ParsecT [Tok] LaTeXState m LaTeXState
-> ParsecT [Tok] LaTeXState m Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m LaTeXState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  Bool -> ParsecT [Tok] LaTeXState m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT [Tok] LaTeXState m ())
-> Bool -> ParsecT [Tok] LaTeXState m ()
forall a b. (a -> b) -> a -> b
$ Bool -> Bool
not Bool
inListItem
  ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts
  Blocks -> LP m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
forall a. Monoid a => a
mempty

epigraph :: PandocMonad m => LP m Blocks
epigraph :: LP m Blocks
epigraph = do
  Blocks
p1 <- LP m Blocks -> LP m Blocks
forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
grouped LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
block
  Blocks
p2 <- LP m Blocks -> LP m Blocks
forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
grouped LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
block
  Blocks -> LP m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return (Blocks -> LP m Blocks) -> Blocks -> LP m Blocks
forall a b. (a -> b) -> a -> b
$ Attr -> Blocks -> Blocks
divWith ("", ["epigraph"], []) (Blocks
p1 Blocks -> Blocks -> Blocks
forall a. Semigroup a => a -> a -> a
<> Blocks
p2)

resetCaption :: PandocMonad m => LP m ()
resetCaption :: LP m ()
resetCaption = (LaTeXState -> LaTeXState) -> LP m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((LaTeXState -> LaTeXState) -> LP m ())
-> (LaTeXState -> LaTeXState) -> LP m ()
forall a b. (a -> b) -> a -> b
$ \st :: LaTeXState
st -> LaTeXState
st{ sCaption :: Maybe Inlines
sCaption   = Maybe Inlines
forall a. Maybe a
Nothing
                                      , sLastLabel :: Maybe Text
sLastLabel = Maybe Text
forall a. Maybe a
Nothing }

section :: PandocMonad m => Attr -> Int -> LP m Blocks
section :: Attr -> Int -> LP m Blocks
section (ident :: Text
ident, classes :: [Text]
classes, kvs :: [(Text, Text)]
kvs) lvl :: Int
lvl = do
  LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts
  Inlines
contents <- LP m Inlines -> LP m Inlines
forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
grouped LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
inline
  Text
lab <- Text
-> ParsecT [Tok] LaTeXState m Text
-> ParsecT [Tok] LaTeXState m Text
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Text
ident (ParsecT [Tok] LaTeXState m Text
 -> ParsecT [Tok] LaTeXState m Text)
-> ParsecT [Tok] LaTeXState m Text
-> ParsecT [Tok] LaTeXState m Text
forall a b. (a -> b) -> a -> b
$
          ParsecT [Tok] LaTeXState m Text -> ParsecT [Tok] LaTeXState m Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces LP m ()
-> ParsecT [Tok] LaTeXState m Tok -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Text -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "label"
               ParsecT [Tok] LaTeXState m Tok -> LP m () -> LP m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces LP m ()
-> ParsecT [Tok] LaTeXState m Text
-> ParsecT [Tok] LaTeXState m Text
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Tok] -> Text
untokenize ([Tok] -> Text)
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced)
  Bool -> LP m () -> LP m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Int
lvl Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== 0) (LP m () -> LP m ()) -> LP m () -> LP m ()
forall a b. (a -> b) -> a -> b
$
    (LaTeXState -> LaTeXState) -> LP m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((LaTeXState -> LaTeXState) -> LP m ())
-> (LaTeXState -> LaTeXState) -> LP m ()
forall a b. (a -> b) -> a -> b
$ \st :: LaTeXState
st -> LaTeXState
st{ sHasChapters :: Bool
sHasChapters = Bool
True }
  Bool -> LP m () -> LP m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless ("unnumbered" Text -> [Text] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Text]
classes) (LP m () -> LP m ()) -> LP m () -> LP m ()
forall a b. (a -> b) -> a -> b
$ do
    DottedNum
hn <- LaTeXState -> DottedNum
sLastHeaderNum (LaTeXState -> DottedNum)
-> ParsecT [Tok] LaTeXState m LaTeXState
-> ParsecT [Tok] LaTeXState m DottedNum
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m LaTeXState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
    Bool
hasChapters <- LaTeXState -> Bool
sHasChapters (LaTeXState -> Bool)
-> ParsecT [Tok] LaTeXState m LaTeXState
-> ParsecT [Tok] LaTeXState m Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m LaTeXState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
    let lvl' :: Int
lvl' = Int
lvl Int -> Int -> Int
forall a. Num a => a -> a -> a
+ if Bool
hasChapters then 1 else 0
    let num :: DottedNum
num = Int -> DottedNum -> DottedNum
incrementDottedNum Int
lvl' DottedNum
hn
    (LaTeXState -> LaTeXState) -> LP m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((LaTeXState -> LaTeXState) -> LP m ())
-> (LaTeXState -> LaTeXState) -> LP m ()
forall a b. (a -> b) -> a -> b
$ \st :: LaTeXState
st -> LaTeXState
st{ sLastHeaderNum :: DottedNum
sLastHeaderNum = DottedNum
num
                           , sLabels :: Map Text [Inline]
sLabels = Text -> [Inline] -> Map Text [Inline] -> Map Text [Inline]
forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert Text
lab
                              [Text -> Inline
Str (DottedNum -> Text
renderDottedNum DottedNum
num)]
                              (LaTeXState -> Map Text [Inline]
sLabels LaTeXState
st) }
  Attr
attr' <- Attr -> Inlines -> ParserT [Tok] LaTeXState m Attr
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st, HasLogMessages st,
 HasIdentifierList st) =>
Attr -> Inlines -> ParserT s st m Attr
registerHeader (Text
lab, [Text]
classes, [(Text, Text)]
kvs) Inlines
contents
  Blocks -> LP m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return (Blocks -> LP m Blocks) -> Blocks -> LP m Blocks
forall a b. (a -> b) -> a -> b
$ Attr -> Int -> Inlines -> Blocks
headerWith Attr
attr' Int
lvl Inlines
contents

blockCommand :: PandocMonad m => LP m Blocks
blockCommand :: LP m Blocks
blockCommand = LP m Blocks -> LP m Blocks
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (LP m Blocks -> LP m Blocks) -> LP m Blocks -> LP m Blocks
forall a b. (a -> b) -> a -> b
$ do
  Tok _ (CtrlSeq name :: Text
name) txt :: Text
txt <- LP m Tok
forall (m :: * -> *). PandocMonad m => LP m Tok
anyControlSeq
  Bool -> ParsecT [Tok] LaTeXState m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT [Tok] LaTeXState m ())
-> Bool -> ParsecT [Tok] LaTeXState m ()
forall a b. (a -> b) -> a -> b
$ Text
name Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
/= "begin" Bool -> Bool -> Bool
&& Text
name Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
/= "end"
  Text
star <- Text
-> ParsecT [Tok] LaTeXState m Text
-> ParsecT [Tok] LaTeXState m Text
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option "" ("*" Text -> LP m Tok -> ParsecT [Tok] LaTeXState m Text
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> LP m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '*' ParsecT [Tok] LaTeXState m Text
-> ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
sp)
  let name' :: Text
name' = Text
name Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
star
  let names :: [Text]
names = [Text] -> [Text]
forall a. Ord a => [a] -> [a]
ordNub [Text
name', Text
name]
  let rawDefiniteBlock :: LP m Blocks
rawDefiniteBlock = do
        Bool -> ParsecT [Tok] LaTeXState m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT [Tok] LaTeXState m ())
-> Bool -> ParsecT [Tok] LaTeXState m ()
forall a b. (a -> b) -> a -> b
$ Text -> Bool
isBlockCommand Text
name
        Text
rawcontents <- Text -> Text -> ParsecT [Tok] LaTeXState m Text
forall (m :: * -> *). PandocMonad m => Text -> Text -> LP m Text
getRawCommand Text
name (Text
txt Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
star)
        (Extension -> ParsecT [Tok] LaTeXState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParserT s st m ()
guardEnabled Extension
Ext_raw_tex ParsecT [Tok] LaTeXState m () -> LP m Blocks -> LP m Blocks
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Blocks -> LP m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> Text -> Blocks
rawBlock "latex" Text
rawcontents))
          LP m Blocks -> LP m Blocks -> LP m Blocks
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Text -> LP m Blocks
forall a (m :: * -> *) s u.
(Monoid a, PandocMonad m) =>
Text -> ParserT s u m a
ignore Text
rawcontents
  -- heuristic:  if it could be either block or inline, we
  -- treat it if block if we have a sequence of block
  -- commands followed by a newline.  But we stop if we
  -- hit a \startXXX, since this might start a raw ConTeXt
  -- environment (this is important because this parser is
  -- used by the Markdown reader).
  let startCommand :: ParsecT [Tok] LaTeXState m ()
startCommand = ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m ())
-> ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m ()
forall a b. (a -> b) -> a -> b
$ do
        Tok _ (CtrlSeq n :: Text
n) _ <- LP m Tok
forall (m :: * -> *). PandocMonad m => LP m Tok
anyControlSeq
        Bool -> ParsecT [Tok] LaTeXState m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT [Tok] LaTeXState m ())
-> Bool -> ParsecT [Tok] LaTeXState m ()
forall a b. (a -> b) -> a -> b
$ "start" Text -> Text -> Bool
`T.isPrefixOf` Text
n
  let rawMaybeBlock :: LP m Blocks
rawMaybeBlock = LP m Blocks -> LP m Blocks
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (LP m Blocks -> LP m Blocks) -> LP m Blocks -> LP m Blocks
forall a b. (a -> b) -> a -> b
$ do
        Bool -> ParsecT [Tok] LaTeXState m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT [Tok] LaTeXState m ())
-> Bool -> ParsecT [Tok] LaTeXState m ()
forall a b. (a -> b) -> a -> b
$ Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ Text -> Bool
isInlineCommand Text
name
        Text
rawcontents <- Text -> Text -> ParsecT [Tok] LaTeXState m Text
forall (m :: * -> *). PandocMonad m => Text -> Text -> LP m Text
getRawCommand Text
name (Text
txt Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
star)
        Blocks
curr <- (Extension -> ParsecT [Tok] LaTeXState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParserT s st m ()
guardEnabled Extension
Ext_raw_tex ParsecT [Tok] LaTeXState m () -> LP m Blocks -> LP m Blocks
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
                    Blocks -> LP m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> Text -> Blocks
rawBlock "latex" Text
rawcontents))
                   LP m Blocks -> LP m Blocks -> LP m Blocks
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Text -> LP m Blocks
forall a (m :: * -> *) s u.
(Monoid a, PandocMonad m) =>
Text -> ParserT s u m a
ignore Text
rawcontents
        [Blocks]
rest <- LP m Blocks -> ParsecT [Tok] LaTeXState m [Blocks]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (LP m Blocks -> ParsecT [Tok] LaTeXState m [Blocks])
-> LP m Blocks -> ParsecT [Tok] LaTeXState m [Blocks]
forall a b. (a -> b) -> a -> b
$ ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy ParsecT [Tok] LaTeXState m ()
startCommand ParsecT [Tok] LaTeXState m () -> LP m Blocks -> LP m Blocks
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
blockCommand
        ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m ())
-> ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m ()
forall a b. (a -> b) -> a -> b
$ ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
blankline ParsecT [Tok] LaTeXState m ()
-> ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ParsecT [Tok] LaTeXState m ()
startCommand
        Blocks -> LP m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return (Blocks -> LP m Blocks) -> Blocks -> LP m Blocks
forall a b. (a -> b) -> a -> b
$ Blocks
curr Blocks -> Blocks -> Blocks
forall a. Semigroup a => a -> a -> a
<> [Blocks] -> Blocks
forall a. Monoid a => [a] -> a
mconcat [Blocks]
rest
  let raw :: LP m Blocks
raw = LP m Blocks
rawDefiniteBlock LP m Blocks -> LP m Blocks -> LP m Blocks
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> LP m Blocks
rawMaybeBlock
  LP m Blocks -> [Text] -> Map Text (LP m Blocks) -> LP m Blocks
forall k v. Ord k => v -> [k] -> Map k v -> v
lookupListDefault LP m Blocks
raw [Text]
names Map Text (LP m Blocks)
forall (m :: * -> *). PandocMonad m => Map Text (LP m Blocks)
blockCommands

closing :: PandocMonad m => LP m Blocks
closing :: LP m Blocks
closing = do
  Inlines
contents <- LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok
  LaTeXState
st <- ParsecT [Tok] LaTeXState m LaTeXState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  let extractInlines :: MetaValue -> [Inline]
extractInlines (MetaBlocks [Plain ys :: [Inline]
ys]) = [Inline]
ys
      extractInlines (MetaBlocks [Para ys :: [Inline]
ys ]) = [Inline]
ys
      extractInlines _                       = []
  let sigs :: Blocks
sigs = case Text -> Meta -> Maybe MetaValue
lookupMeta "author" (LaTeXState -> Meta
sMeta LaTeXState
st) of
                  Just (MetaList xs :: [MetaValue]
xs) ->
                    Inlines -> Blocks
para (Inlines -> Blocks) -> Inlines -> Blocks
forall a b. (a -> b) -> a -> b
$ Inlines -> Inlines
trimInlines (Inlines -> Inlines) -> Inlines -> Inlines
forall a b. (a -> b) -> a -> b
$ [Inline] -> Inlines
forall a. [a] -> Many a
fromList ([Inline] -> Inlines) -> [Inline] -> Inlines
forall a b. (a -> b) -> a -> b
$
                      [Inline] -> [[Inline]] -> [Inline]
forall a. [a] -> [[a]] -> [a]
intercalate [Inline
LineBreak] ([[Inline]] -> [Inline]) -> [[Inline]] -> [Inline]
forall a b. (a -> b) -> a -> b
$ (MetaValue -> [Inline]) -> [MetaValue] -> [[Inline]]
forall a b. (a -> b) -> [a] -> [b]
map MetaValue -> [Inline]
extractInlines [MetaValue]
xs
                  _ -> Blocks
forall a. Monoid a => a
mempty
  Blocks -> LP m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return (Blocks -> LP m Blocks) -> Blocks -> LP m Blocks
forall a b. (a -> b) -> a -> b
$ Inlines -> Blocks
para (Inlines -> Inlines
trimInlines Inlines
contents) Blocks -> Blocks -> Blocks
forall a. Semigroup a => a -> a -> a
<> Blocks
sigs

parbox :: PandocMonad m => LP m Blocks
parbox :: LP m Blocks
parbox = LP m Blocks -> LP m Blocks
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (LP m Blocks -> LP m Blocks) -> LP m Blocks -> LP m Blocks
forall a b. (a -> b) -> a -> b
$ do
  LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts
  LP m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced -- size
  Bool
oldInTableCell <- LaTeXState -> Bool
sInTableCell (LaTeXState -> Bool)
-> ParsecT [Tok] LaTeXState m LaTeXState
-> ParsecT [Tok] LaTeXState m Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m LaTeXState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  -- see #5711
  (LaTeXState -> LaTeXState) -> LP m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((LaTeXState -> LaTeXState) -> LP m ())
-> (LaTeXState -> LaTeXState) -> LP m ()
forall a b. (a -> b) -> a -> b
$ \st :: LaTeXState
st -> LaTeXState
st{ sInTableCell :: Bool
sInTableCell = Bool
False }
  Blocks
res <- LP m Blocks -> LP m Blocks
forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
grouped LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
block
  (LaTeXState -> LaTeXState) -> LP m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((LaTeXState -> LaTeXState) -> LP m ())
-> (LaTeXState -> LaTeXState) -> LP m ()
forall a b. (a -> b) -> a -> b
$ \st :: LaTeXState
st -> LaTeXState
st{ sInTableCell :: Bool
sInTableCell = Bool
oldInTableCell }
  Blocks -> LP m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
res

blockCommands :: PandocMonad m => M.Map Text (LP m Blocks)
blockCommands :: Map Text (LP m Blocks)
blockCommands = [(Text, LP m Blocks)] -> Map Text (LP m Blocks)
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList
   [ ("par", Blocks
forall a. Monoid a => a
mempty Blocks -> ParsecT [Tok] LaTeXState m () -> LP m Blocks
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts)
   , ("parbox",  LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
parbox)
   , ("title", Blocks
forall a. Monoid a => a
mempty Blocks -> ParsecT [Tok] LaTeXState m () -> LP m Blocks
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts ParsecT [Tok] LaTeXState m ()
-> ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
                             (LP m Inlines -> LP m Inlines
forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
grouped LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
inline LP m Inlines
-> (Inlines -> ParsecT [Tok] LaTeXState m ())
-> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> Inlines -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) a.
(PandocMonad m, ToMetaValue a) =>
Text -> a -> LP m ()
addMeta "title")
                         ParsecT [Tok] LaTeXState m ()
-> ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (LP m Blocks -> LP m Blocks
forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
grouped LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
block LP m Blocks
-> (Blocks -> ParsecT [Tok] LaTeXState m ())
-> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> Blocks -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) a.
(PandocMonad m, ToMetaValue a) =>
Text -> a -> LP m ()
addMeta "title")))
   , ("subtitle", Blocks
forall a. Monoid a => a
mempty Blocks -> ParsecT [Tok] LaTeXState m () -> LP m Blocks
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts ParsecT [Tok] LaTeXState m () -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok LP m Inlines
-> (Inlines -> ParsecT [Tok] LaTeXState m ())
-> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> Inlines -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) a.
(PandocMonad m, ToMetaValue a) =>
Text -> a -> LP m ()
addMeta "subtitle"))
   , ("author", Blocks
forall a. Monoid a => a
mempty Blocks -> ParsecT [Tok] LaTeXState m () -> LP m Blocks
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts ParsecT [Tok] LaTeXState m ()
-> ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
authors))
   -- -- in letter class, temp. store address & sig as title, author
   , ("address", Blocks
forall a. Monoid a => a
mempty Blocks -> ParsecT [Tok] LaTeXState m () -> LP m Blocks
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts ParsecT [Tok] LaTeXState m () -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok LP m Inlines
-> (Inlines -> ParsecT [Tok] LaTeXState m ())
-> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> Inlines -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) a.
(PandocMonad m, ToMetaValue a) =>
Text -> a -> LP m ()
addMeta "address"))
   , ("signature", Blocks
forall a. Monoid a => a
mempty Blocks -> ParsecT [Tok] LaTeXState m () -> LP m Blocks
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts ParsecT [Tok] LaTeXState m ()
-> ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
authors))
   , ("date", Blocks
forall a. Monoid a => a
mempty Blocks -> ParsecT [Tok] LaTeXState m () -> LP m Blocks
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts ParsecT [Tok] LaTeXState m () -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok LP m Inlines
-> (Inlines -> ParsecT [Tok] LaTeXState m ())
-> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> Inlines -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) a.
(PandocMonad m, ToMetaValue a) =>
Text -> a -> LP m ()
addMeta "date"))
   -- KOMA-Script metadata commands
   , ("extratitle", Blocks
forall a. Monoid a => a
mempty Blocks -> ParsecT [Tok] LaTeXState m () -> LP m Blocks
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts ParsecT [Tok] LaTeXState m () -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok LP m Inlines
-> (Inlines -> ParsecT [Tok] LaTeXState m ())
-> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> Inlines -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) a.
(PandocMonad m, ToMetaValue a) =>
Text -> a -> LP m ()
addMeta "extratitle"))
   , ("frontispiece", Blocks
forall a. Monoid a => a
mempty Blocks -> ParsecT [Tok] LaTeXState m () -> LP m Blocks
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts ParsecT [Tok] LaTeXState m () -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok LP m Inlines
-> (Inlines -> ParsecT [Tok] LaTeXState m ())
-> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> Inlines -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) a.
(PandocMonad m, ToMetaValue a) =>
Text -> a -> LP m ()
addMeta "frontispiece"))
   , ("titlehead", Blocks
forall a. Monoid a => a
mempty Blocks -> ParsecT [Tok] LaTeXState m () -> LP m Blocks
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts ParsecT [Tok] LaTeXState m () -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok LP m Inlines
-> (Inlines -> ParsecT [Tok] LaTeXState m ())
-> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> Inlines -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) a.
(PandocMonad m, ToMetaValue a) =>
Text -> a -> LP m ()
addMeta "titlehead"))
   , ("subject", Blocks
forall a. Monoid a => a
mempty Blocks -> ParsecT [Tok] LaTeXState m () -> LP m Blocks
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts ParsecT [Tok] LaTeXState m () -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok LP m Inlines
-> (Inlines -> ParsecT [Tok] LaTeXState m ())
-> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> Inlines -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) a.
(PandocMonad m, ToMetaValue a) =>
Text -> a -> LP m ()
addMeta "subject"))
   , ("publishers", Blocks
forall a. Monoid a => a
mempty Blocks -> ParsecT [Tok] LaTeXState m () -> LP m Blocks
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts ParsecT [Tok] LaTeXState m () -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok LP m Inlines
-> (Inlines -> ParsecT [Tok] LaTeXState m ())
-> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> Inlines -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) a.
(PandocMonad m, ToMetaValue a) =>
Text -> a -> LP m ()
addMeta "publishers"))
   , ("uppertitleback", Blocks
forall a. Monoid a => a
mempty Blocks -> ParsecT [Tok] LaTeXState m () -> LP m Blocks
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts ParsecT [Tok] LaTeXState m () -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok LP m Inlines
-> (Inlines -> ParsecT [Tok] LaTeXState m ())
-> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> Inlines -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) a.
(PandocMonad m, ToMetaValue a) =>
Text -> a -> LP m ()
addMeta "uppertitleback"))
   , ("lowertitleback", Blocks
forall a. Monoid a => a
mempty Blocks -> ParsecT [Tok] LaTeXState m () -> LP m Blocks
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts ParsecT [Tok] LaTeXState m () -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok LP m Inlines
-> (Inlines -> ParsecT [Tok] LaTeXState m ())
-> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> Inlines -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) a.
(PandocMonad m, ToMetaValue a) =>
Text -> a -> LP m ()
addMeta "lowertitleback"))
   , ("dedication", Blocks
forall a. Monoid a => a
mempty Blocks -> ParsecT [Tok] LaTeXState m () -> LP m Blocks
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts ParsecT [Tok] LaTeXState m () -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok LP m Inlines
-> (Inlines -> ParsecT [Tok] LaTeXState m ())
-> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> Inlines -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) a.
(PandocMonad m, ToMetaValue a) =>
Text -> a -> LP m ()
addMeta "dedication"))
   -- sectioning
   , ("part", Attr -> Int -> LP m Blocks
forall (m :: * -> *). PandocMonad m => Attr -> Int -> LP m Blocks
section Attr
nullAttr (-1))
   , ("part*", Attr -> Int -> LP m Blocks
forall (m :: * -> *). PandocMonad m => Attr -> Int -> LP m Blocks
section Attr
nullAttr (-1))
   , ("chapter", Attr -> Int -> LP m Blocks
forall (m :: * -> *). PandocMonad m => Attr -> Int -> LP m Blocks
section Attr
nullAttr 0)
   , ("chapter*", Attr -> Int -> LP m Blocks
forall (m :: * -> *). PandocMonad m => Attr -> Int -> LP m Blocks
section ("",["unnumbered"],[]) 0)
   , ("section", Attr -> Int -> LP m Blocks
forall (m :: * -> *). PandocMonad m => Attr -> Int -> LP m Blocks
section Attr
nullAttr 1)
   , ("section*", Attr -> Int -> LP m Blocks
forall (m :: * -> *). PandocMonad m => Attr -> Int -> LP m Blocks
section ("",["unnumbered"],[]) 1)
   , ("subsection", Attr -> Int -> LP m Blocks
forall (m :: * -> *). PandocMonad m => Attr -> Int -> LP m Blocks
section Attr
nullAttr 2)
   , ("subsection*", Attr -> Int -> LP m Blocks
forall (m :: * -> *). PandocMonad m => Attr -> Int -> LP m Blocks
section ("",["unnumbered"],[]) 2)
   , ("subsubsection", Attr -> Int -> LP m Blocks
forall (m :: * -> *). PandocMonad m => Attr -> Int -> LP m Blocks
section Attr
nullAttr 3)
   , ("subsubsection*", Attr -> Int -> LP m Blocks
forall (m :: * -> *). PandocMonad m => Attr -> Int -> LP m Blocks
section ("",["unnumbered"],[]) 3)
   , ("paragraph", Attr -> Int -> LP m Blocks
forall (m :: * -> *). PandocMonad m => Attr -> Int -> LP m Blocks
section Attr
nullAttr 4)
   , ("paragraph*", Attr -> Int -> LP m Blocks
forall (m :: * -> *). PandocMonad m => Attr -> Int -> LP m Blocks
section ("",["unnumbered"],[]) 4)
   , ("subparagraph", Attr -> Int -> LP m Blocks
forall (m :: * -> *). PandocMonad m => Attr -> Int -> LP m Blocks
section Attr
nullAttr 5)
   , ("subparagraph*", Attr -> Int -> LP m Blocks
forall (m :: * -> *). PandocMonad m => Attr -> Int -> LP m Blocks
section ("",["unnumbered"],[]) 5)
   -- beamer slides
   , ("frametitle", Attr -> Int -> LP m Blocks
forall (m :: * -> *). PandocMonad m => Attr -> Int -> LP m Blocks
section Attr
nullAttr 3)
   , ("framesubtitle", Attr -> Int -> LP m Blocks
forall (m :: * -> *). PandocMonad m => Attr -> Int -> LP m Blocks
section Attr
nullAttr 4)
   -- letters
   , ("opening", (Inlines -> Blocks
para (Inlines -> Blocks) -> (Inlines -> Inlines) -> Inlines -> Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> Inlines
trimInlines) (Inlines -> Blocks) -> LP m Inlines -> LP m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts ParsecT [Tok] LaTeXState m () -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok))
   , ("closing", ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts ParsecT [Tok] LaTeXState m () -> LP m Blocks -> LP m Blocks
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
closing)
   -- memoir
   , ("plainbreak", LP m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced LP m [Tok] -> LP m Blocks -> LP m Blocks
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Blocks -> LP m Blocks
forall (f :: * -> *) a. Applicative f => a -> f a
pure Blocks
horizontalRule)
   , ("plainbreak*", LP m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced LP m [Tok] -> LP m Blocks -> LP m Blocks
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Blocks -> LP m Blocks
forall (f :: * -> *) a. Applicative f => a -> f a
pure Blocks
horizontalRule)
   , ("fancybreak", LP m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced LP m [Tok] -> LP m Blocks -> LP m Blocks
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Blocks -> LP m Blocks
forall (f :: * -> *) a. Applicative f => a -> f a
pure Blocks
horizontalRule)
   , ("fancybreak*", LP m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced LP m [Tok] -> LP m Blocks -> LP m Blocks
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Blocks -> LP m Blocks
forall (f :: * -> *) a. Applicative f => a -> f a
pure Blocks
horizontalRule)
   , ("plainfancybreak", LP m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced LP m [Tok] -> LP m [Tok] -> LP m [Tok]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> LP m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced LP m [Tok] -> LP m [Tok] -> LP m [Tok]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> LP m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced LP m [Tok] -> LP m Blocks -> LP m Blocks
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Blocks -> LP m Blocks
forall (f :: * -> *) a. Applicative f => a -> f a
pure Blocks
horizontalRule)
   , ("plainfancybreak*", LP m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced LP m [Tok] -> LP m [Tok] -> LP m [Tok]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> LP m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced LP m [Tok] -> LP m [Tok] -> LP m [Tok]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> LP m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced LP m [Tok] -> LP m Blocks -> LP m Blocks
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Blocks -> LP m Blocks
forall (f :: * -> *) a. Applicative f => a -> f a
pure Blocks
horizontalRule)
   , ("pfbreak", Blocks -> LP m Blocks
forall (f :: * -> *) a. Applicative f => a -> f a
pure Blocks
horizontalRule)
   , ("pfbreak*", Blocks -> LP m Blocks
forall (f :: * -> *) a. Applicative f => a -> f a
pure Blocks
horizontalRule)
   --
   , ("hrule", Blocks -> LP m Blocks
forall (f :: * -> *) a. Applicative f => a -> f a
pure Blocks
horizontalRule)
   , ("strut", Blocks -> LP m Blocks
forall (f :: * -> *) a. Applicative f => a -> f a
pure Blocks
forall a. Monoid a => a
mempty)
   , ("rule", ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts ParsecT [Tok] LaTeXState m () -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok LP m Inlines -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok LP m Inlines -> LP m Blocks -> LP m Blocks
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Blocks -> LP m Blocks
forall (f :: * -> *) a. Applicative f => a -> f a
pure Blocks
horizontalRule)
   , ("item", LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
looseItem)
   , ("documentclass", ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts ParsecT [Tok] LaTeXState m () -> LP m [Tok] -> LP m [Tok]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> LP m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced LP m [Tok] -> LP m Blocks -> LP m Blocks
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
preamble)
   , ("centerline", (Inlines -> Blocks
para (Inlines -> Blocks) -> (Inlines -> Inlines) -> Inlines -> Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> Inlines
trimInlines) (Inlines -> Blocks) -> LP m Inlines -> LP m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts ParsecT [Tok] LaTeXState m () -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok))
   , ("caption", Blocks
forall a. Monoid a => a
mempty Blocks -> ParsecT [Tok] LaTeXState m () -> LP m Blocks
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
setCaption)
   , ("bibliography", Blocks
forall a. Monoid a => a
mempty Blocks -> ParsecT [Tok] LaTeXState m () -> LP m Blocks
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts ParsecT [Tok] LaTeXState m () -> LP m [Tok] -> LP m [Tok]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> LP m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced LP m [Tok]
-> ([Tok] -> ParsecT [Tok] LaTeXState m ())
-> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
         Text -> [Inlines] -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) a.
(PandocMonad m, ToMetaValue a) =>
Text -> a -> LP m ()
addMeta "bibliography" ([Inlines] -> ParsecT [Tok] LaTeXState m ())
-> ([Tok] -> [Inlines]) -> [Tok] -> ParsecT [Tok] LaTeXState m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> [Inlines]
splitBibs (Text -> [Inlines]) -> ([Tok] -> Text) -> [Tok] -> [Inlines]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize))
   , ("addbibresource", Blocks
forall a. Monoid a => a
mempty Blocks -> ParsecT [Tok] LaTeXState m () -> LP m Blocks
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts ParsecT [Tok] LaTeXState m () -> LP m [Tok] -> LP m [Tok]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> LP m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced LP m [Tok]
-> ([Tok] -> ParsecT [Tok] LaTeXState m ())
-> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
         Text -> [Inlines] -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) a.
(PandocMonad m, ToMetaValue a) =>
Text -> a -> LP m ()
addMeta "bibliography" ([Inlines] -> ParsecT [Tok] LaTeXState m ())
-> ([Tok] -> [Inlines]) -> [Tok] -> ParsecT [Tok] LaTeXState m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> [Inlines]
splitBibs (Text -> [Inlines]) -> ([Tok] -> Text) -> [Tok] -> [Inlines]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize))
   , ("endinput", Blocks
forall a. Monoid a => a
mempty Blocks -> ParsecT [Tok] LaTeXState m () -> LP m Blocks
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ LP m Inlines -> ParsecT [Tok] LaTeXState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
   -- includes
   , ("lstinputlisting", LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
inputListing)
   , ("inputminted", LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
inputMinted)
   , ("graphicspath", LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
graphicsPath)
   -- polyglossia
   , ("setdefaultlanguage", LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
setDefaultLanguage)
   , ("setmainlanguage", LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
setDefaultLanguage)
   -- hyperlink
   , ("hypertarget", LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
hypertargetBlock)
   -- LaTeX colors
   , ("textcolor", Text -> LP m Blocks
forall (m :: * -> *). PandocMonad m => Text -> LP m Blocks
coloredBlock "color")
   , ("colorbox", Text -> LP m Blocks
forall (m :: * -> *). PandocMonad m => Text -> LP m Blocks
coloredBlock "background-color")
   -- csquotes
   , ("blockquote", Bool -> Maybe Text -> LP m Blocks
forall (m :: * -> *).
PandocMonad m =>
Bool -> Maybe Text -> LP m Blocks
blockquote Bool
False Maybe Text
forall a. Maybe a
Nothing)
   , ("blockcquote", Bool -> Maybe Text -> LP m Blocks
forall (m :: * -> *).
PandocMonad m =>
Bool -> Maybe Text -> LP m Blocks
blockquote Bool
True Maybe Text
forall a. Maybe a
Nothing)
   , ("foreignblockquote", LP m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced LP m [Tok] -> ([Tok] -> LP m Blocks) -> LP m Blocks
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Bool -> Maybe Text -> LP m Blocks
forall (m :: * -> *).
PandocMonad m =>
Bool -> Maybe Text -> LP m Blocks
blockquote Bool
False (Maybe Text -> LP m Blocks)
-> ([Tok] -> Maybe Text) -> [Tok] -> LP m Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Maybe Text
forall a. a -> Maybe a
Just (Text -> Maybe Text) -> ([Tok] -> Text) -> [Tok] -> Maybe Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize)
   , ("foreignblockcquote", LP m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced LP m [Tok] -> ([Tok] -> LP m Blocks) -> LP m Blocks
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Bool -> Maybe Text -> LP m Blocks
forall (m :: * -> *).
PandocMonad m =>
Bool -> Maybe Text -> LP m Blocks
blockquote Bool
True (Maybe Text -> LP m Blocks)
-> ([Tok] -> Maybe Text) -> [Tok] -> LP m Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Maybe Text
forall a. a -> Maybe a
Just (Text -> Maybe Text) -> ([Tok] -> Text) -> [Tok] -> Maybe Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize)
   , ("hyphenblockquote", LP m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced LP m [Tok] -> ([Tok] -> LP m Blocks) -> LP m Blocks
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Bool -> Maybe Text -> LP m Blocks
forall (m :: * -> *).
PandocMonad m =>
Bool -> Maybe Text -> LP m Blocks
blockquote Bool
False (Maybe Text -> LP m Blocks)
-> ([Tok] -> Maybe Text) -> [Tok] -> LP m Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Maybe Text
forall a. a -> Maybe a
Just (Text -> Maybe Text) -> ([Tok] -> Text) -> [Tok] -> Maybe Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize)
   , ("hyphenblockcquote", LP m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced LP m [Tok] -> ([Tok] -> LP m Blocks) -> LP m Blocks
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Bool -> Maybe Text -> LP m Blocks
forall (m :: * -> *).
PandocMonad m =>
Bool -> Maybe Text -> LP m Blocks
blockquote Bool
True (Maybe Text -> LP m Blocks)
-> ([Tok] -> Maybe Text) -> [Tok] -> LP m Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Maybe Text
forall a. a -> Maybe a
Just (Text -> Maybe Text) -> ([Tok] -> Text) -> [Tok] -> Maybe Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize)
   -- include
   , ("include", Text -> LP m Blocks -> LP m Blocks
forall (m :: * -> *).
PandocMonad m =>
Text -> LP m Blocks -> LP m Blocks
rawBlockOr "include" (LP m Blocks -> LP m Blocks) -> LP m Blocks -> LP m Blocks
forall a b. (a -> b) -> a -> b
$ Text -> LP m Blocks
forall (m :: * -> *) a. (PandocMonad m, Monoid a) => Text -> LP m a
include "include")
   , ("input", Text -> LP m Blocks -> LP m Blocks
forall (m :: * -> *).
PandocMonad m =>
Text -> LP m Blocks -> LP m Blocks
rawBlockOr "input" (LP m Blocks -> LP m Blocks) -> LP m Blocks -> LP m Blocks
forall a b. (a -> b) -> a -> b
$ Text -> LP m Blocks
forall (m :: * -> *) a. (PandocMonad m, Monoid a) => Text -> LP m a
include "input")
   , ("subfile", Text -> LP m Blocks -> LP m Blocks
forall (m :: * -> *).
PandocMonad m =>
Text -> LP m Blocks -> LP m Blocks
rawBlockOr "subfile" (LP m Blocks -> LP m Blocks) -> LP m Blocks -> LP m Blocks
forall a b. (a -> b) -> a -> b
$ Text -> LP m Blocks
forall (m :: * -> *) a. (PandocMonad m, Monoid a) => Text -> LP m a
include "subfile")
   , ("usepackage", Text -> LP m Blocks -> LP m Blocks
forall (m :: * -> *).
PandocMonad m =>
Text -> LP m Blocks -> LP m Blocks
rawBlockOr "usepackage" (LP m Blocks -> LP m Blocks) -> LP m Blocks -> LP m Blocks
forall a b. (a -> b) -> a -> b
$ Text -> LP m Blocks
forall (m :: * -> *) a. (PandocMonad m, Monoid a) => Text -> LP m a
include "usepackage")
   -- preamble
   , ("PackageError", Blocks
forall a. Monoid a => a
mempty Blocks -> LP m [Tok] -> LP m Blocks
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (LP m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced LP m [Tok] -> LP m [Tok] -> LP m [Tok]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> LP m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced LP m [Tok] -> LP m [Tok] -> LP m [Tok]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> LP m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced))
   -- epigraph package
   , ("epigraph", LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
epigraph)
   ]


environments :: PandocMonad m => M.Map Text (LP m Blocks)
environments :: Map Text (LP m Blocks)
environments = [(Text, LP m Blocks)] -> Map Text (LP m Blocks)
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList
   [ ("document", Text -> LP m Blocks -> LP m Blocks
forall (m :: * -> *) a. PandocMonad m => Text -> LP m a -> LP m a
env "document" LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks)
   , ("abstract", Blocks
forall a. Monoid a => a
mempty Blocks -> ParsecT [Tok] LaTeXState m () -> LP m Blocks
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (Text -> LP m Blocks -> LP m Blocks
forall (m :: * -> *) a. PandocMonad m => Text -> LP m a -> LP m a
env "abstract" LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks LP m Blocks
-> (Blocks -> ParsecT [Tok] LaTeXState m ())
-> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> Blocks -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) a.
(PandocMonad m, ToMetaValue a) =>
Text -> a -> LP m ()
addMeta "abstract"))
   , ("sloppypar", Text -> LP m Blocks -> LP m Blocks
forall (m :: * -> *) a. PandocMonad m => Text -> LP m a -> LP m a
env "sloppypar" (LP m Blocks -> LP m Blocks) -> LP m Blocks -> LP m Blocks
forall a b. (a -> b) -> a -> b
$ LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks)
   , ("letter", Text -> LP m Blocks -> LP m Blocks
forall (m :: * -> *) a. PandocMonad m => Text -> LP m a -> LP m a
env "letter" LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
letterContents)
   , ("minipage", Text -> LP m Blocks -> LP m Blocks
forall (m :: * -> *) a. PandocMonad m => Text -> LP m a -> LP m a
env "minipage" (LP m Blocks -> LP m Blocks) -> LP m Blocks -> LP m Blocks
forall a b. (a -> b) -> a -> b
$
          ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts ParsecT [Tok] LaTeXState m ()
-> ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces ParsecT [Tok] LaTeXState m ()
-> ParsecT [Tok] LaTeXState m (Maybe [Tok])
-> ParsecT [Tok] LaTeXState m (Maybe [Tok])
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m (Maybe [Tok])
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced ParsecT [Tok] LaTeXState m (Maybe [Tok])
-> ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces ParsecT [Tok] LaTeXState m () -> LP m Blocks -> LP m Blocks
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks)
   , ("figure", Text -> LP m Blocks -> LP m Blocks
forall (m :: * -> *) a. PandocMonad m => Text -> LP m a -> LP m a
env "figure" (LP m Blocks -> LP m Blocks) -> LP m Blocks -> LP m Blocks
forall a b. (a -> b) -> a -> b
$ ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts ParsecT [Tok] LaTeXState m () -> LP m Blocks -> LP m Blocks
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
figure)
   , ("subfigure", Text -> LP m Blocks -> LP m Blocks
forall (m :: * -> *) a. PandocMonad m => Text -> LP m a -> LP m a
env "subfigure" (LP m Blocks -> LP m Blocks) -> LP m Blocks -> LP m Blocks
forall a b. (a -> b) -> a -> b
$ ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts ParsecT [Tok] LaTeXState m ()
-> ParsecT [Tok] LaTeXState m Inlines
-> ParsecT [Tok] LaTeXState m Inlines
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT [Tok] LaTeXState m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok ParsecT [Tok] LaTeXState m Inlines -> LP m Blocks -> LP m Blocks
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
figure)
   , ("center", Text -> LP m Blocks -> LP m Blocks
forall (m :: * -> *) a. PandocMonad m => Text -> LP m a -> LP m a
env "center" LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks)
   , ("longtable",  Text -> LP m Blocks -> LP m Blocks
forall (m :: * -> *) a. PandocMonad m => Text -> LP m a -> LP m a
env "longtable" (LP m Blocks -> LP m Blocks) -> LP m Blocks -> LP m Blocks
forall a b. (a -> b) -> a -> b
$
          ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
resetCaption ParsecT [Tok] LaTeXState m () -> LP m Blocks -> LP m Blocks
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Text -> Bool -> LP m Blocks
forall (m :: * -> *). PandocMonad m => Text -> Bool -> LP m Blocks
simpTable "longtable" Bool
False LP m Blocks -> (Blocks -> LP m Blocks) -> LP m Blocks
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Blocks -> LP m Blocks
forall (m :: * -> *). PandocMonad m => Blocks -> LP m Blocks
addTableCaption)
   , ("table",  Text -> LP m Blocks -> LP m Blocks
forall (m :: * -> *) a. PandocMonad m => Text -> LP m a -> LP m a
env "table" (LP m Blocks -> LP m Blocks) -> LP m Blocks -> LP m Blocks
forall a b. (a -> b) -> a -> b
$
          ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts ParsecT [Tok] LaTeXState m ()
-> ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
resetCaption ParsecT [Tok] LaTeXState m () -> LP m Blocks -> LP m Blocks
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks LP m Blocks -> (Blocks -> LP m Blocks) -> LP m Blocks
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Blocks -> LP m Blocks
forall (m :: * -> *). PandocMonad m => Blocks -> LP m Blocks
addTableCaption)
   , ("tabular*", Text -> LP m Blocks -> LP m Blocks
forall (m :: * -> *) a. PandocMonad m => Text -> LP m a -> LP m a
env "tabular*" (LP m Blocks -> LP m Blocks) -> LP m Blocks -> LP m Blocks
forall a b. (a -> b) -> a -> b
$ Text -> Bool -> LP m Blocks
forall (m :: * -> *). PandocMonad m => Text -> Bool -> LP m Blocks
simpTable "tabular*" Bool
True)
   , ("tabularx", Text -> LP m Blocks -> LP m Blocks
forall (m :: * -> *) a. PandocMonad m => Text -> LP m a -> LP m a
env "tabularx" (LP m Blocks -> LP m Blocks) -> LP m Blocks -> LP m Blocks
forall a b. (a -> b) -> a -> b
$ Text -> Bool -> LP m Blocks
forall (m :: * -> *). PandocMonad m => Text -> Bool -> LP m Blocks
simpTable "tabularx" Bool
True)
   , ("tabular", Text -> LP m Blocks -> LP m Blocks
forall (m :: * -> *) a. PandocMonad m => Text -> LP m a -> LP m a
env "tabular"  (LP m Blocks -> LP m Blocks) -> LP m Blocks -> LP m Blocks
forall a b. (a -> b) -> a -> b
$ Text -> Bool -> LP m Blocks
forall (m :: * -> *). PandocMonad m => Text -> Bool -> LP m Blocks
simpTable "tabular" Bool
False)
   , ("quote", Blocks -> Blocks
blockQuote (Blocks -> Blocks) -> LP m Blocks -> LP m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> LP m Blocks -> LP m Blocks
forall (m :: * -> *) a. PandocMonad m => Text -> LP m a -> LP m a
env "quote" LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks)
   , ("quotation", Blocks -> Blocks
blockQuote (Blocks -> Blocks) -> LP m Blocks -> LP m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> LP m Blocks -> LP m Blocks
forall (m :: * -> *) a. PandocMonad m => Text -> LP m a -> LP m a
env "quotation" LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks)
   , ("verse", Blocks -> Blocks
blockQuote (Blocks -> Blocks) -> LP m Blocks -> LP m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> LP m Blocks -> LP m Blocks
forall (m :: * -> *) a. PandocMonad m => Text -> LP m a -> LP m a
env "verse" LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks)
   , ("itemize", [Blocks] -> Blocks
bulletList ([Blocks] -> Blocks)
-> ParsecT [Tok] LaTeXState m [Blocks] -> LP m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text
-> ParsecT [Tok] LaTeXState m [Blocks]
-> ParsecT [Tok] LaTeXState m [Blocks]
forall (m :: * -> *) a. PandocMonad m => Text -> LP m a -> LP m a
listenv "itemize" (LP m Blocks -> ParsecT [Tok] LaTeXState m [Blocks]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
item))
   , ("description", [(Inlines, [Blocks])] -> Blocks
definitionList ([(Inlines, [Blocks])] -> Blocks)
-> ParsecT [Tok] LaTeXState m [(Inlines, [Blocks])] -> LP m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text
-> ParsecT [Tok] LaTeXState m [(Inlines, [Blocks])]
-> ParsecT [Tok] LaTeXState m [(Inlines, [Blocks])]
forall (m :: * -> *) a. PandocMonad m => Text -> LP m a -> LP m a
listenv "description" (ParsecT [Tok] LaTeXState m (Inlines, [Blocks])
-> ParsecT [Tok] LaTeXState m [(Inlines, [Blocks])]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many ParsecT [Tok] LaTeXState m (Inlines, [Blocks])
forall (m :: * -> *). PandocMonad m => LP m (Inlines, [Blocks])
descItem))
   , ("enumerate", LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
orderedList')
   , ("alltt", Blocks -> Blocks
alltt (Blocks -> Blocks) -> LP m Blocks -> LP m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> LP m Blocks -> LP m Blocks
forall (m :: * -> *) a. PandocMonad m => Text -> LP m a -> LP m a
env "alltt" LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks)
   , ("code", Extension -> ParsecT [Tok] LaTeXState m ()
forall s (m :: * -> *) a st.
(Stream s m a, HasReaderOptions st) =>
Extension -> ParserT s st m ()
guardEnabled Extension
Ext_literate_haskell ParsecT [Tok] LaTeXState m () -> LP m Blocks -> LP m Blocks
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
       (Attr -> Text -> Blocks
codeBlockWith ("",["haskell","literate"],[]) (Text -> Blocks) -> ParsecT [Tok] LaTeXState m Text -> LP m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> ParsecT [Tok] LaTeXState m Text
forall (m :: * -> *). PandocMonad m => Text -> LP m Text
verbEnv "code"))
   , ("comment", Blocks
forall a. Monoid a => a
mempty Blocks -> ParsecT [Tok] LaTeXState m Text -> LP m Blocks
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Text -> ParsecT [Tok] LaTeXState m Text
forall (m :: * -> *). PandocMonad m => Text -> LP m Text
verbEnv "comment")
   , ("verbatim", Text -> Blocks
codeBlock (Text -> Blocks) -> ParsecT [Tok] LaTeXState m Text -> LP m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> ParsecT [Tok] LaTeXState m Text
forall (m :: * -> *). PandocMonad m => Text -> LP m Text
verbEnv "verbatim")
   , ("Verbatim", Text -> LP m Blocks
forall (m :: * -> *). PandocMonad m => Text -> LP m Blocks
fancyverbEnv "Verbatim")
   , ("BVerbatim", Text -> LP m Blocks
forall (m :: * -> *). PandocMonad m => Text -> LP m Blocks
fancyverbEnv "BVerbatim")
   , ("lstlisting", do Attr
attr <- [(Text, Text)] -> Attr
parseListingsOptions ([(Text, Text)] -> Attr)
-> ParsecT [Tok] LaTeXState m [(Text, Text)]
-> ParsecT [Tok] LaTeXState m Attr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(Text, Text)]
-> ParsecT [Tok] LaTeXState m [(Text, Text)]
-> ParsecT [Tok] LaTeXState m [(Text, Text)]
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option [] ParsecT [Tok] LaTeXState m [(Text, Text)]
forall (m :: * -> *). PandocMonad m => LP m [(Text, Text)]
keyvals
                       Attr -> Text -> Blocks
codeBlockWith Attr
attr (Text -> Blocks) -> ParsecT [Tok] LaTeXState m Text -> LP m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> ParsecT [Tok] LaTeXState m Text
forall (m :: * -> *). PandocMonad m => Text -> LP m Text
verbEnv "lstlisting")
   , ("minted", LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
minted)
   , ("obeylines", LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
obeylines)
   , ("tikzpicture", Text -> LP m Blocks
forall (m :: * -> *). PandocMonad m => Text -> LP m Blocks
rawVerbEnv "tikzpicture")
   , ("tikzcd", Text -> LP m Blocks
forall (m :: * -> *). PandocMonad m => Text -> LP m Blocks
rawVerbEnv "tikzcd")
   , ("lilypond", Text -> LP m Blocks
forall (m :: * -> *). PandocMonad m => Text -> LP m Blocks
rawVerbEnv "lilypond")
   , ("ly", Text -> LP m Blocks
forall (m :: * -> *). PandocMonad m => Text -> LP m Blocks
rawVerbEnv "ly")
   -- etoolbox
   , ("ifstrequal", LP m Blocks
forall (m :: * -> *) a. (PandocMonad m, Monoid a) => LP m a
ifstrequal)
   , ("newtoggle", ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced ParsecT [Tok] LaTeXState m [Tok]
-> ([Tok] -> LP m Blocks) -> LP m Blocks
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= [Tok] -> LP m Blocks
forall a (m :: * -> *).
(Monoid a, PandocMonad m) =>
[Tok] -> LP m a
newToggle)
   , ("toggletrue", ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced ParsecT [Tok] LaTeXState m [Tok]
-> ([Tok] -> LP m Blocks) -> LP m Blocks
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Bool -> [Tok] -> LP m Blocks
forall a (m :: * -> *).
(Monoid a, PandocMonad m) =>
Bool -> [Tok] -> LP m a
setToggle Bool
True)
   , ("togglefalse", ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced ParsecT [Tok] LaTeXState m [Tok]
-> ([Tok] -> LP m Blocks) -> LP m Blocks
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Bool -> [Tok] -> LP m Blocks
forall a (m :: * -> *).
(Monoid a, PandocMonad m) =>
Bool -> [Tok] -> LP m a
setToggle Bool
False)
   , ("iftoggle", LP m Blocks -> LP m Blocks
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (LP m Blocks -> LP m Blocks) -> LP m Blocks -> LP m Blocks
forall a b. (a -> b) -> a -> b
$ ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
ifToggle ParsecT [Tok] LaTeXState m () -> LP m Blocks -> LP m Blocks
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
block)
   ]

environment :: PandocMonad m => LP m Blocks
environment :: LP m Blocks
environment = LP m Blocks -> LP m Blocks
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (LP m Blocks -> LP m Blocks) -> LP m Blocks -> LP m Blocks
forall a b. (a -> b) -> a -> b
$ do
  Text -> LP m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "begin"
  Text
name <- [Tok] -> Text
untokenize ([Tok] -> Text)
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
  LP m Blocks -> Text -> Map Text (LP m Blocks) -> LP m Blocks
forall k a. Ord k => a -> k -> Map k a -> a
M.findWithDefault LP m Blocks
forall (m :: * -> *) a. MonadPlus m => m a
mzero Text
name Map Text (LP m Blocks)
forall (m :: * -> *). PandocMonad m => Map Text (LP m Blocks)
environments LP m Blocks -> LP m Blocks -> LP m Blocks
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
    if Text -> Map Text (LP PandocPure Inlines) -> Bool
forall k a. Ord k => k -> Map k a -> Bool
M.member Text
name (Map Text (LP PandocPure Inlines)
forall (m :: * -> *). PandocMonad m => Map Text (LP m Inlines)
inlineEnvironments
                       :: M.Map Text (LP PandocPure Inlines))
       then LP m Blocks
forall (m :: * -> *) a. MonadPlus m => m a
mzero
       else LP m Blocks -> LP m Blocks
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (Text -> LP m Blocks
forall (m :: * -> *). PandocMonad m => Text -> LP m Blocks
rawEnv Text
name) LP m Blocks -> LP m Blocks -> LP m Blocks
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Text -> LP m Blocks
forall (m :: * -> *). PandocMonad m => Text -> LP m Blocks
rawVerbEnv Text
name

env :: PandocMonad m => Text -> LP m a -> LP m a
env :: Text -> LP m a -> LP m a
env name :: Text
name p :: LP m a
p = LP m a
p LP m a -> ParsecT [Tok] LaTeXState m () -> LP m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Text -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => Text -> LP m ()
end_ Text
name

rawEnv :: PandocMonad m => Text -> LP m Blocks
rawEnv :: Text -> LP m Blocks
rawEnv name :: Text
name = do
  Extensions
exts <- (ReaderOptions -> Extensions)
-> ParserT [Tok] LaTeXState m Extensions
forall st s (m :: * -> *) t b.
(HasReaderOptions st, Stream s m t) =>
(ReaderOptions -> b) -> ParserT s st m b
getOption ReaderOptions -> Extensions
readerExtensions
  let parseRaw :: Bool
parseRaw = Extension -> Extensions -> Bool
extensionEnabled Extension
Ext_raw_tex Extensions
exts
  Text
rawOptions <- [Text] -> Text
forall a. Monoid a => [a] -> a
mconcat ([Text] -> Text)
-> ParsecT [Tok] LaTeXState m [Text]
-> ParsecT [Tok] LaTeXState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m Text
-> ParsecT [Tok] LaTeXState m [Text]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many ParsecT [Tok] LaTeXState m Text
forall (m :: * -> *). PandocMonad m => LP m Text
rawopt
  let beginCommand :: Text
beginCommand = "\\begin{" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
name Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> "}" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
rawOptions
  SourcePos
pos1 <- ParsecT [Tok] LaTeXState m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
  (bs :: Blocks
bs, raw :: [Tok]
raw) <- LP m Blocks -> LP m (Blocks, [Tok])
forall (m :: * -> *) a. PandocMonad m => LP m a -> LP m (a, [Tok])
withRaw (LP m Blocks -> LP m (Blocks, [Tok]))
-> LP m Blocks -> LP m (Blocks, [Tok])
forall a b. (a -> b) -> a -> b
$ Text -> LP m Blocks -> LP m Blocks
forall (m :: * -> *) a. PandocMonad m => Text -> LP m a -> LP m a
env Text
name LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks
  if Bool
parseRaw
     then Blocks -> LP m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return (Blocks -> LP m Blocks) -> Blocks -> LP m Blocks
forall a b. (a -> b) -> a -> b
$ Text -> Text -> Blocks
rawBlock "latex"
                 (Text -> Blocks) -> Text -> Blocks
forall a b. (a -> b) -> a -> b
$ Text
beginCommand Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> [Tok] -> Text
untokenize [Tok]
raw
     else do
       LogMessage -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LogMessage -> m ()
report (LogMessage -> ParsecT [Tok] LaTeXState m ())
-> LogMessage -> ParsecT [Tok] LaTeXState m ()
forall a b. (a -> b) -> a -> b
$ Text -> SourcePos -> LogMessage
SkippedContent Text
beginCommand SourcePos
pos1
       SourcePos
pos2 <- ParsecT [Tok] LaTeXState m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
       LogMessage -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LogMessage -> m ()
report (LogMessage -> ParsecT [Tok] LaTeXState m ())
-> LogMessage -> ParsecT [Tok] LaTeXState m ()
forall a b. (a -> b) -> a -> b
$ Text -> SourcePos -> LogMessage
SkippedContent ("\\end{" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
name Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> "}") SourcePos
pos2
       Blocks -> LP m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
bs

rawVerbEnv :: PandocMonad m => Text -> LP m Blocks
rawVerbEnv :: Text -> LP m Blocks
rawVerbEnv name :: Text
name = do
  SourcePos
pos <- ParsecT [Tok] LaTeXState m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
  (_, raw :: [Tok]
raw) <- LP m Text -> LP m (Text, [Tok])
forall (m :: * -> *) a. PandocMonad m => LP m a -> LP m (a, [Tok])
withRaw (LP m Text -> LP m (Text, [Tok]))
-> LP m Text -> LP m (Text, [Tok])
forall a b. (a -> b) -> a -> b
$ Text -> LP m Text
forall (m :: * -> *). PandocMonad m => Text -> LP m Text
verbEnv Text
name
  let raw' :: Text
raw' = "\\begin{" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
name Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> "}" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> [Tok] -> Text
untokenize [Tok]
raw
  Extensions
exts <- (ReaderOptions -> Extensions)
-> ParserT [Tok] LaTeXState m Extensions
forall st s (m :: * -> *) t b.
(HasReaderOptions st, Stream s m t) =>
(ReaderOptions -> b) -> ParserT s st m b
getOption ReaderOptions -> Extensions
readerExtensions
  let parseRaw :: Bool
parseRaw = Extension -> Extensions -> Bool
extensionEnabled Extension
Ext_raw_tex Extensions
exts
  if Bool
parseRaw
     then Blocks -> LP m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return (Blocks -> LP m Blocks) -> Blocks -> LP m Blocks
forall a b. (a -> b) -> a -> b
$ Text -> Text -> Blocks
rawBlock "latex" Text
raw'
     else do
       LogMessage -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LogMessage -> m ()
report (LogMessage -> ParsecT [Tok] LaTeXState m ())
-> LogMessage -> ParsecT [Tok] LaTeXState m ()
forall a b. (a -> b) -> a -> b
$ Text -> SourcePos -> LogMessage
SkippedContent Text
raw' SourcePos
pos
       Blocks -> LP m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
forall a. Monoid a => a
mempty

verbEnv :: PandocMonad m => Text -> LP m Text
verbEnv :: Text -> LP m Text
verbEnv name :: Text
name = LP m Text -> LP m Text
forall (m :: * -> *) a. PandocMonad m => LP m a -> LP m a
withVerbatimMode (LP m Text -> LP m Text) -> LP m Text -> LP m Text
forall a b. (a -> b) -> a -> b
$ do
  ParsecT [Tok] LaTeXState m ()
-> ParsecT [Tok] LaTeXState m (Maybe ())
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
blankline
  [Tok]
res <- ParsecT [Tok] LaTeXState m Tok
-> ParsecT [Tok] LaTeXState m ()
-> ParsecT [Tok] LaTeXState m [Tok]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => LP m Tok
anyTok (Text -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => Text -> LP m ()
end_ Text
name)
  Text -> LP m Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> LP m Text) -> Text -> LP m Text
forall a b. (a -> b) -> a -> b
$ Text -> Text
stripTrailingNewline
         (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ [Tok] -> Text
untokenize
         ([Tok] -> Text) -> [Tok] -> Text
forall a b. (a -> b) -> a -> b
$ [Tok]
res

-- Strip single final newline and any spaces following it.
-- Input is unchanged if it doesn't end with newline +
-- optional spaces.
stripTrailingNewline :: Text -> Text
stripTrailingNewline :: Text -> Text
stripTrailingNewline t :: Text
t =
  let (b :: Text
b, e :: Text
e) = Text -> Text -> (Text, Text)
T.breakOnEnd "\n" Text
t
  in  if (Char -> Bool) -> Text -> Bool
T.all (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== ' ') Text
e
         then Int -> Text -> Text
T.dropEnd 1 Text
b
         else Text
t

fancyverbEnv :: PandocMonad m => Text -> LP m Blocks
fancyverbEnv :: Text -> LP m Blocks
fancyverbEnv name :: Text
name = do
  [(Text, Text)]
options <- [(Text, Text)]
-> ParsecT [Tok] LaTeXState m [(Text, Text)]
-> ParsecT [Tok] LaTeXState m [(Text, Text)]
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option [] ParsecT [Tok] LaTeXState m [(Text, Text)]
forall (m :: * -> *). PandocMonad m => LP m [(Text, Text)]
keyvals
  let kvs :: [(Text, Text)]
kvs = [ (if Text
k Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== "firstnumber"
                  then "startFrom"
                  else Text
k, Text
v) | (k :: Text
k,v :: Text
v) <- [(Text, Text)]
options ]
  let classes :: [Text]
classes = [ "numberLines" |
                  Text -> [(Text, Text)] -> Maybe Text
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup "numbers" [(Text, Text)]
options Maybe Text -> Maybe Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text -> Maybe Text
forall a. a -> Maybe a
Just "left" ]
  let attr :: Attr
attr = ("",[Text]
classes,[(Text, Text)]
kvs)
  Attr -> Text -> Blocks
codeBlockWith Attr
attr (Text -> Blocks) -> ParsecT [Tok] LaTeXState m Text -> LP m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> ParsecT [Tok] LaTeXState m Text
forall (m :: * -> *). PandocMonad m => Text -> LP m Text
verbEnv Text
name

obeylines :: PandocMonad m => LP m Blocks
obeylines :: LP m Blocks
obeylines =
  Inlines -> Blocks
para (Inlines -> Blocks) -> (Inlines -> Inlines) -> Inlines -> Blocks
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inline] -> Inlines
forall a. [a] -> Many a
fromList ([Inline] -> Inlines)
-> (Inlines -> [Inline]) -> Inlines -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inline] -> [Inline]
removeLeadingTrailingBreaks ([Inline] -> [Inline])
-> (Inlines -> [Inline]) -> Inlines -> [Inline]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
   (Inline -> Inline) -> [Inline] -> [Inline]
forall a b. Walkable a b => (a -> a) -> b -> b
walk Inline -> Inline
softBreakToHard ([Inline] -> [Inline])
-> (Inlines -> [Inline]) -> Inlines -> [Inline]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> [Inline]
forall a. Many a -> [a]
toList (Inlines -> Blocks)
-> ParsecT [Tok] LaTeXState m Inlines -> LP m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text
-> ParsecT [Tok] LaTeXState m Inlines
-> ParsecT [Tok] LaTeXState m Inlines
forall (m :: * -> *) a. PandocMonad m => Text -> LP m a -> LP m a
env "obeylines" ParsecT [Tok] LaTeXState m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
inlines
  where softBreakToHard :: Inline -> Inline
softBreakToHard SoftBreak = Inline
LineBreak
        softBreakToHard x :: Inline
x         = Inline
x
        removeLeadingTrailingBreaks :: [Inline] -> [Inline]
removeLeadingTrailingBreaks = [Inline] -> [Inline]
forall a. [a] -> [a]
reverse ([Inline] -> [Inline])
-> ([Inline] -> [Inline]) -> [Inline] -> [Inline]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Inline -> Bool) -> [Inline] -> [Inline]
forall a. (a -> Bool) -> [a] -> [a]
dropWhile Inline -> Bool
isLineBreak ([Inline] -> [Inline])
-> ([Inline] -> [Inline]) -> [Inline] -> [Inline]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
                                      [Inline] -> [Inline]
forall a. [a] -> [a]
reverse ([Inline] -> [Inline])
-> ([Inline] -> [Inline]) -> [Inline] -> [Inline]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Inline -> Bool) -> [Inline] -> [Inline]
forall a. (a -> Bool) -> [a] -> [a]
dropWhile Inline -> Bool
isLineBreak
        isLineBreak :: Inline -> Bool
isLineBreak LineBreak = Bool
True
        isLineBreak _         = Bool
False

minted :: PandocMonad m => LP m Blocks
minted :: LP m Blocks
minted = do
  Attr
attr <- LP m Attr
forall (m :: * -> *). PandocMonad m => LP m Attr
mintedAttr
  Attr -> Text -> Blocks
codeBlockWith Attr
attr (Text -> Blocks) -> ParsecT [Tok] LaTeXState m Text -> LP m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> ParsecT [Tok] LaTeXState m Text
forall (m :: * -> *). PandocMonad m => Text -> LP m Text
verbEnv "minted"

mintedAttr :: PandocMonad m => LP m Attr
mintedAttr :: LP m Attr
mintedAttr = do
  [(Text, Text)]
options <- [(Text, Text)]
-> ParsecT [Tok] LaTeXState m [(Text, Text)]
-> ParsecT [Tok] LaTeXState m [(Text, Text)]
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option [] ParsecT [Tok] LaTeXState m [(Text, Text)]
forall (m :: * -> *). PandocMonad m => LP m [(Text, Text)]
keyvals
  Text
lang <- [Tok] -> Text
untokenize ([Tok] -> Text)
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
  let kvs :: [(Text, Text)]
kvs = [ (if Text
k Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== "firstnumber"
                  then "startFrom"
                  else Text
k, Text
v) | (k :: Text
k,v :: Text
v) <- [(Text, Text)]
options ]
  let classes :: [Text]
classes = [ Text
lang | Bool -> Bool
not (Text -> Bool
T.null Text
lang) ] [Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++
                [ "numberLines" |
                  Text -> [(Text, Text)] -> Maybe Text
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup "linenos" [(Text, Text)]
options Maybe Text -> Maybe Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text -> Maybe Text
forall a. a -> Maybe a
Just "true" ]
  Attr -> LP m Attr
forall (m :: * -> *) a. Monad m => a -> m a
return ("",[Text]
classes,[(Text, Text)]
kvs)

inputMinted :: PandocMonad m => LP m Blocks
inputMinted :: LP m Blocks
inputMinted = do
  SourcePos
pos <- ParsecT [Tok] LaTeXState m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
  Attr
attr <- LP m Attr
forall (m :: * -> *). PandocMonad m => LP m Attr
mintedAttr
  Text
f <- (Char -> Bool) -> Text -> Text
T.filter (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/='"') (Text -> Text) -> ([Tok] -> Text) -> [Tok] -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize ([Tok] -> Text)
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
  [SourceName]
dirs <- ((Text -> SourceName) -> [Text] -> [SourceName]
forall a b. (a -> b) -> [a] -> [b]
map Text -> SourceName
T.unpack ([Text] -> [SourceName])
-> (Maybe Text -> [Text]) -> Maybe Text -> [SourceName]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> Text -> [Text]
splitTextBy (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
==':') (Text -> [Text]) -> (Maybe Text -> Text) -> Maybe Text -> [Text]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe ".") (Maybe Text -> [SourceName])
-> ParsecT [Tok] LaTeXState m (Maybe Text)
-> ParsecT [Tok] LaTeXState m [SourceName]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> ParsecT [Tok] LaTeXState m (Maybe Text)
forall (m :: * -> *). PandocMonad m => Text -> m (Maybe Text)
lookupEnv "TEXINPUTS"
  Maybe Text
mbCode <- [SourceName]
-> SourceName -> ParsecT [Tok] LaTeXState m (Maybe Text)
forall (m :: * -> *).
PandocMonad m =>
[SourceName] -> SourceName -> m (Maybe Text)
readFileFromDirs [SourceName]
dirs (Text -> SourceName
T.unpack Text
f)
  Text
rawcode <- case Maybe Text
mbCode of
                  Just s :: Text
s -> Text -> ParsecT [Tok] LaTeXState m Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
s
                  Nothing -> do
                    LogMessage -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LogMessage -> m ()
report (LogMessage -> ParsecT [Tok] LaTeXState m ())
-> LogMessage -> ParsecT [Tok] LaTeXState m ()
forall a b. (a -> b) -> a -> b
$ Text -> SourcePos -> LogMessage
CouldNotLoadIncludeFile Text
f SourcePos
pos
                    Text -> ParsecT [Tok] LaTeXState m Text
forall (m :: * -> *) a. Monad m => a -> m a
return ""
  Blocks -> LP m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return (Blocks -> LP m Blocks) -> Blocks -> LP m Blocks
forall a b. (a -> b) -> a -> b
$ Attr -> Text -> Blocks
B.codeBlockWith Attr
attr Text
rawcode

letterContents :: PandocMonad m => LP m Blocks
letterContents :: LP m Blocks
letterContents = do
  Blocks
bs <- LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks
  LaTeXState
st <- ParsecT [Tok] LaTeXState m LaTeXState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  -- add signature (author) and address (title)
  let addr :: Blocks
addr = case Text -> Meta -> Maybe MetaValue
lookupMeta "address" (LaTeXState -> Meta
sMeta LaTeXState
st) of
                  Just (MetaBlocks [Plain xs :: [Inline]
xs]) ->
                     Inlines -> Blocks
para (Inlines -> Blocks) -> Inlines -> Blocks
forall a b. (a -> b) -> a -> b
$ Inlines -> Inlines
trimInlines (Inlines -> Inlines) -> Inlines -> Inlines
forall a b. (a -> b) -> a -> b
$ [Inline] -> Inlines
forall a. [a] -> Many a
fromList [Inline]
xs
                  _ -> Blocks
forall a. Monoid a => a
mempty
  Blocks -> LP m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return (Blocks -> LP m Blocks) -> Blocks -> LP m Blocks
forall a b. (a -> b) -> a -> b
$ Blocks
addr Blocks -> Blocks -> Blocks
forall a. Semigroup a => a -> a -> a
<> Blocks
bs -- sig added by \closing

figure :: PandocMonad m => LP m Blocks
figure :: LP m Blocks
figure = LP m Blocks -> LP m Blocks
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (LP m Blocks -> LP m Blocks) -> LP m Blocks -> LP m Blocks
forall a b. (a -> b) -> a -> b
$ do
  LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
resetCaption
  LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks LP m Blocks -> (Blocks -> LP m Blocks) -> LP m Blocks
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Blocks -> LP m Blocks
forall (m :: * -> *). PandocMonad m => Blocks -> LP m Blocks
addImageCaption

addImageCaption :: PandocMonad m => Blocks -> LP m Blocks
addImageCaption :: Blocks -> LP m Blocks
addImageCaption = (Inline -> ParsecT [Tok] LaTeXState m Inline)
-> Blocks -> LP m Blocks
forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM Inline -> ParsecT [Tok] LaTeXState m Inline
forall (m :: * -> *).
Monad m =>
Inline -> ParsecT [Tok] LaTeXState m Inline
go
  where go :: Inline -> ParsecT [Tok] LaTeXState m Inline
go (Image attr :: Attr
attr@(_, cls :: [Text]
cls, kvs :: [(Text, Text)]
kvs) alt :: [Inline]
alt (src :: Text
src,tit :: Text
tit))
            | Bool -> Bool
not ("fig:" Text -> Text -> Bool
`T.isPrefixOf` Text
tit) = do
          LaTeXState
st <- ParsecT [Tok] LaTeXState m LaTeXState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
          let (alt' :: [Inline]
alt', tit' :: Text
tit') = case LaTeXState -> Maybe Inlines
sCaption LaTeXState
st of
                               Just ils :: Inlines
ils -> (Inlines -> [Inline]
forall a. Many a -> [a]
toList Inlines
ils, "fig:" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
tit)
                               Nothing  -> ([Inline]
alt, Text
tit)
              attr' :: Attr
attr' = case LaTeXState -> Maybe Text
sLastLabel LaTeXState
st of
                        Just lab :: Text
lab -> (Text
lab, [Text]
cls, [(Text, Text)]
kvs)
                        Nothing  -> Attr
attr
          case Attr
attr' of
               ("", _, _)    -> () -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
               (ident :: Text
ident, _, _) -> do
                  DottedNum
num <- (LaTeXState -> DottedNum) -> LP m DottedNum
forall (m :: * -> *).
Monad m =>
(LaTeXState -> DottedNum) -> LP m DottedNum
getNextNumber LaTeXState -> DottedNum
sLastFigureNum
                  LaTeXState -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) u s. Monad m => u -> ParsecT s u m ()
setState
                    LaTeXState
st{ sLastFigureNum :: DottedNum
sLastFigureNum = DottedNum
num
                      , sLabels :: Map Text [Inline]
sLabels = Text -> [Inline] -> Map Text [Inline] -> Map Text [Inline]
forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert Text
ident
                                 [Text -> Inline
Str (DottedNum -> Text
renderDottedNum DottedNum
num)] (LaTeXState -> Map Text [Inline]
sLabels LaTeXState
st) }
          Inline -> ParsecT [Tok] LaTeXState m Inline
forall (m :: * -> *) a. Monad m => a -> m a
return (Inline -> ParsecT [Tok] LaTeXState m Inline)
-> Inline -> ParsecT [Tok] LaTeXState m Inline
forall a b. (a -> b) -> a -> b
$ Attr -> [Inline] -> (Text, Text) -> Inline
Image Attr
attr' [Inline]
alt' (Text
src, Text
tit')
        go x :: Inline
x = Inline -> ParsecT [Tok] LaTeXState m Inline
forall (m :: * -> *) a. Monad m => a -> m a
return Inline
x

getNextNumber :: Monad m
              => (LaTeXState -> DottedNum) -> LP m DottedNum
getNextNumber :: (LaTeXState -> DottedNum) -> LP m DottedNum
getNextNumber getCurrentNum :: LaTeXState -> DottedNum
getCurrentNum = do
  LaTeXState
st <- ParsecT [Tok] LaTeXState m LaTeXState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  let chapnum :: Maybe Int
chapnum =
        case LaTeXState -> DottedNum
sLastHeaderNum LaTeXState
st of
             DottedNum (n :: Int
n:_) | LaTeXState -> Bool
sHasChapters LaTeXState
st -> Int -> Maybe Int
forall a. a -> Maybe a
Just Int
n
             _                                 -> Maybe Int
forall a. Maybe a
Nothing
  DottedNum -> LP m DottedNum
forall (m :: * -> *) a. Monad m => a -> m a
return (DottedNum -> LP m DottedNum)
-> ([Int] -> DottedNum) -> [Int] -> LP m DottedNum
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Int] -> DottedNum
DottedNum ([Int] -> LP m DottedNum) -> [Int] -> LP m DottedNum
forall a b. (a -> b) -> a -> b
$
    case LaTeXState -> DottedNum
getCurrentNum LaTeXState
st of
       DottedNum [m :: Int
m,n :: Int
n]  ->
         case Maybe Int
chapnum of
              Just m' :: Int
m' | Int
m' Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
m   -> [Int
m, Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
+1]
                      | Bool
otherwise -> [Int
m', 1]
              Nothing             -> [1]
                                      -- shouldn't happen
       DottedNum [n :: Int
n]   ->
         case Maybe Int
chapnum of
              Just m :: Int
m  -> [Int
m, 1]
              Nothing -> [Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ 1]
       _               ->
         case Maybe Int
chapnum of
               Just n :: Int
n  -> [Int
n, 1]
               Nothing -> [1]


coloredBlock :: PandocMonad m => Text -> LP m Blocks
coloredBlock :: Text -> LP m Blocks
coloredBlock stylename :: Text
stylename = LP m Blocks -> LP m Blocks
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (LP m Blocks -> LP m Blocks) -> LP m Blocks -> LP m Blocks
forall a b. (a -> b) -> a -> b
$ do
  LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts
  [Tok]
color <- LP m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
  ParsecT [Tok] LaTeXState m Inlines -> LP m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (ParsecT [Tok] LaTeXState m Inlines
-> ParsecT [Tok] LaTeXState m Inlines
forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
grouped ParsecT [Tok] LaTeXState m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
inline)
  let constructor :: Blocks -> Blocks
constructor = Attr -> Blocks -> Blocks
divWith ("",[],[("style",Text
stylename Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> ": " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> [Tok] -> Text
untokenize [Tok]
color)])
  Blocks -> Blocks
constructor (Blocks -> Blocks) -> LP m Blocks -> LP m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Blocks -> LP m Blocks
forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
grouped LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
block

graphicsPath :: PandocMonad m => LP m Blocks
graphicsPath :: LP m Blocks
graphicsPath = do
  [SourceName]
ps <- ([Tok] -> SourceName) -> [[Tok]] -> [SourceName]
forall a b. (a -> b) -> [a] -> [b]
map (Text -> SourceName
T.unpack (Text -> SourceName) -> ([Tok] -> Text) -> [Tok] -> SourceName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize) ([[Tok]] -> [SourceName])
-> ParsecT [Tok] LaTeXState m [[Tok]]
-> ParsecT [Tok] LaTeXState m [SourceName]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
          (LP m Tok
forall (m :: * -> *). PandocMonad m => LP m Tok
bgroup LP m Tok
-> ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces ParsecT [Tok] LaTeXState m ()
-> ParsecT [Tok] LaTeXState m [[Tok]]
-> ParsecT [Tok] LaTeXState m [[Tok]]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT [Tok] LaTeXState m [Tok]
-> LP m Tok -> ParsecT [Tok] LaTeXState m [[Tok]]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill (ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m ()
-> ParsecT [Tok] LaTeXState m [Tok]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces) LP m Tok
forall (m :: * -> *). PandocMonad m => LP m Tok
egroup)
  ParsecT [Tok] LaTeXState m [SourceName]
forall (m :: * -> *). PandocMonad m => m [SourceName]
getResourcePath ParsecT [Tok] LaTeXState m [SourceName]
-> ([SourceName] -> ParsecT [Tok] LaTeXState m ())
-> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= [SourceName] -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => [SourceName] -> m ()
setResourcePath ([SourceName] -> ParsecT [Tok] LaTeXState m ())
-> ([SourceName] -> [SourceName])
-> [SourceName]
-> ParsecT [Tok] LaTeXState m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([SourceName] -> [SourceName] -> [SourceName]
forall a. Semigroup a => a -> a -> a
<> [SourceName]
ps)
  Blocks -> LP m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
forall a. Monoid a => a
mempty

splitBibs :: Text -> [Inlines]
splitBibs :: Text -> [Inlines]
splitBibs = (Text -> Inlines) -> [Text] -> [Inlines]
forall a b. (a -> b) -> [a] -> [b]
map (Text -> Inlines
str (Text -> Inlines) -> (Text -> Text) -> Text -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SourceName -> Text
T.pack (SourceName -> Text) -> (Text -> SourceName) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (SourceName -> SourceName -> SourceName)
-> SourceName -> SourceName -> SourceName
forall a b c. (a -> b -> c) -> b -> a -> c
flip SourceName -> SourceName -> SourceName
replaceExtension "bib" (SourceName -> SourceName)
-> (Text -> SourceName) -> Text -> SourceName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> SourceName
T.unpack (Text -> SourceName) -> (Text -> Text) -> Text -> SourceName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
trim) ([Text] -> [Inlines]) -> (Text -> [Text]) -> Text -> [Inlines]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> Text -> [Text]
splitTextBy (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
==',')

alltt :: Blocks -> Blocks
alltt :: Blocks -> Blocks
alltt = (Inline -> Inline) -> Blocks -> Blocks
forall a b. Walkable a b => (a -> a) -> b -> b
walk Inline -> Inline
strToCode
  where strToCode :: Inline -> Inline
strToCode (Str s :: Text
s)   = Attr -> Text -> Inline
Code Attr
nullAttr Text
s
        strToCode Space     = Format -> Text -> Inline
RawInline (Text -> Format
Format "latex") "\\ "
        strToCode SoftBreak = Inline
LineBreak
        strToCode x :: Inline
x         = Inline
x

parseListingsOptions :: [(Text, Text)] -> Attr
parseListingsOptions :: [(Text, Text)] -> Attr
parseListingsOptions options :: [(Text, Text)]
options =
  let kvs :: [(Text, Text)]
kvs = [ (if Text
k Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== "firstnumber"
                  then "startFrom"
                  else Text
k, Text
v) | (k :: Text
k,v :: Text
v) <- [(Text, Text)]
options ]
      classes :: [Text]
classes = [ "numberLines" |
                  Text -> [(Text, Text)] -> Maybe Text
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup "numbers" [(Text, Text)]
options Maybe Text -> Maybe Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text -> Maybe Text
forall a. a -> Maybe a
Just "left" ]
             [Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++ Maybe Text -> [Text]
forall a. Maybe a -> [a]
maybeToList ([(Text, Text)] -> Maybe Text
listingsLanguage [(Text, Text)]
options)
  in  (Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe "" (Text -> [(Text, Text)] -> Maybe Text
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup "label" [(Text, Text)]
options), [Text]
classes, [(Text, Text)]
kvs)

inputListing :: PandocMonad m => LP m Blocks
inputListing :: LP m Blocks
inputListing = do
  SourcePos
pos <- ParsecT [Tok] LaTeXState m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
  [(Text, Text)]
options <- [(Text, Text)]
-> ParsecT [Tok] LaTeXState m [(Text, Text)]
-> ParsecT [Tok] LaTeXState m [(Text, Text)]
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option [] ParsecT [Tok] LaTeXState m [(Text, Text)]
forall (m :: * -> *). PandocMonad m => LP m [(Text, Text)]
keyvals
  Text
f <- (Char -> Bool) -> Text -> Text
T.filter (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/='"') (Text -> Text) -> ([Tok] -> Text) -> [Tok] -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize ([Tok] -> Text)
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
  [SourceName]
dirs <- ((Text -> SourceName) -> [Text] -> [SourceName]
forall a b. (a -> b) -> [a] -> [b]
map Text -> SourceName
T.unpack ([Text] -> [SourceName])
-> (Maybe Text -> [Text]) -> Maybe Text -> [SourceName]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> Text -> [Text]
splitTextBy (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
==':') (Text -> [Text]) -> (Maybe Text -> Text) -> Maybe Text -> [Text]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe ".") (Maybe Text -> [SourceName])
-> ParsecT [Tok] LaTeXState m (Maybe Text)
-> ParsecT [Tok] LaTeXState m [SourceName]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> ParsecT [Tok] LaTeXState m (Maybe Text)
forall (m :: * -> *). PandocMonad m => Text -> m (Maybe Text)
lookupEnv "TEXINPUTS"
  Maybe Text
mbCode <- [SourceName]
-> SourceName -> ParsecT [Tok] LaTeXState m (Maybe Text)
forall (m :: * -> *).
PandocMonad m =>
[SourceName] -> SourceName -> m (Maybe Text)
readFileFromDirs [SourceName]
dirs (Text -> SourceName
T.unpack Text
f)
  [Text]
codeLines <- case Maybe Text
mbCode of
                      Just s :: Text
s -> [Text] -> ParsecT [Tok] LaTeXState m [Text]
forall (m :: * -> *) a. Monad m => a -> m a
return ([Text] -> ParsecT [Tok] LaTeXState m [Text])
-> [Text] -> ParsecT [Tok] LaTeXState m [Text]
forall a b. (a -> b) -> a -> b
$ Text -> [Text]
T.lines Text
s
                      Nothing -> do
                        LogMessage -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LogMessage -> m ()
report (LogMessage -> ParsecT [Tok] LaTeXState m ())
-> LogMessage -> ParsecT [Tok] LaTeXState m ()
forall a b. (a -> b) -> a -> b
$ Text -> SourcePos -> LogMessage
CouldNotLoadIncludeFile Text
f SourcePos
pos
                        [Text] -> ParsecT [Tok] LaTeXState m [Text]
forall (m :: * -> *) a. Monad m => a -> m a
return []
  let (ident :: Text
ident,classes :: [Text]
classes,kvs :: [(Text, Text)]
kvs) = [(Text, Text)] -> Attr
parseListingsOptions [(Text, Text)]
options
  let classes' :: [Text]
classes' =
        (case [(Text, Text)] -> Maybe Text
listingsLanguage [(Text, Text)]
options of
           Nothing -> (Int -> [Text] -> [Text]
forall a. Int -> [a] -> [a]
take 1 (Text -> [Text]
languagesByExtension (SourceName -> Text
T.pack (SourceName -> Text) -> SourceName -> Text
forall a b. (a -> b) -> a -> b
$ SourceName -> SourceName
takeExtension (SourceName -> SourceName) -> SourceName -> SourceName
forall a b. (a -> b) -> a -> b
$ Text -> SourceName
T.unpack Text
f)) [Text] -> [Text] -> [Text]
forall a. Semigroup a => a -> a -> a
<>)
           Just _  -> [Text] -> [Text]
forall a. a -> a
id) [Text]
classes
  let firstline :: Int
firstline = Int -> Maybe Int -> Int
forall a. a -> Maybe a -> a
fromMaybe 1 (Maybe Int -> Int) -> Maybe Int -> Int
forall a b. (a -> b) -> a -> b
$ Text -> [(Text, Text)] -> Maybe Text
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup "firstline" [(Text, Text)]
options Maybe Text -> (Text -> Maybe Int) -> Maybe Int
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> Maybe Int
forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
safeRead
  let lastline :: Int
lastline = Int -> Maybe Int -> Int
forall a. a -> Maybe a -> a
fromMaybe ([Text] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Text]
codeLines) (Maybe Int -> Int) -> Maybe Int -> Int
forall a b. (a -> b) -> a -> b
$
                       Text -> [(Text, Text)] -> Maybe Text
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup "lastline" [(Text, Text)]
options Maybe Text -> (Text -> Maybe Int) -> Maybe Int
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> Maybe Int
forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
safeRead
  let codeContents :: Text
codeContents = Text -> [Text] -> Text
T.intercalate "\n" ([Text] -> Text) -> [Text] -> Text
forall a b. (a -> b) -> a -> b
$ Int -> [Text] -> [Text]
forall a. Int -> [a] -> [a]
take (1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
lastline Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
firstline) ([Text] -> [Text]) -> [Text] -> [Text]
forall a b. (a -> b) -> a -> b
$
                       Int -> [Text] -> [Text]
forall a. Int -> [a] -> [a]
drop (Int
firstline Int -> Int -> Int
forall a. Num a => a -> a -> a
- 1) [Text]
codeLines
  Blocks -> LP m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return (Blocks -> LP m Blocks) -> Blocks -> LP m Blocks
forall a b. (a -> b) -> a -> b
$ Attr -> Text -> Blocks
codeBlockWith (Text
ident,[Text]
classes',[(Text, Text)]
kvs) Text
codeContents

-- lists

item :: PandocMonad m => LP m Blocks
item :: LP m Blocks
item = LP m Blocks -> ParsecT [Tok] LaTeXState m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks ParsecT [Tok] LaTeXState m ()
-> ParsecT [Tok] LaTeXState m Tok -> ParsecT [Tok] LaTeXState m Tok
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Text -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "item" ParsecT [Tok] LaTeXState m Tok
-> ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts ParsecT [Tok] LaTeXState m () -> LP m Blocks -> LP m Blocks
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks

descItem :: PandocMonad m => LP m (Inlines, [Blocks])
descItem :: LP m (Inlines, [Blocks])
descItem = do
  LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks -- skip blocks before item
  Text -> LP m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "item"
  LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
sp
  Inlines
ils <- LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
opt
  Blocks
bs <- LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks
  (Inlines, [Blocks]) -> LP m (Inlines, [Blocks])
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines
ils, [Blocks
bs])

listenv :: PandocMonad m => Text -> LP m a -> LP m a
listenv :: Text -> LP m a -> LP m a
listenv name :: Text
name p :: LP m a
p = LP m a -> LP m a
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (LP m a -> LP m a) -> LP m a -> LP m a
forall a b. (a -> b) -> a -> b
$ do
  Bool
oldInListItem <- LaTeXState -> Bool
sInListItem (LaTeXState -> Bool)
-> ParsecT [Tok] LaTeXState m LaTeXState
-> ParsecT [Tok] LaTeXState m Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` ParsecT [Tok] LaTeXState m LaTeXState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
  (LaTeXState -> LaTeXState) -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((LaTeXState -> LaTeXState) -> ParsecT [Tok] LaTeXState m ())
-> (LaTeXState -> LaTeXState) -> ParsecT [Tok] LaTeXState m ()
forall a b. (a -> b) -> a -> b
$ \st :: LaTeXState
st -> LaTeXState
st{ sInListItem :: Bool
sInListItem = Bool
True }
  a
res <- Text -> LP m a -> LP m a
forall (m :: * -> *) a. PandocMonad m => Text -> LP m a -> LP m a
env Text
name LP m a
p
  (LaTeXState -> LaTeXState) -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((LaTeXState -> LaTeXState) -> ParsecT [Tok] LaTeXState m ())
-> (LaTeXState -> LaTeXState) -> ParsecT [Tok] LaTeXState m ()
forall a b. (a -> b) -> a -> b
$ \st :: LaTeXState
st -> LaTeXState
st{ sInListItem :: Bool
sInListItem = Bool
oldInListItem }
  a -> LP m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
res

orderedList' :: PandocMonad m => LP m Blocks
orderedList' :: LP m Blocks
orderedList' = LP m Blocks -> LP m Blocks
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (LP m Blocks -> LP m Blocks) -> LP m Blocks -> LP m Blocks
forall a b. (a -> b) -> a -> b
$ do
  LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces
  let markerSpec :: ParsecT [Tok] LaTeXState m ListAttributes
markerSpec = do
        Char -> LP m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '['
        Text
ts <- [Tok] -> Text
untokenize ([Tok] -> Text)
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Tok -> LP m Tok -> ParsecT [Tok] LaTeXState m [Tok]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill LP m Tok
forall (m :: * -> *). PandocMonad m => LP m Tok
anyTok (Char -> LP m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol ']')
        case Parsec Text ParserState ListAttributes
-> ParserState
-> SourceName
-> Text
-> Either ParseError ListAttributes
forall s t u a.
Stream s Identity t =>
Parsec s u a -> u -> SourceName -> s -> Either ParseError a
runParser Parsec Text ParserState ListAttributes
forall s (m :: * -> *).
Stream s m Char =>
ParserT s ParserState m ListAttributes
anyOrderedListMarker ParserState
forall a. Default a => a
def "option" Text
ts of
             Right r :: ListAttributes
r -> ListAttributes -> ParsecT [Tok] LaTeXState m ListAttributes
forall (m :: * -> *) a. Monad m => a -> m a
return ListAttributes
r
             Left _  -> do
               SourcePos
pos <- ParsecT [Tok] LaTeXState m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
               LogMessage -> LP m ()
forall (m :: * -> *). PandocMonad m => LogMessage -> m ()
report (LogMessage -> LP m ()) -> LogMessage -> LP m ()
forall a b. (a -> b) -> a -> b
$ Text -> SourcePos -> LogMessage
SkippedContent ("[" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
ts Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> "]") SourcePos
pos
               ListAttributes -> ParsecT [Tok] LaTeXState m ListAttributes
forall (m :: * -> *) a. Monad m => a -> m a
return (1, ListNumberStyle
DefaultStyle, ListNumberDelim
DefaultDelim)
  (_, style :: ListNumberStyle
style, delim :: ListNumberDelim
delim) <- ListAttributes
-> ParsecT [Tok] LaTeXState m ListAttributes
-> ParsecT [Tok] LaTeXState m ListAttributes
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option (1, ListNumberStyle
DefaultStyle, ListNumberDelim
DefaultDelim) ParsecT [Tok] LaTeXState m ListAttributes
markerSpec
  LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces
  ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m (Maybe [Tok])
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (ParsecT [Tok] LaTeXState m [Tok]
 -> ParsecT [Tok] LaTeXState m (Maybe [Tok]))
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m (Maybe [Tok])
forall a b. (a -> b) -> a -> b
$ ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m [Tok]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT [Tok] LaTeXState m [Tok]
 -> ParsecT [Tok] LaTeXState m [Tok])
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m [Tok]
forall a b. (a -> b) -> a -> b
$ Text -> LP m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "setlength"
                   LP m Tok
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m [Tok]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
grouped (Int -> LP m Tok -> ParsecT [Tok] LaTeXState m [Tok]
forall s (m :: * -> *) t u a.
Stream s m t =>
Int -> ParsecT s u m a -> ParsecT s u m [a]
count 1 (LP m Tok -> ParsecT [Tok] LaTeXState m [Tok])
-> LP m Tok -> ParsecT [Tok] LaTeXState m [Tok]
forall a b. (a -> b) -> a -> b
$ Text -> LP m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "itemindent")
                   ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m [Tok]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
  LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces
  Int
start <- Int
-> ParsecT [Tok] LaTeXState m Int -> ParsecT [Tok] LaTeXState m Int
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option 1 (ParsecT [Tok] LaTeXState m Int -> ParsecT [Tok] LaTeXState m Int)
-> ParsecT [Tok] LaTeXState m Int -> ParsecT [Tok] LaTeXState m Int
forall a b. (a -> b) -> a -> b
$ ParsecT [Tok] LaTeXState m Int -> ParsecT [Tok] LaTeXState m Int
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT [Tok] LaTeXState m Int -> ParsecT [Tok] LaTeXState m Int)
-> ParsecT [Tok] LaTeXState m Int -> ParsecT [Tok] LaTeXState m Int
forall a b. (a -> b) -> a -> b
$ do SourcePos
pos <- ParsecT [Tok] LaTeXState m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
                               Text -> LP m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "setcounter"
                               Text
ctr <- [Tok] -> Text
untokenize ([Tok] -> Text)
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
                               Bool -> LP m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> LP m ()) -> Bool -> LP m ()
forall a b. (a -> b) -> a -> b
$ "enum" Text -> Text -> Bool
`T.isPrefixOf` Text
ctr
                               Bool -> LP m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> LP m ()) -> Bool -> LP m ()
forall a b. (a -> b) -> a -> b
$ (Char -> Bool) -> Text -> Bool
T.all (Char -> SourceName -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` ['i','v']) (Int -> Text -> Text
T.drop 4 Text
ctr)
                               LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
sp
                               Text
num <- [Tok] -> Text
untokenize ([Tok] -> Text)
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
                               case Text -> Maybe Int
forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
safeRead Text
num of
                                    Just i :: Int
i -> Int -> ParsecT [Tok] LaTeXState m Int
forall (m :: * -> *) a. Monad m => a -> m a
return (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ 1 :: Int)
                                    Nothing -> do
                                      LogMessage -> LP m ()
forall (m :: * -> *). PandocMonad m => LogMessage -> m ()
report (LogMessage -> LP m ()) -> LogMessage -> LP m ()
forall a b. (a -> b) -> a -> b
$ Text -> SourcePos -> LogMessage
SkippedContent
                                        ("\\setcounter{" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
ctr Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
                                         "}{" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
num Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> "}") SourcePos
pos
                                      Int -> ParsecT [Tok] LaTeXState m Int
forall (m :: * -> *) a. Monad m => a -> m a
return 1
  [Blocks]
bs <- Text -> LP m [Blocks] -> LP m [Blocks]
forall (m :: * -> *) a. PandocMonad m => Text -> LP m a -> LP m a
listenv "enumerate" (LP m Blocks -> LP m [Blocks]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
item)
  Blocks -> LP m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return (Blocks -> LP m Blocks) -> Blocks -> LP m Blocks
forall a b. (a -> b) -> a -> b
$ ListAttributes -> [Blocks] -> Blocks
orderedListWith (Int
start, ListNumberStyle
style, ListNumberDelim
delim) [Blocks]
bs

-- tables

hline :: PandocMonad m => LP m ()
hline :: LP m ()
hline = LP m () -> LP m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (LP m () -> LP m ()) -> LP m () -> LP m ()
forall a b. (a -> b) -> a -> b
$ do
  LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces
  Text -> LP m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "hline" LP m Tok -> LP m Tok -> LP m Tok
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
    -- booktabs rules:
    Text -> LP m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "toprule" LP m Tok -> LP m Tok -> LP m Tok
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
    Text -> LP m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "bottomrule" LP m Tok -> LP m Tok -> LP m Tok
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
    Text -> LP m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "midrule" LP m Tok -> LP m Tok -> LP m Tok
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
    Text -> LP m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "endhead" LP m Tok -> LP m Tok -> LP m Tok
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
    Text -> LP m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "endfirsthead"
  LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces
  ParsecT [Tok] LaTeXState m Inlines
-> ParsecT [Tok] LaTeXState m (Maybe Inlines)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional ParsecT [Tok] LaTeXState m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
opt
  () -> LP m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

lbreak :: PandocMonad m => LP m Tok
lbreak :: LP m Tok
lbreak = (Text -> LP m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "\\" LP m Tok -> LP m Tok -> LP m Tok
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Text -> LP m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "tabularnewline")
         LP m Tok -> ParsecT [Tok] LaTeXState m () -> LP m Tok
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts LP m Tok -> ParsecT [Tok] LaTeXState m () -> LP m Tok
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces

amp :: PandocMonad m => LP m Tok
amp :: LP m Tok
amp = Char -> LP m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '&'

-- Split a Word into individual Symbols (for parseAligns)
splitWordTok :: PandocMonad m => LP m ()
splitWordTok :: LP m ()
splitWordTok = do
  [Tok]
inp <- ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *) s u. Monad m => ParsecT s u m s
getInput
  case [Tok]
inp of
       (Tok spos :: SourcePos
spos Word t :: Text
t : rest :: [Tok]
rest) ->
         [Tok] -> LP m ()
forall (m :: * -> *) s u. Monad m => s -> ParsecT s u m ()
setInput ([Tok] -> LP m ()) -> [Tok] -> LP m ()
forall a b. (a -> b) -> a -> b
$ (Char -> Tok) -> SourceName -> [Tok]
forall a b. (a -> b) -> [a] -> [b]
map (SourcePos -> TokType -> Text -> Tok
Tok SourcePos
spos TokType
Symbol (Text -> Tok) -> (Char -> Text) -> Char -> Tok
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Text
T.singleton) (Text -> SourceName
T.unpack Text
t) [Tok] -> [Tok] -> [Tok]
forall a. Semigroup a => a -> a -> a
<> [Tok]
rest
       _ -> () -> LP m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

parseAligns :: PandocMonad m => LP m [(Alignment, Double, ([Tok], [Tok]))]
parseAligns :: LP m [(Alignment, Double, ([Tok], [Tok]))]
parseAligns = LP m [(Alignment, Double, ([Tok], [Tok]))]
-> LP m [(Alignment, Double, ([Tok], [Tok]))]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (LP m [(Alignment, Double, ([Tok], [Tok]))]
 -> LP m [(Alignment, Double, ([Tok], [Tok]))])
-> LP m [(Alignment, Double, ([Tok], [Tok]))]
-> LP m [(Alignment, Double, ([Tok], [Tok]))]
forall a b. (a -> b) -> a -> b
$ do
  let maybeBar :: ParsecT [Tok] LaTeXState m ()
maybeBar = ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany
        (ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m ())
-> ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m ()
forall a b. (a -> b) -> a -> b
$ ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
sp ParsecT [Tok] LaTeXState m ()
-> ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (() ()
-> ParsecT [Tok] LaTeXState m Tok -> ParsecT [Tok] LaTeXState m ()
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '|' ParsecT [Tok] LaTeXState m ()
-> ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> () ()
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m ()
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (Char -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '@' ParsecT [Tok] LaTeXState m Tok
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced)))
  let cAlign :: ParsecT [Tok] LaTeXState m Alignment
cAlign = Alignment
AlignCenter Alignment
-> ParsecT [Tok] LaTeXState m Tok
-> ParsecT [Tok] LaTeXState m Alignment
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol 'c'
  let lAlign :: ParsecT [Tok] LaTeXState m Alignment
lAlign = Alignment
AlignLeft Alignment
-> ParsecT [Tok] LaTeXState m Tok
-> ParsecT [Tok] LaTeXState m Alignment
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol 'l'
  let rAlign :: ParsecT [Tok] LaTeXState m Alignment
rAlign = Alignment
AlignRight Alignment
-> ParsecT [Tok] LaTeXState m Tok
-> ParsecT [Tok] LaTeXState m Alignment
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol 'r'
  let parAlign :: ParsecT [Tok] LaTeXState m Alignment
parAlign = Alignment
AlignLeft Alignment
-> ParsecT [Tok] LaTeXState m Tok
-> ParsecT [Tok] LaTeXState m Alignment
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol 'p'
  -- aligns from tabularx
  let xAlign :: ParsecT [Tok] LaTeXState m Alignment
xAlign = Alignment
AlignLeft Alignment
-> ParsecT [Tok] LaTeXState m Tok
-> ParsecT [Tok] LaTeXState m Alignment
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol 'X'
  let mAlign :: ParsecT [Tok] LaTeXState m Alignment
mAlign = Alignment
AlignLeft Alignment
-> ParsecT [Tok] LaTeXState m Tok
-> ParsecT [Tok] LaTeXState m Alignment
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol 'm'
  let bAlign :: ParsecT [Tok] LaTeXState m Alignment
bAlign = Alignment
AlignLeft Alignment
-> ParsecT [Tok] LaTeXState m Tok
-> ParsecT [Tok] LaTeXState m Alignment
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol 'b'
  let alignChar :: ParsecT [Tok] LaTeXState m Alignment
alignChar = ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
splitWordTok ParsecT [Tok] LaTeXState m ()
-> ParsecT [Tok] LaTeXState m Alignment
-> ParsecT [Tok] LaTeXState m Alignment
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (  ParsecT [Tok] LaTeXState m Alignment
cAlign ParsecT [Tok] LaTeXState m Alignment
-> ParsecT [Tok] LaTeXState m Alignment
-> ParsecT [Tok] LaTeXState m Alignment
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ParsecT [Tok] LaTeXState m Alignment
lAlign ParsecT [Tok] LaTeXState m Alignment
-> ParsecT [Tok] LaTeXState m Alignment
-> ParsecT [Tok] LaTeXState m Alignment
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ParsecT [Tok] LaTeXState m Alignment
rAlign ParsecT [Tok] LaTeXState m Alignment
-> ParsecT [Tok] LaTeXState m Alignment
-> ParsecT [Tok] LaTeXState m Alignment
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ParsecT [Tok] LaTeXState m Alignment
parAlign
                                 ParsecT [Tok] LaTeXState m Alignment
-> ParsecT [Tok] LaTeXState m Alignment
-> ParsecT [Tok] LaTeXState m Alignment
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ParsecT [Tok] LaTeXState m Alignment
xAlign ParsecT [Tok] LaTeXState m Alignment
-> ParsecT [Tok] LaTeXState m Alignment
-> ParsecT [Tok] LaTeXState m Alignment
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ParsecT [Tok] LaTeXState m Alignment
mAlign ParsecT [Tok] LaTeXState m Alignment
-> ParsecT [Tok] LaTeXState m Alignment
-> ParsecT [Tok] LaTeXState m Alignment
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ParsecT [Tok] LaTeXState m Alignment
bAlign )
  let alignPrefix :: ParsecT [Tok] LaTeXState m [Tok]
alignPrefix = Char -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '>' ParsecT [Tok] LaTeXState m Tok
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
  let alignSuffix :: ParsecT [Tok] LaTeXState m [Tok]
alignSuffix = Char -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '<' ParsecT [Tok] LaTeXState m Tok
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
  let colWidth :: ParsecT [Tok] LaTeXState m Double
colWidth = ParsecT [Tok] LaTeXState m Double
-> ParsecT [Tok] LaTeXState m Double
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT [Tok] LaTeXState m Double
 -> ParsecT [Tok] LaTeXState m Double)
-> ParsecT [Tok] LaTeXState m Double
-> ParsecT [Tok] LaTeXState m Double
forall a b. (a -> b) -> a -> b
$ do
        Char -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '{'
        Text
ds <- Text -> Text
trim (Text -> Text) -> ([Tok] -> Text) -> [Tok] -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize ([Tok] -> Text)
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m Tok
-> ParsecT [Tok] LaTeXState m Tok
-> ParsecT [Tok] LaTeXState m [Tok]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => LP m Tok
anyTok (Text -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "linewidth")
        ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces
        Char -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '}'
        case Text -> Maybe Double
forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
safeRead Text
ds of
              Just w :: Double
w  -> Double -> ParsecT [Tok] LaTeXState m Double
forall (m :: * -> *) a. Monad m => a -> m a
return Double
w
              Nothing -> Double -> ParsecT [Tok] LaTeXState m Double
forall (m :: * -> *) a. Monad m => a -> m a
return 0.0
  let alignSpec :: ParsecT [Tok] LaTeXState m (Alignment, Double, ([Tok], [Tok]))
alignSpec = do
        [Tok]
pref <- [Tok]
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m [Tok]
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option [] ParsecT [Tok] LaTeXState m [Tok]
alignPrefix
        ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces
        Alignment
al <- ParsecT [Tok] LaTeXState m Alignment
alignChar
        Double
width <- ParsecT [Tok] LaTeXState m Double
colWidth ParsecT [Tok] LaTeXState m Double
-> ParsecT [Tok] LaTeXState m Double
-> ParsecT [Tok] LaTeXState m Double
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Double
-> ParsecT [Tok] LaTeXState m Double
-> ParsecT [Tok] LaTeXState m Double
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option 0.0 (do Text
s <- [Tok] -> Text
untokenize ([Tok] -> Text)
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
                                             SourcePos
pos <- ParsecT [Tok] LaTeXState m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
                                             LogMessage -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LogMessage -> m ()
report (LogMessage -> ParsecT [Tok] LaTeXState m ())
-> LogMessage -> ParsecT [Tok] LaTeXState m ()
forall a b. (a -> b) -> a -> b
$ Text -> SourcePos -> LogMessage
SkippedContent Text
s SourcePos
pos
                                             Double -> ParsecT [Tok] LaTeXState m Double
forall (m :: * -> *) a. Monad m => a -> m a
return 0.0)
        ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces
        [Tok]
suff <- [Tok]
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m [Tok]
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option [] ParsecT [Tok] LaTeXState m [Tok]
alignSuffix
        (Alignment, Double, ([Tok], [Tok]))
-> ParsecT [Tok] LaTeXState m (Alignment, Double, ([Tok], [Tok]))
forall (m :: * -> *) a. Monad m => a -> m a
return (Alignment
al, Double
width, ([Tok]
pref, [Tok]
suff))
  let starAlign :: ParsecT [Tok] LaTeXState m ()
starAlign = do -- '*{2}{r}' == 'rr', we just expand like a macro
        Char -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '*'
        ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces
        Text
ds <- Text -> Text
trim (Text -> Text) -> ([Tok] -> Text) -> [Tok] -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize ([Tok] -> Text)
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
        ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces
        [Tok]
spec <- ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
        case Text -> Maybe Int
forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
safeRead Text
ds of
             Just n :: Int
n  ->
               ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *) s u. Monad m => ParsecT s u m s
getInput ParsecT [Tok] LaTeXState m [Tok]
-> ([Tok] -> ParsecT [Tok] LaTeXState m ())
-> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= [Tok] -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) s u. Monad m => s -> ParsecT s u m ()
setInput ([Tok] -> ParsecT [Tok] LaTeXState m ())
-> ([Tok] -> [Tok]) -> [Tok] -> ParsecT [Tok] LaTeXState m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([[Tok]] -> [Tok]
forall a. Monoid a => [a] -> a
mconcat (Int -> [Tok] -> [[Tok]]
forall a. Int -> a -> [a]
replicate Int
n [Tok]
spec) [Tok] -> [Tok] -> [Tok]
forall a. [a] -> [a] -> [a]
++)
             Nothing -> SourceName -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) a. MonadFail m => SourceName -> m a
Prelude.fail (SourceName -> ParsecT [Tok] LaTeXState m ())
-> SourceName -> ParsecT [Tok] LaTeXState m ()
forall a b. (a -> b) -> a -> b
$ "Could not parse " SourceName -> SourceName -> SourceName
forall a. Semigroup a => a -> a -> a
<> Text -> SourceName
T.unpack Text
ds SourceName -> SourceName -> SourceName
forall a. Semigroup a => a -> a -> a
<> " as number"
  ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => LP m Tok
bgroup
  ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces
  ParsecT [Tok] LaTeXState m ()
maybeBar
  [(Alignment, Double, ([Tok], [Tok]))]
aligns' <- ParsecT [Tok] LaTeXState m (Alignment, Double, ([Tok], [Tok]))
-> LP m [(Alignment, Double, ([Tok], [Tok]))]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (ParsecT [Tok] LaTeXState m (Alignment, Double, ([Tok], [Tok]))
 -> LP m [(Alignment, Double, ([Tok], [Tok]))])
-> ParsecT [Tok] LaTeXState m (Alignment, Double, ([Tok], [Tok]))
-> LP m [(Alignment, Double, ([Tok], [Tok]))]
forall a b. (a -> b) -> a -> b
$ ParsecT [Tok] LaTeXState m (Alignment, Double, ([Tok], [Tok]))
-> ParsecT [Tok] LaTeXState m (Alignment, Double, ([Tok], [Tok]))
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT [Tok] LaTeXState m (Alignment, Double, ([Tok], [Tok]))
 -> ParsecT [Tok] LaTeXState m (Alignment, Double, ([Tok], [Tok])))
-> ParsecT [Tok] LaTeXState m (Alignment, Double, ([Tok], [Tok]))
-> ParsecT [Tok] LaTeXState m (Alignment, Double, ([Tok], [Tok]))
forall a b. (a -> b) -> a -> b
$ ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces ParsecT [Tok] LaTeXState m ()
-> ParsecT [Tok] LaTeXState m (Maybe ())
-> ParsecT [Tok] LaTeXState m (Maybe ())
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT [Tok] LaTeXState m ()
-> ParsecT [Tok] LaTeXState m (Maybe ())
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional ParsecT [Tok] LaTeXState m ()
starAlign ParsecT [Tok] LaTeXState m (Maybe ())
-> ParsecT [Tok] LaTeXState m (Alignment, Double, ([Tok], [Tok]))
-> ParsecT [Tok] LaTeXState m (Alignment, Double, ([Tok], [Tok]))
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
                            (ParsecT [Tok] LaTeXState m (Alignment, Double, ([Tok], [Tok]))
alignSpec ParsecT [Tok] LaTeXState m (Alignment, Double, ([Tok], [Tok]))
-> ParsecT [Tok] LaTeXState m ()
-> ParsecT [Tok] LaTeXState m (Alignment, Double, ([Tok], [Tok]))
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT [Tok] LaTeXState m ()
maybeBar)
  ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces
  ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => LP m Tok
egroup
  ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces
  [(Alignment, Double, ([Tok], [Tok]))]
-> LP m [(Alignment, Double, ([Tok], [Tok]))]
forall (m :: * -> *) a. Monad m => a -> m a
return [(Alignment, Double, ([Tok], [Tok]))]
aligns'

parseTableRow :: PandocMonad m
              => Text   -- ^ table environment name
              -> [([Tok], [Tok])] -- ^ pref/suffixes
              -> LP m [Blocks]
parseTableRow :: Text -> [([Tok], [Tok])] -> LP m [Blocks]
parseTableRow envname :: Text
envname prefsufs :: [([Tok], [Tok])]
prefsufs = do
  ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces ParsecT [Tok] LaTeXState m ()
-> ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Text -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => Text -> LP m ()
end_ Text
envname)
  let cols :: Int
cols = [([Tok], [Tok])] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [([Tok], [Tok])]
prefsufs
  -- add prefixes and suffixes in token stream:
  let celltoks :: ([Tok], [Tok]) -> ParsecT [Tok] LaTeXState m [Tok]
celltoks (pref :: [Tok]
pref, suff :: [Tok]
suff) = do
        SourcePos
prefpos <- ParsecT [Tok] LaTeXState m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
        [Tok]
contents <- [[Tok]] -> [Tok]
forall a. Monoid a => [a] -> a
mconcat ([[Tok]] -> [Tok])
-> ParsecT [Tok] LaTeXState m [[Tok]]
-> ParsecT [Tok] LaTeXState m [Tok]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
            ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m [[Tok]]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many ( (Blocks, [Tok]) -> [Tok]
forall a b. (a, b) -> b
snd ((Blocks, [Tok]) -> [Tok])
-> ParsecT [Tok] LaTeXState m (Blocks, [Tok])
-> ParsecT [Tok] LaTeXState m [Tok]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Blocks -> ParsecT [Tok] LaTeXState m (Blocks, [Tok])
forall (m :: * -> *) a. PandocMonad m => LP m a -> LP m (a, [Tok])
withRaw (Text -> LP m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "parbox" LP m Tok -> LP m Blocks -> LP m Blocks
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
parbox) -- #5711
                  ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m [Tok]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
                   (do ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m ()
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy
                         (() () -> LP m Tok -> ParsecT [Tok] LaTeXState m ()
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ LP m Tok
forall (m :: * -> *). PandocMonad m => LP m Tok
amp ParsecT [Tok] LaTeXState m ()
-> ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> () () -> LP m Tok -> ParsecT [Tok] LaTeXState m ()
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ LP m Tok
forall (m :: * -> *). PandocMonad m => LP m Tok
lbreak ParsecT [Tok] LaTeXState m ()
-> ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Text -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => Text -> LP m ()
end_ Text
envname)
                       Int -> LP m Tok -> ParsecT [Tok] LaTeXState m [Tok]
forall s (m :: * -> *) t u a.
Stream s m t =>
Int -> ParsecT s u m a -> ParsecT s u m [a]
count 1 LP m Tok
forall (m :: * -> *). PandocMonad m => LP m Tok
anyTok) )

        SourcePos
suffpos <- ParsecT [Tok] LaTeXState m SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
        [Tok]
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m [Tok]
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option [] (Int -> LP m Tok -> ParsecT [Tok] LaTeXState m [Tok]
forall s (m :: * -> *) t u a.
Stream s m t =>
Int -> ParsecT s u m a -> ParsecT s u m [a]
count 1 LP m Tok
forall (m :: * -> *). PandocMonad m => LP m Tok
amp)
        [Tok] -> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *) a. Monad m => a -> m a
return ([Tok] -> ParsecT [Tok] LaTeXState m [Tok])
-> [Tok] -> ParsecT [Tok] LaTeXState m [Tok]
forall a b. (a -> b) -> a -> b
$ (Tok -> Tok) -> [Tok] -> [Tok]
forall a b. (a -> b) -> [a] -> [b]
map (SourcePos -> Tok -> Tok
setpos SourcePos
prefpos) [Tok]
pref [Tok] -> [Tok] -> [Tok]
forall a. [a] -> [a] -> [a]
++ [Tok]
contents [Tok] -> [Tok] -> [Tok]
forall a. [a] -> [a] -> [a]
++ (Tok -> Tok) -> [Tok] -> [Tok]
forall a b. (a -> b) -> [a] -> [b]
map (SourcePos -> Tok -> Tok
setpos SourcePos
suffpos) [Tok]
suff
  [[Tok]]
rawcells <- (([Tok], [Tok]) -> ParsecT [Tok] LaTeXState m [Tok])
-> [([Tok], [Tok])] -> ParsecT [Tok] LaTeXState m [[Tok]]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM ([Tok], [Tok]) -> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *).
PandocMonad m =>
([Tok], [Tok]) -> ParsecT [Tok] LaTeXState m [Tok]
celltoks [([Tok], [Tok])]
prefsufs
  [Tok]
oldInput <- ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *) s u. Monad m => ParsecT s u m s
getInput
  [Blocks]
cells <- ([Tok] -> ParsecT [Tok] LaTeXState m Blocks)
-> [[Tok]] -> LP m [Blocks]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (\ts :: [Tok]
ts -> [Tok] -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) s u. Monad m => s -> ParsecT s u m ()
setInput [Tok]
ts ParsecT [Tok] LaTeXState m ()
-> ParsecT [Tok] LaTeXState m Blocks
-> ParsecT [Tok] LaTeXState m Blocks
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT [Tok] LaTeXState m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
parseTableCell) [[Tok]]
rawcells
  [Tok] -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) s u. Monad m => s -> ParsecT s u m ()
setInput [Tok]
oldInput
  ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces
  let numcells :: Int
numcells = [Blocks] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Blocks]
cells
  Bool -> ParsecT [Tok] LaTeXState m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT [Tok] LaTeXState m ())
-> Bool -> ParsecT [Tok] LaTeXState m ()
forall a b. (a -> b) -> a -> b
$ Int
numcells Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
cols Bool -> Bool -> Bool
&& Int
numcells Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= 1
  Bool -> ParsecT [Tok] LaTeXState m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ParsecT [Tok] LaTeXState m ())
-> Bool -> ParsecT [Tok] LaTeXState m ()
forall a b. (a -> b) -> a -> b
$ [Blocks]
cells [Blocks] -> [Blocks] -> Bool
forall a. Eq a => a -> a -> Bool
/= [Blocks
forall a. Monoid a => a
mempty]
  -- note:  a & b in a three-column table leaves an empty 3rd cell:
  [Blocks] -> LP m [Blocks]
forall (m :: * -> *) a. Monad m => a -> m a
return ([Blocks] -> LP m [Blocks]) -> [Blocks] -> LP m [Blocks]
forall a b. (a -> b) -> a -> b
$ [Blocks]
cells [Blocks] -> [Blocks] -> [Blocks]
forall a. [a] -> [a] -> [a]
++ Int -> Blocks -> [Blocks]
forall a. Int -> a -> [a]
replicate (Int
cols Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
numcells) Blocks
forall a. Monoid a => a
mempty

parseTableCell :: PandocMonad m => LP m Blocks
parseTableCell :: LP m Blocks
parseTableCell = do
  let plainify :: Blocks -> Blocks
plainify bs :: Blocks
bs = case Blocks -> [Block]
forall a. Many a -> [a]
toList Blocks
bs of
                         [Para ils :: [Inline]
ils] -> Inlines -> Blocks
plain ([Inline] -> Inlines
forall a. [a] -> Many a
fromList [Inline]
ils)
                         _          -> Blocks
bs
  (LaTeXState -> LaTeXState) -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((LaTeXState -> LaTeXState) -> ParsecT [Tok] LaTeXState m ())
-> (LaTeXState -> LaTeXState) -> ParsecT [Tok] LaTeXState m ()
forall a b. (a -> b) -> a -> b
$ \st :: LaTeXState
st -> LaTeXState
st{ sInTableCell :: Bool
sInTableCell = Bool
True }
  Blocks
cells <- Blocks -> Blocks
plainify (Blocks -> Blocks) -> LP m Blocks -> LP m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
blocks
  (LaTeXState -> LaTeXState) -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((LaTeXState -> LaTeXState) -> ParsecT [Tok] LaTeXState m ())
-> (LaTeXState -> LaTeXState) -> ParsecT [Tok] LaTeXState m ()
forall a b. (a -> b) -> a -> b
$ \st :: LaTeXState
st -> LaTeXState
st{ sInTableCell :: Bool
sInTableCell = Bool
False }
  Blocks -> LP m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
cells

simpTable :: PandocMonad m => Text -> Bool -> LP m Blocks
simpTable :: Text -> Bool -> LP m Blocks
simpTable envname :: Text
envname hasWidthParameter :: Bool
hasWidthParameter = LP m Blocks -> LP m Blocks
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (LP m Blocks -> LP m Blocks) -> LP m Blocks -> LP m Blocks
forall a b. (a -> b) -> a -> b
$ do
  Bool
-> ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
hasWidthParameter (ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m ())
-> ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m ()
forall a b. (a -> b) -> a -> b
$ () ()
-> ParsecT [Tok] LaTeXState m Inlines
-> ParsecT [Tok] LaTeXState m ()
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces ParsecT [Tok] LaTeXState m ()
-> ParsecT [Tok] LaTeXState m Inlines
-> ParsecT [Tok] LaTeXState m Inlines
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ParsecT [Tok] LaTeXState m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
tok)
  ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts
  [(Alignment, Double, ([Tok], [Tok]))]
colspecs <- LP m [(Alignment, Double, ([Tok], [Tok]))]
forall (m :: * -> *).
PandocMonad m =>
LP m [(Alignment, Double, ([Tok], [Tok]))]
parseAligns
  let (aligns :: [Alignment]
aligns, widths :: [Double]
widths, prefsufs :: [([Tok], [Tok])]
prefsufs) = [(Alignment, Double, ([Tok], [Tok]))]
-> ([Alignment], [Double], [([Tok], [Tok])])
forall a b c. [(a, b, c)] -> ([a], [b], [c])
unzip3 [(Alignment, Double, ([Tok], [Tok]))]
colspecs
  let cols :: Int
cols = [(Alignment, Double, ([Tok], [Tok]))] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [(Alignment, Double, ([Tok], [Tok]))]
colspecs
  ParsecT [Tok] LaTeXState m ()
-> ParsecT [Tok] LaTeXState m (Maybe ())
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (ParsecT [Tok] LaTeXState m ()
 -> ParsecT [Tok] LaTeXState m (Maybe ()))
-> ParsecT [Tok] LaTeXState m ()
-> ParsecT [Tok] LaTeXState m (Maybe ())
forall a b. (a -> b) -> a -> b
$ Text -> LP m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "caption" LP m Tok
-> ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
setCaption
  ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces
  ParsecT [Tok] LaTeXState m ()
-> ParsecT [Tok] LaTeXState m (Maybe ())
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
label
  ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces
  LP m Tok -> ParsecT [Tok] LaTeXState m (Maybe Tok)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional LP m Tok
forall (m :: * -> *). PandocMonad m => LP m Tok
lbreak
  ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces
  ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
hline
  ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces
  [Blocks]
header' <- [Blocks]
-> ParsecT [Tok] LaTeXState m [Blocks]
-> ParsecT [Tok] LaTeXState m [Blocks]
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option [] (ParsecT [Tok] LaTeXState m [Blocks]
 -> ParsecT [Tok] LaTeXState m [Blocks])
-> ParsecT [Tok] LaTeXState m [Blocks]
-> ParsecT [Tok] LaTeXState m [Blocks]
forall a b. (a -> b) -> a -> b
$ ParsecT [Tok] LaTeXState m [Blocks]
-> ParsecT [Tok] LaTeXState m [Blocks]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (Text -> [([Tok], [Tok])] -> ParsecT [Tok] LaTeXState m [Blocks]
forall (m :: * -> *).
PandocMonad m =>
Text -> [([Tok], [Tok])] -> LP m [Blocks]
parseTableRow Text
envname [([Tok], [Tok])]
prefsufs ParsecT [Tok] LaTeXState m [Blocks]
-> LP m Tok -> ParsecT [Tok] LaTeXState m [Blocks]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<*
                                   LP m Tok
forall (m :: * -> *). PandocMonad m => LP m Tok
lbreak ParsecT [Tok] LaTeXState m [Blocks]
-> ParsecT [Tok] LaTeXState m [()]
-> ParsecT [Tok] LaTeXState m [Blocks]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m [()]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
hline)
  ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces
  [[Blocks]]
rows <- ParsecT [Tok] LaTeXState m [Blocks]
-> LP m Tok -> ParsecT [Tok] LaTeXState m [[Blocks]]
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
sepEndBy (Text -> [([Tok], [Tok])] -> ParsecT [Tok] LaTeXState m [Blocks]
forall (m :: * -> *).
PandocMonad m =>
Text -> [([Tok], [Tok])] -> LP m [Blocks]
parseTableRow Text
envname [([Tok], [Tok])]
prefsufs)
                    (LP m Tok
forall (m :: * -> *). PandocMonad m => LP m Tok
lbreak LP m Tok -> ParsecT [Tok] LaTeXState m (Maybe ()) -> LP m Tok
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT [Tok] LaTeXState m ()
-> ParsecT [Tok] LaTeXState m (Maybe ())
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
hline))
  ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces
  ParsecT [Tok] LaTeXState m ()
-> ParsecT [Tok] LaTeXState m (Maybe ())
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (ParsecT [Tok] LaTeXState m ()
 -> ParsecT [Tok] LaTeXState m (Maybe ()))
-> ParsecT [Tok] LaTeXState m ()
-> ParsecT [Tok] LaTeXState m (Maybe ())
forall a b. (a -> b) -> a -> b
$ Text -> LP m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "caption" LP m Tok
-> ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
setCaption
  ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces
  ParsecT [Tok] LaTeXState m ()
-> ParsecT [Tok] LaTeXState m (Maybe ())
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
label
  ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces
  LP m Tok -> ParsecT [Tok] LaTeXState m (Maybe Tok)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional LP m Tok
forall (m :: * -> *). PandocMonad m => LP m Tok
lbreak
  ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces
  let header'' :: [Blocks]
header'' = if [Blocks] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Blocks]
header'
                    then Int -> Blocks -> [Blocks]
forall a. Int -> a -> [a]
replicate Int
cols Blocks
forall a. Monoid a => a
mempty
                    else [Blocks]
header'
  LP m Tok -> LP m Tok
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (LP m Tok -> LP m Tok) -> LP m Tok -> LP m Tok
forall a b. (a -> b) -> a -> b
$ Text -> LP m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "end" -- make sure we're at end
  Blocks -> LP m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return (Blocks -> LP m Blocks) -> Blocks -> LP m Blocks
forall a b. (a -> b) -> a -> b
$ Inlines
-> [(Alignment, Double)] -> [Blocks] -> [[Blocks]] -> Blocks
table Inlines
forall a. Monoid a => a
mempty ([Alignment] -> [Double] -> [(Alignment, Double)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Alignment]
aligns [Double]
widths) [Blocks]
header'' [[Blocks]]
rows

addTableCaption :: PandocMonad m => Blocks -> LP m Blocks
addTableCaption :: Blocks -> LP m Blocks
addTableCaption = (Block -> ParsecT [Tok] LaTeXState m Block)
-> Blocks -> LP m Blocks
forall a b (m :: * -> *).
(Walkable a b, Monad m, Applicative m, Functor m) =>
(a -> m a) -> b -> m b
walkM Block -> ParsecT [Tok] LaTeXState m Block
forall (m :: * -> *).
Monad m =>
Block -> ParsecT [Tok] LaTeXState m Block
go
  where go :: Block -> ParsecT [Tok] LaTeXState m Block
go (Table c :: [Inline]
c als :: [Alignment]
als ws :: [Double]
ws hs :: [[Block]]
hs rs :: [[[Block]]]
rs) = do
          LaTeXState
st <- ParsecT [Tok] LaTeXState m LaTeXState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
          let mblabel :: Maybe Text
mblabel = LaTeXState -> Maybe Text
sLastLabel LaTeXState
st
          [Inline]
capt <- case (LaTeXState -> Maybe Inlines
sCaption LaTeXState
st, Maybe Text
mblabel) of
                   (Just ils :: Inlines
ils, Nothing)  -> [Inline] -> ParsecT [Tok] LaTeXState m [Inline]
forall (m :: * -> *) a. Monad m => a -> m a
return ([Inline] -> ParsecT [Tok] LaTeXState m [Inline])
-> [Inline] -> ParsecT [Tok] LaTeXState m [Inline]
forall a b. (a -> b) -> a -> b
$ Inlines -> [Inline]
forall a. Many a -> [a]
toList Inlines
ils
                   (Just ils :: Inlines
ils, Just lab :: Text
lab) -> do
                     DottedNum
num <- (LaTeXState -> DottedNum) -> LP m DottedNum
forall (m :: * -> *).
Monad m =>
(LaTeXState -> DottedNum) -> LP m DottedNum
getNextNumber LaTeXState -> DottedNum
sLastTableNum
                     LaTeXState -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) u s. Monad m => u -> ParsecT s u m ()
setState
                       LaTeXState
st{ sLastTableNum :: DottedNum
sLastTableNum = DottedNum
num
                         , sLabels :: Map Text [Inline]
sLabels = Text -> [Inline] -> Map Text [Inline] -> Map Text [Inline]
forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert Text
lab
                                    [Text -> Inline
Str (DottedNum -> Text
renderDottedNum DottedNum
num)]
                                    (LaTeXState -> Map Text [Inline]
sLabels LaTeXState
st) }
                     [Inline] -> ParsecT [Tok] LaTeXState m [Inline]
forall (m :: * -> *) a. Monad m => a -> m a
return ([Inline] -> ParsecT [Tok] LaTeXState m [Inline])
-> [Inline] -> ParsecT [Tok] LaTeXState m [Inline]
forall a b. (a -> b) -> a -> b
$ Inlines -> [Inline]
forall a. Many a -> [a]
toList Inlines
ils -- add number??
                   (Nothing, _)  -> [Inline] -> ParsecT [Tok] LaTeXState m [Inline]
forall (m :: * -> *) a. Monad m => a -> m a
return [Inline]
c
          Block -> ParsecT [Tok] LaTeXState m Block
forall (m :: * -> *) a. Monad m => a -> m a
return (Block -> ParsecT [Tok] LaTeXState m Block)
-> Block -> ParsecT [Tok] LaTeXState m Block
forall a b. (a -> b) -> a -> b
$ (Block -> Block)
-> (Text -> Block -> Block) -> Maybe Text -> Block -> Block
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Block -> Block
forall a. a -> a
id (\ident :: Text
ident -> Attr -> [Block] -> Block
Div (Text
ident, [], []) ([Block] -> Block) -> (Block -> [Block]) -> Block -> Block
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Block -> [Block] -> [Block]
forall a. a -> [a] -> [a]
:[])) Maybe Text
mblabel (Block -> Block) -> Block -> Block
forall a b. (a -> b) -> a -> b
$
                     [Inline]
-> [Alignment] -> [Double] -> [[Block]] -> [[[Block]]] -> Block
Table [Inline]
capt [Alignment]
als [Double]
ws [[Block]]
hs [[[Block]]]
rs
        go x :: Block
x = Block -> ParsecT [Tok] LaTeXState m Block
forall (m :: * -> *) a. Monad m => a -> m a
return Block
x


block :: PandocMonad m => LP m Blocks
block :: LP m Blocks
block = do
  Blocks
res <- (Blocks
forall a. Monoid a => a
mempty Blocks -> ParsecT [Tok] LaTeXState m () -> LP m Blocks
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces1)
    LP m Blocks -> LP m Blocks -> LP m Blocks
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
environment
    LP m Blocks -> LP m Blocks -> LP m Blocks
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Text -> Blocks) -> LP m Blocks
forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
(Text -> a) -> LP m a
macroDef (Text -> Text -> Blocks
rawBlock "latex")
    LP m Blocks -> LP m Blocks -> LP m Blocks
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
blockCommand
    LP m Blocks -> LP m Blocks -> LP m Blocks
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
paragraph
    LP m Blocks -> LP m Blocks -> LP m Blocks
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> LP m Blocks -> LP m Blocks
forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
grouped LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
block
  Text -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => Text -> m ()
trace (Int -> Text -> Text
T.take 60 (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ [Block] -> Text
forall a. Show a => a -> Text
tshow ([Block] -> Text) -> [Block] -> Text
forall a b. (a -> b) -> a -> b
$ Blocks -> [Block]
forall a. Many a -> [a]
B.toList Blocks
res)
  Blocks -> LP m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
res

blocks :: PandocMonad m => LP m Blocks
blocks :: LP m Blocks
blocks = [Blocks] -> Blocks
forall a. Monoid a => [a] -> a
mconcat ([Blocks] -> Blocks)
-> ParsecT [Tok] LaTeXState m [Blocks] -> LP m Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Blocks -> ParsecT [Tok] LaTeXState m [Blocks]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many LP m Blocks
forall (m :: * -> *). PandocMonad m => LP m Blocks
block

setDefaultLanguage :: PandocMonad m => LP m Blocks
setDefaultLanguage :: LP m Blocks
setDefaultLanguage = do
  Text
o <- Text
-> ParsecT [Tok] LaTeXState m Text
-> ParsecT [Tok] LaTeXState m Text
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option "" (ParsecT [Tok] LaTeXState m Text
 -> ParsecT [Tok] LaTeXState m Text)
-> ParsecT [Tok] LaTeXState m Text
-> ParsecT [Tok] LaTeXState m Text
forall a b. (a -> b) -> a -> b
$ (Char -> Bool) -> Text -> Text
T.filter (\c :: Char
c -> Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= '[' Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= ']')
                (Text -> Text)
-> ParsecT [Tok] LaTeXState m Text
-> ParsecT [Tok] LaTeXState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m Text
forall (m :: * -> *). PandocMonad m => LP m Text
rawopt
  Text
polylang <- [Tok] -> Text
untokenize ([Tok] -> Text)
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
  case Text -> Map Text (Text -> Lang) -> Maybe (Text -> Lang)
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Text
polylang Map Text (Text -> Lang)
polyglossiaLangToBCP47 of
       Nothing -> Blocks -> LP m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
forall a. Monoid a => a
mempty -- TODO mzero? warning?
       Just langFunc :: Text -> Lang
langFunc -> do
         let l :: Lang
l = Text -> Lang
langFunc Text
o
         Lang -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => Lang -> m ()
setTranslations Lang
l
         (LaTeXState -> LaTeXState) -> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((LaTeXState -> LaTeXState) -> ParsecT [Tok] LaTeXState m ())
-> (LaTeXState -> LaTeXState) -> ParsecT [Tok] LaTeXState m ()
forall a b. (a -> b) -> a -> b
$ Text -> Inlines -> LaTeXState -> LaTeXState
forall a b. (HasMeta a, ToMetaValue b) => Text -> b -> a -> a
setMeta "lang" (Inlines -> LaTeXState -> LaTeXState)
-> Inlines -> LaTeXState -> LaTeXState
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
str (Lang -> Text
renderLang Lang
l)
         Blocks -> LP m Blocks
forall (m :: * -> *) a. Monad m => a -> m a
return Blocks
forall a. Monoid a => a
mempty