@@ -159,6 +159,7 @@ data LaTeXState = LaTeXState{ sOptions :: ReaderOptions
159159 , sInTableCell :: Bool
160160 , sLastHeaderNum :: HeaderNum
161161 , sLabels :: M.Map String [Inline]
162+ , sToggles :: M.Map String Bool
162163 }
163164 deriving Show
164165
@@ -177,6 +178,7 @@ defaultLaTeXState = LaTeXState{ sOptions = def
177178 , sInTableCell = False
178179 , sLastHeaderNum = HeaderNum []
179180 , sLabels = M.empty
181+ , sToggles = M.empty
180182 }
181183
182184instance PandocMonad m => HasQuoteContext LaTeXState m where
@@ -704,16 +706,16 @@ enquote = do
704706doAcronym :: PandocMonad m => String -> LP m Inlines
705707doAcronym form = do
706708 acro <- braced
707− return . mconcat $ [spanWith ("",[],[("acronym-label", toksToString acro),
708− ("acronym-form", "singular+" ++ form)])
709+ return . mconcat $ [spanWith ("",[],[("acronym-label", toksToString acro),
710+ ("acronym-form", "singular+" ++ form)])
709711 $ str $ toksToString acro]
710712
711713doAcronymPlural :: PandocMonad m => String -> LP m Inlines
712714doAcronymPlural form = do
713715 acro <- braced
714716 plural <- lit "s"
715− return . mconcat $ [spanWith ("",[],[("acronym-label", toksToString acro),
716− ("acronym-form", "plural+" ++ form)]) $ mconcat
717+ return . mconcat $ [spanWith ("",[],[("acronym-label", toksToString acro),
718+ ("acronym-form", "plural+" ++ form)]) $ mconcat
717719 $ [str $ toksToString acro, plural]]
718720
719721doverb :: PandocMonad m => LP m Inlines
@@ -1440,12 +1442,46 @@ inlineCommands = M.fromList $
14401442 , ("xspace", doxspace)
14411443 -- etoolbox
14421444 , ("ifstrequal", ifstrequal)
1445+ , ("newtoggle", braced >>= newToggle)
1446+ , ("toggletrue", braced >>= setToggle True)
1447+ , ("togglefalse", braced >>= setToggle False)
1448+ , ("iftoggle", try $ ifToggle >> inline)
14431449 ]
14441450
1451+newToggle :: (Monoid a, PandocMonad m) => [Tok] -> LP m a
1452+newToggle name = do
1453+ updateState $ \st ->
1454+ st{ sToggles = M.insert (toksToString name) False (sToggles st) }
1455+ return mempty
1456+
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) }
1461+ return mempty
1462+
1463+ifToggle :: PandocMonad m => LP m ()
1464+ifToggle = do
1465+ name <- braced
1466+ spaces
1467+ yes <- braced
1468+ spaces
1469+ no <- braced
1470+ toggles <- sToggles <$> getState
1471+ inp <- getInput
1472+ let name' = toksToString name
1473+ case M.lookup name' toggles of
1474+ Just True -> setInput (yes ++ inp)
1475+ Just False -> setInput (no ++ inp)
1476+ Nothing -> do
1477+ pos <- getPosition
1478+ report $ UndefinedToggle name' pos
1479+ return ()
1480+
14451481doTerm :: PandocMonad m => Translations.Term -> LP m Inlines
14461482doTerm term = str <$> translateTerm term
14471483
1448−ifstrequal :: PandocMonad m => LP m Inlines
1484+ifstrequal :: (PandocMonad m, Monoid a) => LP m a
14491485ifstrequal = do
14501486 str1 <- tok
14511487 str2 <- tok
@@ -1964,6 +2000,12 @@ environments = M.fromList
19642000 , ("alignat", mathEnvWith para (Just "aligned") "alignat")
19652001 , ("alignat*", mathEnvWith para (Just "aligned") "alignat*")
19662002 , ("tikzpicture", rawVerbEnv "tikzpicture")
2003+ -- etoolbox
2004+ , ("ifstrequal", ifstrequal)
2005+ , ("newtoggle", braced >>= newToggle)
2006+ , ("toggletrue", braced >>= setToggle True)
2007+ , ("togglefalse", braced >>= setToggle False)
2008+ , ("iftoggle", try $ ifToggle >> block)
19672009 ]
19682010
19692011environment :: PandocMonad m => LP m Blocks