git.iko.soy/typeable/pandoc
on master help sign in
LaTeX reader: support column specs like `*{2}{r}`.

This is equivalent to `rr`. We now expand it like a macro. Closes #4056.

commiteeaa3b048c325859d049f1b7aa7f60553c897aa6 authorJohn MacFarlane <jgm@berkeley.edu> dateSun 12 Nov 2017, 14:46 (9 years ago) parent7ba0ae8
2 files changed+27−4
src/Text/Pandoc/Readers/LaTeX.hs+13−3 test/command/4056.md+14−1
src/Text/Pandoc/Readers/LaTeX.hs+13−3
@@ -2406,8 +2406,7 @@ parseAligns = try $ do
24062406 case safeRead ds of
24072407 Just w -> return w
24082408 Nothing -> return 0.0
2409− let alignSpec = try $ do
2410− spaces
2409+ let alignSpec = do
24112410 pref <- option [] alignPrefix
24122411 spaces
24132412 al <- alignChar
@@ -2418,10 +2417,21 @@ parseAligns = try $ do
24182417 spaces
24192418 suff <- option [] alignSuffix
24202419 return (al, width, (pref, suff))
2420+ let starAlign = do -- *{2}{r} == rr, we just expand like a macro
2421+ symbol '*'
2422+ spaces
2423+ ds <- trim . toksToString <$> braced
2424+ spaces
2425+ spec <- braced
2426+ case safeRead ds of
2427+ Just n -> do
2428+ getInput >>= setInput . (mconcat (replicate n spec) ++)
2429+ Nothing -> fail $ "Could not parse " ++ ds ++ " as number"
24212430 bgroup
24222431 spaces
24232432 maybeBar
2424− aligns' <- many (alignSpec <* maybeBar)
2433+ aligns' <- many $ try $ spaces >> optional starAlign >>
2434+ (alignSpec <* maybeBar)
24252435 spaces
24262436 egroup
24272437 spaces
test/command/4056.md+14−1
@@ -8,4 +8,17 @@
88[RawBlock (Format "latex") "\\parbox[t]{0.4\\textwidth}{\n\\begin{shaded}\n\\end{shaded}\n}"]
99```
1010
11−
11+```
12+% pandoc -f latex -t native
13+\begin{tabular}{l*{2}{r}}
14+Blah & Foo & Bar \\
15+\end{tabular}
16+^D
17+[Table [] [AlignLeft,AlignRight,AlignRight] [0.0,0.0,0.0]
18+ [[]
19+ ,[]
20+ ,[]]
21+ [[[Plain [Str "Blah"]]
22+ ,[Plain [Str "Foo"]]
23+ ,[Plain [Str "Bar"]]]]]
24+```