From eeaa3b048c325859d049f1b7aa7f60553c897aa6 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sun, 12 Nov 2017 14:46:29 -0800 Subject: LaTeX reader: support column specs like `*{2}{r}`. This is equivalent to `rr`. We now expand it like a macro. Closes #4056. --- src/Text/Pandoc/Readers/LaTeX.hs | 16 +++++++++++++--- test/command/4056.md | 15 ++++++++++++++- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index 708980f1d..28c8fd736 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -2406,8 +2406,7 @@ parseAligns = try $ do case safeRead ds of Just w -> return w Nothing -> return 0.0 - let alignSpec = try $ do - spaces + let alignSpec = do pref <- option [] alignPrefix spaces al <- alignChar @@ -2418,10 +2417,21 @@ parseAligns = try $ do spaces suff <- option [] alignSuffix return (al, width, (pref, suff)) + let starAlign = do -- *{2}{r} == rr, we just expand like a macro + symbol '*' + spaces + ds <- trim . toksToString <$> braced + spaces + spec <- braced + case safeRead ds of + Just n -> do + getInput >>= setInput . (mconcat (replicate n spec) ++) + Nothing -> fail $ "Could not parse " ++ ds ++ " as number" bgroup spaces maybeBar - aligns' <- many (alignSpec <* maybeBar) + aligns' <- many $ try $ spaces >> optional starAlign >> + (alignSpec <* maybeBar) spaces egroup spaces diff --git a/test/command/4056.md b/test/command/4056.md index be245a30d..eed4f6d6a 100644 --- a/test/command/4056.md +++ b/test/command/4056.md @@ -8,4 +8,17 @@ [RawBlock (Format "latex") "\\parbox[t]{0.4\\textwidth}{\n\\begin{shaded}\n\\end{shaded}\n}"] ``` - +``` +% pandoc -f latex -t native +\begin{tabular}{l*{2}{r}} +Blah & Foo & Bar \\ +\end{tabular} +^D +[Table [] [AlignLeft,AlignRight,AlignRight] [0.0,0.0,0.0] + [[] + ,[] + ,[]] + [[[Plain [Str "Blah"]] + ,[Plain [Str "Foo"]] + ,[Plain [Str "Bar"]]]]] +``` -- cgit v1.2.3