Skip to content
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

fix: Respect catcode in macro expansion and set ~'s catcode correctly #2949

Merged
merged 2 commits into from Apr 24, 2021

Conversation

edemaine
Copy link
Member

Support single characters having a catcode of 13 (active) or 12 (other), and expand a macro defined for the character only if it's active.

This enables defining ~ as a macro, but avoiding expansion in URLs and \char,
which fixes #2924.

The method of asking the lexer for the current catcode does not match TeX's behavior. In TeX, the lexer returns a catcode along with every token, and the macro expander uses that catcode, instead of the current one (which can differ). I'm leaving this for future work... but could try if desired.

@edemaine edemaine requested a review from ylemkimon April 21, 2021 16:33
Support single characters having a catcode of 13 (active) or 12 (other),
and expand a macro defined for the character only if it's active.
This enables defining `~` as a macro, but avoiding expansion in URLs.

Fix #2924
@codecov-commenter
Copy link

codecov-commenter commented Apr 24, 2021

Codecov Report

Merging #2949 (aa27eb8) into master (24332e0) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2949   +/-   ##
=======================================
  Coverage   93.94%   93.95%           
=======================================
  Files          87       87           
  Lines        6327     6332    +5     
  Branches     1309     1311    +2     
=======================================
+ Hits         5944     5949    +5     
  Misses        353      353           
  Partials       30       30           
Impacted Files Coverage Δ
src/Lexer.js 100.00% <ø> (ø)
src/symbols.js 100.00% <ø> (ø)
src/MacroExpander.js 97.87% <100.00%> (+0.04%) ⬆️
src/Parser.js 96.26% <100.00%> (+0.02%) ⬆️
src/macros.js 97.29% <100.00%> (+<0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 24332e0...aa27eb8. Read the comment docs.

@ylemkimon ylemkimon enabled auto-merge (squash) April 24, 2021 19:30
@ylemkimon ylemkimon merged commit 01ae7f8 into master Apr 24, 2021
@ylemkimon ylemkimon deleted the tilde-catcode branch April 24, 2021 19:33
KaTeX-bot added a commit that referenced this pull request Apr 24, 2021
## [0.13.3](v0.13.2...v0.13.3) (2021-04-24)

### Bug Fixes

* Respect catcode in macro expansion and set ~'s catcode correctly ([#2949](#2949)) ([01ae7f8](01ae7f8)), closes [#2924](#2924)
* **array:** Keep single empty row in AMS environments ([#2947](#2947)) ([24332e0](24332e0)), closes [#2944](#2944)
@KaTeX-bot
Copy link
Member

🎉 This PR is included in version 0.13.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

\char renders `\~ as space
4 participants