diff options
| author | John MacFarlane <[email protected]> | 2022-08-24 09:35:25 -0700 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2022-08-24 09:36:13 -0700 |
| commit | 488ad80a20e71db187291ec32fd96c85814bf848 (patch) | |
| tree | bb69c91775bc6ac37538e63cfaaea727fecaa86c /src | |
| parent | 373a3255a0644dd6bf6ac978fa5e70be63d4ce2a (diff) | |
LaTeX reader: handle `##` macro arguments properly.
These turn into regular `#` arguments when expanded.
Closes #8243.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Text/Pandoc/Readers/LaTeX/Macro.hs | 2 | ||||
| -rw-r--r-- | src/Text/Pandoc/Readers/LaTeX/Parsing.hs | 28 | ||||
| -rw-r--r-- | src/Text/Pandoc/Readers/LaTeX/Types.hs | 2 |
3 files changed, 22 insertions, 10 deletions
diff --git a/src/Text/Pandoc/Readers/LaTeX/Macro.hs b/src/Text/Pandoc/Readers/LaTeX/Macro.hs index 6706fae14..4756c5381 100644 --- a/src/Text/Pandoc/Readers/LaTeX/Macro.hs +++ b/src/Text/Pandoc/Readers/LaTeX/Macro.hs @@ -216,7 +216,7 @@ newenvironment = do let result = (name, Macro GroupScope ExpandWhenUsed argspecs optarg (bg:startcontents), - Macro GroupScope ExpandWhenUsed [] Nothing + Macro GroupScope ExpandWhenUsed argspecs optarg (endcontents ++ [eg])) (do lookupMacro name case mtype of diff --git a/src/Text/Pandoc/Readers/LaTeX/Parsing.hs b/src/Text/Pandoc/Readers/LaTeX/Parsing.hs index 8d7181689..7528e8623 100644 --- a/src/Text/Pandoc/Readers/LaTeX/Parsing.hs +++ b/src/Text/Pandoc/Readers/LaTeX/Parsing.hs @@ -414,14 +414,24 @@ tokenize = totoks Tok pos (CtrlSeq (T.singleton d)) (T.pack [c,d]) : totoks (incSourceColumn pos 2) rest' | c == '#' -> - let (t1, t2) = T.span (\d -> d >= '0' && d <= '9') rest - in case safeRead t1 of - Just i -> - Tok pos (Arg i) ("#" <> t1) - : totoks (incSourceColumn pos (1 + T.length t1)) t2 - Nothing -> - Tok pos Symbol "#" - : totoks (incSourceColumn pos 1) t2 + case T.uncons rest of + Just ('#', t3) -> + let (t1, t2) = T.span (\d -> d >= '0' && d <= '9') t3 + in case safeRead t1 of + Just i -> + Tok pos (DeferredArg i) ("##" <> t1) + : totoks (incSourceColumn pos (2 + T.length t1)) t2 + Nothing -> Tok pos Symbol "#" + : Tok (incSourceColumn pos 1) Symbol "#" + : totoks (incSourceColumn pos 1) t2 + _ -> + let (t1, t2) = T.span (\d -> d >= '0' && d <= '9') rest + in case safeRead t1 of + Just i -> + Tok pos (Arg i) ("#" <> t1) + : totoks (incSourceColumn pos (1 + T.length t1)) t2 + Nothing -> Tok pos Symbol "#" + : totoks (incSourceColumn pos 1) rest | c == '^' -> case T.uncons rest of Just ('^', rest') -> @@ -571,6 +581,8 @@ doMacros' n inp = x <- try $ spaces >> bracedOrToken getargs (M.insert i x argmap) rest + addTok False _args spos (Tok _ (DeferredArg i) txt) acc = + Tok spos (Arg i) txt : acc addTok False args spos (Tok _ (Arg i) _) acc = case M.lookup i args of Nothing -> mzero diff --git a/src/Text/Pandoc/Readers/LaTeX/Types.hs b/src/Text/Pandoc/Readers/LaTeX/Types.hs index 7157c5dee..ce85fc43a 100644 --- a/src/Text/Pandoc/Readers/LaTeX/Types.hs +++ b/src/Text/Pandoc/Readers/LaTeX/Types.hs @@ -25,7 +25,7 @@ import Text.Pandoc.Sources import Data.List (groupBy) data TokType = CtrlSeq Text | Spaces | Newline | Symbol | Word | Comment | - Esc1 | Esc2 | Arg Int + Esc1 | Esc2 | Arg Int | DeferredArg Int deriving (Eq, Ord, Show) data Tok = Tok SourcePos TokType Text |
