Skip to content

Commit

Permalink
\verb support outside math mode
Browse files Browse the repository at this point in the history
  • Loading branch information
edemaine committed Dec 14, 2023
1 parent fd7c3d8 commit d8c0ab5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ instead of version numbers.
## 2023-12-14

* Copy/pasting a URL from a message no longer adds extraneous zero-width spaces
* `\verb|$|` now works inside math mode
* `\verb|$|` now works both inside and outside math mode

## 2023-12-05

Expand Down
12 changes: 8 additions & 4 deletions lib/formats.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,16 @@ boldWeight = 700
## (e.g. % should not be a comment when in a URL or verbatim).
latex2htmlVerb = (tex) ->
tex.replace /\\begin\s*{verbatim}([^]*?)\\end\s*{verbatim}/g,
(match, verb) -> "<pre>#{latexEscape verb}</pre>"
.replace /\\url\s*{([^{}]*)}/g, (match, url) ->
(match, verb) => "<pre>#{latexEscape verb}</pre>"
.replace /\\url\s*{([^{}]*)}/g, (match, url) =>
url = latexURL url
"""<a href="#{url}">#{latexEscape url}</a>"""
.replace /\\href\s*{([^{}]*)}\s*{((?:[^{}]|{[^{}]*})*)}/g,
(match, url, text) ->
(match, url, text) =>
url = latexURL url
"""<a href="#{url}">#{text}</a>"""
.replace /\\begin\s*{CJK(\*?)}\s*{UTF8}\s*{[^{}]*}(.*?)\\end{CJK\*?}/g,
(match, star, text) ->
(match, star, text) =>
text = text.replace /\s+/g, '' if star
text

Expand Down Expand Up @@ -293,6 +293,10 @@ splitOutside = (text, re) ->
## in Markdown too.
latex2htmlCommandsAlpha = (tex, math) ->
tex = tex
## \verb is here instead of latex2htmlVerb so that it's processed after
## math blocks are extracted (as KaTeX has its own \verb support)
.replace /\\verb(.)(.*?)\1/g,
(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) ->
Expand Down

0 comments on commit d8c0ab5

Please sign in to comment.