From 11df2a3c0f2b1b8e351ad8caaa7cdf583e1b3b2e Mon Sep 17 00:00:00 2001
From: John MacFarlane <jgm@berkeley.edu>
Date: Tue, 7 Apr 2020 09:24:26 -0700
Subject: [PATCH] LaTeX reader: better handling of `\lettrine`.

- SmallCaps instead of Span for the part after the initial capital.
- Ensure that both arguments are parsed, so that in Markdown both
  are treated as raw LateX. (Closes #6258.)
---
 src/Text/Pandoc/Readers/LaTeX.hs | 9 ++++++++-
 test/command/lettrine.md         | 4 ++--
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs
index 59339c606..038430f99 100644
--- a/src/Text/Pandoc/Readers/LaTeX.hs
+++ b/src/Text/Pandoc/Readers/LaTeX.hs
@@ -923,7 +923,7 @@ inlineCommands = M.union inlineLanguageCommands $ M.fromList
   , ("eqref", rawInlineOr "eqref" $ doref "eqref")   -- from amsmath.sty
   , ("mbox", rawInlineOr "mbox" $ processHBox <$> tok)
   , ("hbox", rawInlineOr "hbox" $ processHBox <$> tok)
-  , ("lettrine", optional opt >> extractSpaces (spanWith ("",["lettrine"],[])) <$> tok)
+  , ("lettrine", rawInlineOr "lettrine" $ lettrine)
   , ("(", mathInline . untokenize <$> manyTill anyTok (controlSeq ")"))
   , ("[", mathDisplay . untokenize <$> manyTill anyTok (controlSeq "]"))
   , ("ensuremath", mathInline . untokenize <$> braced)
@@ -1178,6 +1178,13 @@ inlineCommands = M.union inlineLanguageCommands $ M.fromList
   , ("ifdim", ifdim)
   ]
 
+lettrine :: PandocMonad m => LP m Inlines
+lettrine = do
+  optional opt
+  x <- tok
+  y <- tok
+  return $ extractSpaces (spanWith ("",["lettrine"],[])) x <> smallcaps y
+
 ifdim :: PandocMonad m => LP m Inlines
 ifdim = do
   contents <- manyTill anyTok (controlSeq "fi")
diff --git a/test/command/lettrine.md b/test/command/lettrine.md
index 0c3c64d66..7bbc20080 100644
--- a/test/command/lettrine.md
+++ b/test/command/lettrine.md
@@ -4,6 +4,6 @@
 
 \lettrine[lhang=0.17]{A}{category} is
 ^D
-[Para [Span ("",["lettrine"],[]) [Str "A"],Span ("",[],[]) [Str "category"],Space,Str "is"]
-,Para [Span ("",["lettrine"],[]) [Str "A"],Span ("",[],[]) [Str "category"],Space,Str "is"]]
+[Para [Span ("",["lettrine"],[]) [Str "A"],SmallCaps [Str "category"],Space,Str "is"]
+,Para [Span ("",["lettrine"],[]) [Str "A"],SmallCaps [Str "category"],Space,Str "is"]]
 ```