@@ -1,4 +1,5 @@
1{-# LANGUAGE OverloadedStrings #-}
1{-# LANGUAGE OverloadedStrings #-}
2+{-# LANGUAGE ViewPatterns #-}
3 Module : Text.Pandoc.Readers.LaTeX.Inline
4 Module : Text.Pandoc.Readers.LaTeX.Inline
4 Copyright : Copyright (C) 2006-2021 John MacFarlane
5 Copyright : Copyright (C) 2006-2021 John MacFarlane
@@ -12,6 +13,7 @@ module Text.Pandoc.Readers.LaTeX.Inline
12 ( acronymCommands
13 ( acronymCommands
13 , verbCommands
14 , verbCommands
14 , charCommands
15 , charCommands
15 , nameCommands
17 , nameCommands
16 , biblatexInlineCommands
18 , biblatexInlineCommands
17 , refCommands
19 , refCommands
@@ -33,11 +35,12 @@ import Text.Pandoc.Readers.LaTeX.Parsing
33import Text.Pandoc.Extensions (extensionEnabled, Extension(..))
35import Text.Pandoc.Extensions (extensionEnabled, Extension(..))
34import Text.Pandoc.Parsing (getOption, updateState, getState, notFollowedBy,
36import Text.Pandoc.Parsing (getOption, updateState, getState, notFollowedBy,
35 manyTill, getInput, setInput, incSourceColumn,
37 manyTill, getInput, setInput, incSourceColumn,
36− option, many1)
38+ option, many1, try)
37import Data.Char (isDigit)
39import Data.Char (isDigit)
38import Text.Pandoc.Highlighting (fromListingsLanguage,)
40import Text.Pandoc.Highlighting (fromListingsLanguage,)
39−import Data.Maybe (maybeToList)
41+import Data.Maybe (maybeToList, fromMaybe)
40import Text.Pandoc.Options (ReaderOptions(..))
42import Text.Pandoc.Options (ReaderOptions(..))
43+import qualified Data.Text.Normalize as Normalize
41import qualified Text.Pandoc.Translations as Translations
44import qualified Text.Pandoc.Translations as Translations
43rawInlineOr :: PandocMonad m => Text -> LP m Inlines -> LP m Inlines
46rawInlineOr :: PandocMonad m => Text -> LP m Inlines -> LP m Inlines
@@ -155,6 +158,22 @@ romanNumeralArg = spaces *> (parser <|> inBraces)
155 Prelude.fail "Non-digits in argument to \\Rn or \\RN"
158 Prelude.fail "Non-digits in argument to \\Rn or \\RN"
156 safeRead digits
159 safeRead digits
161+accentWith :: PandocMonad m
162+ => LP m Inlines -> Char -> Maybe Char -> LP m Inlines
163+accentWith tok combiningAccent fallBack = try $ do
166+ (Str (T.uncons -> Just (x, xs)) : ys) -> return $ fromList $
167+ -- try to normalize to the combined character:
168+ Str (Normalize.normalize Normalize.NFC
169+ (T.pack [x, combiningAccent]) <> xs) : ys
170+ [Space] -> return $ str $ T.singleton
171+ $ fromMaybe combiningAccent fallBack
172+ [] -> return $ str $ T.singleton
173+ $ fromMaybe combiningAccent fallBack
158verbCommands :: PandocMonad m => M.Map Text (LP m Inlines)
177verbCommands :: PandocMonad m => M.Map Text (LP m Inlines)
159verbCommands = M.fromList
178verbCommands = M.fromList
160 [ ("verb", doverb)
179 [ ("verb", doverb)
@@ -163,7 +182,53 @@ verbCommands = M.fromList
163 , ("Verb", doverb)
182 , ("Verb", doverb)
166−
185+accentCommands :: PandocMonad m => LP m Inlines -> M.Map Text (LP m Inlines)
187+ let accent = accentWith tok
200+ , ("pounds", lit "£")
202+ , ("copyright", lit "©")
203+ , ("textasciicircum", lit "^")
204+ , ("textasciitilde", lit "~")
205+ , ("H", accent '\779' Nothing) -- hungarumlaut
206+ , ("`", accent '\768' (Just '`')) -- grave
207+ , ("'", accent '\769' (Just '\'')) -- acute
208+ , ("^", accent '\770' (Just '^')) -- circ
209+ , ("~", accent '\771' (Just '~')) -- tilde
210+ , ("\"", accent '\776' Nothing) -- umlaut
211+ , (".", accent '\775' Nothing) -- dot
212+ , ("=", accent '\772' Nothing) -- macron
213+ , ("|", accent '\781' Nothing) -- vertical line above
214+ , ("b", accent '\817' Nothing) -- macron below
215+ , ("c", accent '\807' Nothing) -- cedilla
216+ , ("G", accent '\783' Nothing) -- doublegrave
217+ , ("h", accent '\777' Nothing) -- hookabove
218+ , ("d", accent '\803' Nothing) -- dotbelow
219+ , ("f", accent '\785' Nothing) -- inverted breve
220+ , ("r", accent '\778' Nothing) -- ringabove
221+ , ("t", accent '\865' Nothing) -- double inverted breve
222+ , ("U", accent '\782' Nothing) -- double vertical line above
223+ , ("v", accent '\780' Nothing) -- hacek
224+ , ("u", accent '\774' Nothing) -- breve
225+ , ("k", accent '\808' Nothing) -- ogonek
226+ , ("textogonekcentered", accent '\808' Nothing) -- ogonek
227+ , ("i", lit "ı") -- dotless i
228+ , ("j", lit "ȷ") -- dotless j
229+ , ("newtie", accent '\785' Nothing) -- inverted breve
230+ , ("textcircled", accent '\8413' Nothing) -- combining circle
168charCommands :: PandocMonad m => M.Map Text (LP m Inlines)
233charCommands :: PandocMonad m => M.Map Text (LP m Inlines)
169charCommands = M.fromList
234charCommands = M.fromList