-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Single-character macros like active characters #973
Conversation
Cool. This will be helpful for double-struck Unicode characters like ℂ or ℕ. |
@ronkok Great! More motivation for this change. |
README.md
Outdated
@@ -48,7 +48,7 @@ You can provide an object of options as the last argument to `katex.render` and | |||
- `displayMode`: `boolean`. If `true` the math will be rendered in display mode, which will put the math in display style (so `\int` and `\sum` are large, for example), and will center the math on the page on its own line. If `false` the math will be rendered in inline mode. (default: `false`) | |||
- `throwOnError`: `boolean`. If `true`, KaTeX will throw a `ParseError` when it encounters an unsupported command. If `false`, KaTeX will render the unsupported command as text in the color given by `errorColor`. (default: `true`) | |||
- `errorColor`: `string`. A color string given in the format `"#XXX"` or `"#XXXXXX"`. This option determines the color which unsupported commands are rendered in. (default: `#cc0000`) | |||
- `macros`: `object`. A collection of custom macros. Each macro is a property with a name like `\name` (written `"\\name"` in JavaScript) which maps to a string that describes the expansion of the macro. | |||
- `macros`: `object`. A collection of custom macros. Each macro is a property with a name like `\name` (written `"\\name"` in JavaScript) which maps to a string that describes the expansion of the macro. The behavior of single characters can also be redefined by a macro (similar to TeX active characters). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests allow single characters for the names, but reading this it sounds like only things like \name
are accepted. Maybe change the last sentence to read like:
Single characters keys can also be included in which case the character will be redefined as the given macro (similar to TeX active characters).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea! Revised.
it("should allow aliasing characters", function() { | ||
compareParseTree("x’=c", "x'=c", { | ||
"’": "'", | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@edemaine thanks for making this change. It's really going to help with the unicode effort. |
This tiny PR adds support for redefining single characters by arbitrary macros, while also simplifying the code slightly. I don't see a reason not to allow this, and it would be immediately useful for resolving #967, as well as e.g. users adding support for Unicode characters that KaTeX doesn't already support, or which KaTeX already supports but the user wants to override in a different way. Overall seems like a win.