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

Single-character macros like active characters #973

Merged
merged 3 commits into from
Nov 24, 2017

Conversation

edemaine
Copy link
Member

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.

@ronkok
Copy link
Collaborator

ronkok commented Nov 19, 2017

Cool. This will be helpful for double-struck Unicode characters like ℂ or ℕ.

@ronkok ronkok mentioned this pull request Nov 19, 2017
@edemaine
Copy link
Member Author

@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).
Copy link
Member

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).

Copy link
Member Author

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", {
"’": "'",
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice test.

Copy link
Member

@kevinbarabash kevinbarabash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kevinbarabash
Copy link
Member

kevinbarabash commented Nov 24, 2017

@edemaine thanks for making this change. It's really going to help with the unicode effort.

@kevinbarabash kevinbarabash merged commit ecad4de into KaTeX:master Nov 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants