From 581c94913fa055fa0d925db893991f01647b37f6 Mon Sep 17 00:00:00 2001
From: John MacFarlane <jgm@berkeley.edu>
Date: Wed, 9 Mar 2022 17:40:15 -0800
Subject: [PATCH] LaTeX reader: allow inline groups starting with `\bgroup`.

Closes #7953.
---
 src/Text/Pandoc/Readers/LaTeX.hs |  2 +-
 test/command/7953.md             | 11 +++++++++++
 test/command/tex-group.md        |  2 +-
 3 files changed, 13 insertions(+), 2 deletions(-)
 create mode 100644 test/command/7953.md

diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs
index 107c9f1fc..571a9ef88 100644
--- a/src/Text/Pandoc/Readers/LaTeX.hs
+++ b/src/Text/Pandoc/Readers/LaTeX.hs
@@ -639,9 +639,9 @@ inline = do
         "}"     -> mzero
         _       -> symbolAsString
     CtrlSeq _   -> macroDef (rawInline "latex")
+                  <|> inlineGroup
                   <|> inlineCommand'
                   <|> inlineEnvironment
-                  <|> inlineGroup
     _           -> mzero
 
 inlines :: PandocMonad m => LP m Inlines
diff --git a/test/command/7953.md b/test/command/7953.md
new file mode 100644
index 000000000..118aea2b6
--- /dev/null
+++ b/test/command/7953.md
@@ -0,0 +1,11 @@
+```
+% pandoc -f latex -t native
+{foo\bgroup bar\egroup }
+^D
+[ Para
+    [ Span
+        ( "" , [] , [] )
+        [ Str "foo" , Span ( "" , [] , [] ) [ Str "bar" ] ]
+    ]
+]
+```
diff --git a/test/command/tex-group.md b/test/command/tex-group.md
index 277b32142..cc0ed219b 100644
--- a/test/command/tex-group.md
+++ b/test/command/tex-group.md
@@ -8,5 +8,5 @@
 hi
 \end{foo}
 ^D
-<p><em>hi</em></p>
+<p><span> <em>hi</em> </span></p>
 ```