Skip to content

Comments

Single-character macros like active characters#973

Merged
k4b7 merged 3 commits intoKaTeX:masterfrom
edemaine:charmacro
Nov 24, 2017
Merged

Single-character macros like active characters#973
k4b7 merged 3 commits intoKaTeX:masterfrom
edemaine:charmacro

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
- `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

@k4b7 k4b7 left a comment

Choose a reason for hiding this comment

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

LGTM

@k4b7
Copy link
Member

k4b7 commented Nov 24, 2017

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

@k4b7 k4b7 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