From 42b915e65624df9f910769604889a3c1c9fc6845 Mon Sep 17 00:00:00 2001
From: John MacFarlane <jgm@berkeley.edu>
Date: Fri, 10 Jan 2020 08:26:33 -0800
Subject: [PATCH] LaTeX reader: allow beamer overlays for all commands in all
 raw tex.

This affecs parsing of raw tex in LaTeX and in Markdown and
other formats.

Closes #6043.
---
 src/Text/Pandoc/Readers/LaTeX.hs | 20 ++++++++++----------
 test/command/6043.md             |  8 ++++++++
 2 files changed, 18 insertions(+), 10 deletions(-)
 create mode 100644 test/command/6043.md

diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs
index bfade7284..c7c778193 100644
--- a/src/Text/Pandoc/Readers/LaTeX.hs
+++ b/src/Text/Pandoc/Readers/LaTeX.hs
@@ -773,7 +773,8 @@ inlineCommand' = try $ do
   Tok _ (CtrlSeq name) cmd <- anyControlSeq
   guard $ name /= "begin" && name /= "end"
   star <- option "" ("*" <$ symbol '*' <* optional sp)
-  let name' = name <> star
+  overlay <- option "" overlaySpecification
+  let name' = name <> star <> overlay
   let names = ordNub [name', name] -- check non-starred as fallback
   let raw = do
        guard $ isInlineCommand name || not (isBlockCommand name)
@@ -802,19 +803,18 @@ rawopt = try $ do
   return $ "[" <> inner <> "]"
 
 skipopts :: PandocMonad m => LP m ()
-skipopts = skipMany (overlaySpecification <|> void rawopt)
+skipopts = skipMany (void overlaySpecification <|> void rawopt)
 
 -- opts in angle brackets are used in beamer
-overlaySpecification :: PandocMonad m => LP m ()
+overlaySpecification :: PandocMonad m => LP m Text
 overlaySpecification = try $ do
   symbol '<'
-  ts <- manyTill overlayTok (symbol '>')
-  guard $ case ts of
-               -- see issue #3368
-               [Tok _ Word s] | T.all isLetter s -> s `elem`
-                                ["beamer","presentation", "trans",
-                                 "handout","article", "second"]
-               _ -> True
+  t <- untokenize <$> manyTill overlayTok (symbol '>')
+  -- see issue #3368
+  guard $ not (T.all isLetter t) ||
+          t `elem` ["beamer","presentation", "trans",
+                    "handout","article", "second"]
+  return $ "<" <> t <> ">"
 
 overlayTok :: PandocMonad m => LP m Tok
 overlayTok =
diff --git a/test/command/6043.md b/test/command/6043.md
new file mode 100644
index 000000000..a3f39a44b
--- /dev/null
+++ b/test/command/6043.md
@@ -0,0 +1,8 @@
+```
+% pandoc -t beamer
+\textbf<1>{Bold Text On Slide1}
+^D
+\begin{frame}
+\textbf<1>{Bold Text On Slide1}
+\end{frame}
+```