@@ -159,6 +159,7 @@ data LaTeXState = LaTeXState{ sOptions :: ReaderOptions
159 , sInTableCell :: Bool
159 , sInTableCell :: Bool
160 , sLastHeaderNum :: HeaderNum
160 , sLastHeaderNum :: HeaderNum
161 , sLabels :: M.Map String [Inline]
161 , sLabels :: M.Map String [Inline]
162+ , sToggles :: M.Map String Bool
163 deriving Show
164 deriving Show
@@ -177,6 +178,7 @@ defaultLaTeXState = LaTeXState{ sOptions = def
177 , sInTableCell = False
178 , sInTableCell = False
178 , sLastHeaderNum = HeaderNum []
179 , sLastHeaderNum = HeaderNum []
179 , sLabels = M.empty
180 , sLabels = M.empty
181+ , sToggles = M.empty
182instance PandocMonad m => HasQuoteContext LaTeXState m where
184instance PandocMonad m => HasQuoteContext LaTeXState m where
@@ -704,16 +706,16 @@ enquote = do
704doAcronym :: PandocMonad m => String -> LP m Inlines
706doAcronym :: PandocMonad m => String -> LP m Inlines
705doAcronym form = do
707doAcronym form = do
706 acro <- braced
708 acro <- braced
707− return . mconcat $ [spanWith ("",[],[("acronym-label", toksToString acro),
709+ return . mconcat $ [spanWith ("",[],[("acronym-label", toksToString acro),
708− ("acronym-form", "singular+" ++ form)])
710+ ("acronym-form", "singular+" ++ form)])
709 $ str $ toksToString acro]
711 $ str $ toksToString acro]
711doAcronymPlural :: PandocMonad m => String -> LP m Inlines
713doAcronymPlural :: PandocMonad m => String -> LP m Inlines
712doAcronymPlural form = do
714doAcronymPlural form = do
713 acro <- braced
715 acro <- braced
714 plural <- lit "s"
716 plural <- lit "s"
715− return . mconcat $ [spanWith ("",[],[("acronym-label", toksToString acro),
717+ return . mconcat $ [spanWith ("",[],[("acronym-label", toksToString acro),
716− ("acronym-form", "plural+" ++ form)]) $ mconcat
718+ ("acronym-form", "plural+" ++ form)]) $ mconcat
717 $ [str $ toksToString acro, plural]]
719 $ [str $ toksToString acro, plural]]
719doverb :: PandocMonad m => LP m Inlines
721doverb :: PandocMonad m => LP m Inlines
@@ -1440,12 +1442,46 @@ inlineCommands = M.fromList $
1440 , ("xspace", doxspace)
1442 , ("xspace", doxspace)
1441 -- etoolbox
1443 -- etoolbox
1442 , ("ifstrequal", ifstrequal)
1444 , ("ifstrequal", ifstrequal)
1445+ , ("newtoggle", braced >>= newToggle)
1446+ , ("toggletrue", braced >>= setToggle True)
1447+ , ("togglefalse", braced >>= setToggle False)
1448+ , ("iftoggle", try $ ifToggle >> inline)
1451+newToggle :: (Monoid a, PandocMonad m) => [Tok] -> LP m a
1453+ updateState $ \st ->
1454+ st{ sToggles = M.insert (toksToString name) False (sToggles st) }
1457+setToggle :: (Monoid a, PandocMonad m) => Bool -> [Tok] -> LP m a
1458+setToggle on name = do
1459+ updateState $ \st ->
1460+ st{ sToggles = M.adjust (const on) (toksToString name) (sToggles st) }
1463+ifToggle :: PandocMonad m => LP m ()
1470+ toggles <- sToggles <$> getState
1472+ let name' = toksToString name
1473+ case M.lookup name' toggles of
1474+ Just True -> setInput (yes ++ inp)
1475+ Just False -> setInput (no ++ inp)
1478+ report $ UndefinedToggle name' pos
1445doTerm :: PandocMonad m => Translations.Term -> LP m Inlines
1481doTerm :: PandocMonad m => Translations.Term -> LP m Inlines
1446doTerm term = str <$> translateTerm term
1482doTerm term = str <$> translateTerm term
1448−ifstrequal :: PandocMonad m => LP m Inlines
1484+ifstrequal :: (PandocMonad m, Monoid a) => LP m a
1449ifstrequal = do
1485ifstrequal = do
1450 str1 <- tok
1486 str1 <- tok
1451 str2 <- tok
1487 str2 <- tok
@@ -1964,6 +2000,12 @@ environments = M.fromList
1964 , ("alignat", mathEnvWith para (Just "aligned") "alignat")
2000 , ("alignat", mathEnvWith para (Just "aligned") "alignat")
1965 , ("alignat*", mathEnvWith para (Just "aligned") "alignat*")
2001 , ("alignat*", mathEnvWith para (Just "aligned") "alignat*")
1966 , ("tikzpicture", rawVerbEnv "tikzpicture")
2002 , ("tikzpicture", rawVerbEnv "tikzpicture")
2004+ , ("ifstrequal", ifstrequal)
2005+ , ("newtoggle", braced >>= newToggle)
2006+ , ("toggletrue", braced >>= setToggle True)
2007+ , ("togglefalse", braced >>= setToggle False)
2008+ , ("iftoggle", try $ ifToggle >> block)
1969environment :: PandocMonad m => LP m Blocks
2011environment :: PandocMonad m => LP m Blocks