Skip to content

Fixed latex highlighter escaping math mode #5306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 28, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions rc/filetype/latex.kak
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ add-highlighter shared/latex/content default-region group
add-highlighter shared/latex/cs region '(?<!\\)(?:\\\\)*\K\\[@\w]' '/\n|(?<![@:\\{}\[\]*])(?![@:\\{}\[\]*])\b|(?<!\\)(?:\\\\)*\K\}\K' group
add-highlighter shared/latex/comment region '(?<!\\)(?:\\\\)*\K%' '\n' fill comment

# Math mode between dollar signs/pairs
add-highlighter shared/latex/dollar-math region -match-capture '(?<!\\)(?:\\\\)*\K(\$\$?)' '(?<!\\)(?:\\\\)*(\$\$?)' fill meta
add-highlighter shared/latex/paren-math region '(?<!\\)(?:\\\\)*\K\\\(' '(?<!\\)(?:\\\\)*\\\)' fill meta
add-highlighter shared/latex/bracket-math region '(?<!\\)(?:\\\\)*\K\\\[' '(?<!\\)(?:\\\\)*\\\]' fill meta

# Document and LaTeX2e control sequence
add-highlighter shared/latex/cs/ regex '(?:\\[a-zA-Z@]+)' 0:keyword
## Options passed to LaTeX2e control sequences, between brackets
Expand Down Expand Up @@ -73,9 +78,6 @@ add-highlighter shared/latex/content/ regex '(?<!\\)(?:\\\\)*\K#+[1-9]' 0:string
## group containing words and numbers (list separated by ; , / or spaces)
add-highlighter shared/latex/content/ regex '(?<!\\)(?:\\\\)*\K\{([\s/;,.\w\d]+)\}' 1:string

# Math mode between dollar signs/pairs
add-highlighter shared/latex/content/ regex '((?<!\\)(?:\\\\)*\K\$(\\\$|[^$])+\$)|((?<!\\)(?:\\\\)*\K\$\$(\\\$|[^$])+\$\$)|((?<!\\)(?:\\\\)*\K\\\[.*?\\\])|(\\\(.*?\\\))' 0:meta

# Indent
# ------

Expand Down