Skip to content

Commit

Permalink
TeX reader: fix two bugs.
Browse files Browse the repository at this point in the history
- Don't crash on array with `\hline` before blank cell.
- Skip whitespace in array column specifier.

See #244.
  • Loading branch information
jgm committed Nov 13, 2024
1 parent 95b3f28 commit 4666e68
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/Text/TeXMath/Readers/TeX.hs
Original file line number Diff line number Diff line change
Expand Up @@ -443,19 +443,20 @@ endLineAMS = lexeme $ try $ do

arrayLine :: TP ArrayLine
arrayLine =
sepBy1 (unGrouped <$>
manyExp (try (ignorable' *> notFollowedBy (('\n' <$ ctrlseq "end") <|> endLine)) *>
expr <*
ignorable')) (symbol "&")
where ignorable' = ignorable >>
optional (try (ctrlseq "hline" >> ignorable'))
sepBy1
(ignorable' *>
(unGrouped <$>
manyExp (try (notFollowedBy (('\n' <$ ctrlseq "end") <|> endLine)) *>
expr <* ignorable'))) (symbol "&")
where ignorable' = ignorable >> optional (try (ctrlseq "hline" >> ignorable'))
-- we don't represent the line, but it shouldn't crash parsing

arrayAlignments :: TP [Alignment]
arrayAlignments = mconcat <$>
braces (many (
((:[]) . letterToAlignment <$> letter)
<|> ([] <$ char '|')
<|> ([] <$ oneOf " \t")
<|> ([] <$ ((char '@' <|> char '!') <* inbraces))
<|> (do char '*'
num <- T.pack <$> braces (many1 digit)
Expand Down
13 changes: 13 additions & 0 deletions test/regression/244.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<<< tex
\begin{array}{l cr}
1 & 2 & 3 \\\hline
& 5 & 6 \\
\end{array}
>>> native
[ EArray
[ AlignLeft , AlignCenter , AlignRight ]
[ [ [ ENumber "1" ] , [ ENumber "2" ] , [ ENumber "3" ] ]
, [ [] , [ ENumber "5" ] , [ ENumber "6" ] ]
, [ [] ]
]
]

0 comments on commit 4666e68

Please sign in to comment.