Skip to content

Commit

Permalink
Support * repetitions in tabular
Browse files Browse the repository at this point in the history
  • Loading branch information
edemaine committed Dec 14, 2023
1 parent d8c0ab5 commit c77a5ff
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ instead of version numbers.

## 2023-12-14

* `\begin{tabular}` improvements:
* `*` repetitions supported: `*3c` is shorthand for `ccc`,
`*{10}{c}` is shorthand for `cccccccccc`,
`*3{lr}` is shorthand for `lrlrlr`.
* Copy/pasting a URL from a message no longer adds extraneous zero-width spaces
* `\verb|$|` now works both inside and outside math mode

Expand Down
9 changes: 8 additions & 1 deletion lib/formats.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,16 @@ latex2htmlCommandsAlpha = (tex, math) ->
(match, char, verb) => "<code>#{latexEscape verb}</code>"
## Process tabular environments first in order to split cells at &
## (so e.g. \bf is local to the cell)
.replace /\\begin\s*{tabular}\s*{([^{}]*)}([^]*?)\\end\s*{tabular}/g, (m, cols, body) ->
.replace /\\begin\s*{tabular}\s*{((?:[^{}]|{[^{}]*})*)}([^]*?)\\end\s*{tabular}/g, (m, cols, body) ->
cols = cols.replace /\|/g, '' # not yet supported
body = body.replace /\\hline\s*|\\cline\s*{[^{}]*}/g, '' # not yet supported
cols = cols.replace /\*(\d|{\d+})([^{}]|{(?:[^{}]|{[^{}]*})*})/g,
(match, repeat, body) =>
body = body[1...-1] if body[0] == '{'
repeat = parseInt (repeat.replace /[{}]/g, ''), 10
repeat = 0 if repeat < 0
repeat = 1000 if repeat > 1000
body.repeat repeat
skip = (0 for colnum in [0...cols.length])
'<table>' +
(for row in splitOutside body, /(?:\\\\|\[DOUBLEBACKSLASH\])/ #(?:\s*\\(?:hline|cline\s*{[^{}]*}))?/
Expand Down

0 comments on commit c77a5ff

Please sign in to comment.