Skip to content

Commit

Permalink
Fix column computations with \multirow and \multicolumn
Browse files Browse the repository at this point in the history
  • Loading branch information
edemaine committed Nov 15, 2023
1 parent d53003d commit 518986c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ instead of version numbers.
By contrast, optional arguments add parentheses:
`\begin{theorem 1}` produces "Theorem (1)", and
`\begin{proof}[sketch]` produces "Proof (sketch)".
* `\begin{tabular}` improvements: skip over `\&`, HTML tags/character codes,
and braced content, which makes it possible to include URLs with `&`s.
* `\begin{tabular}` improvements:
* Skip over `\&`, HTML tags/character codes, and braced content,
which makes it possible to include URLs with `&`s.
* Fix column computations when using both `\multirow` and `\multicolumn`
(in separate cells).

## 2023-11-01

Expand Down
12 changes: 9 additions & 3 deletions lib/formats.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,12 @@ latex2htmlCommandsAlpha = (tex, math) ->
(for row in splitOutside body, /(?:\\\\|\[DOUBLEBACKSLASH\])/ #(?:\s*\\(?:hline|cline\s*{[^{}]*}))?/
#console.log row
continue unless row.trim()
colnum = 0
"<tr>\n" +
(for col, colnum in splitOutside row, /&/
(for col in splitOutside row, /&/
if skip[colnum]
skip[colnum] -= 1
skip[colnum]--
colnum++
continue
align = cols[colnum]
attrs = ''
Expand All @@ -316,9 +318,12 @@ latex2htmlCommandsAlpha = (tex, math) ->
## entry, you must put the \multirow inside the \multicolumn"
## [http://ctan.mirrors.hoobly.com/macros/latex/contrib/multirow/multirow.pdf]
if (match = /\\multicolumn\s*(\d+|{\s*(\d+)\s*})\s*(\w|{([^{}]*)})\s*{((?:[^{}]|{(?:[^{}]|{[^{}]*})*})*)}/.exec col)?
attrs += " colspan=\"#{match[2] ? match[1]}\""
colspan = parseInt match[2] ? match[1], 10
attrs += " colspan=\"#{colspan}\""
align = match[4] ? match[3]
col = match[5]
else
colspan = 1
## In HTML, rowspan means that later rows shouldn't specify <td>s
## for that column, while in LaTeX, they are still present.
if (match = /\\multirow\s*(\d+|{\s*(\d+)\s*})\s*(\*|{([^{}]*)})\s*{((?:[^{}]|{(?:[^{}]|{[^{}]*})*})*)}/.exec col)?
Expand All @@ -338,6 +343,7 @@ latex2htmlCommandsAlpha = (tex, math) ->
" style=\"#{style}text-align: right\""
else
style
colnum += colspan
"<td#{attrs}>#{col}</td>\n"
).join('') +
"</tr>\n"
Expand Down

0 comments on commit 518986c

Please sign in to comment.