-
Notifications
You must be signed in to change notification settings - Fork 207
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
Update \operatorname to work more like in LaTeX. (mathjax/MathJax#2830) #788
Conversation
PS, this PR is to the |
No worries, I think it is easier to review like that. |
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.
Looks pretty good, but I have one major issue with the PR:
The extension of the EnvProp
type to include a non-primitive type. Can't we pass the multiLetterIdentfiers
as a string
from which the RegExp
is created? In addition, can we spell out the regular expression. I find the i
modifier very dodgy as it is implementation dependent what it does on non-ASCII characters representing letters. As an example
'a𝐚A𝐀'.match(/[a𝐚]+/)
vs
'a𝐚A𝐀'.match(/[a𝐚]+/i)
The latter leads to very odd behaviour.
c = parser.string.substr(parser.i - 1).match(/^[a-z]+/i)[0]; | ||
const env = parser.stack.env; | ||
if (env.multiLetterIdentifiers && env.font !== '') { | ||
c = parser.string.substr(parser.i - 1).match(env.multiLetterIdentifiers as RegExp)[0]; |
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.
multiLetterIdentifiers
could be a non-empty string.
@@ -28,7 +28,7 @@ import TexError from './TexError.js'; | |||
import StackItemFactory from './StackItemFactory.js'; | |||
|
|||
// Union types for abbreviation. | |||
export type EnvProp = string | number | boolean; | |||
export type EnvProp = string | number | boolean | RegExp; |
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.
I don't like that. I'd like to keep that to primitive types.
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.
Other than aesthetic reasons, is there a practical advantage to that? I'm not sure why the environment properties can't be any type of data that is needed.
We can, but that means the RegExp has to be re-compiled every time it is used, whereas with a constant RegExp, it is only compiled once, so that is more efficient. That was the main reason to do it this way.
I'm not sure what that means.
But the examples you give aren't the RegExp being used. That is just |
As per f2f I am happy with extending the type by RegExp.
For the record: That just means I prefer |
Thank for the clarification. I'm adjusting the RegExp. |
This PR improves the implementation of
\operatorname
(and\DeclareMathOperator
) to work more like in true LaTeX. In the past, the macro replaced-
and*
by\text{-}
and\text{*}
in order to handle what LaTeX dues using\catcode
. Here, we take advantage of features added toParseMethods.variable
to get\mathrm{}
to produce multi-charactermi
elements to get\operatorname
to do the same. ThemultiLetterIdentifiers
environment value has been replaced by a regular expression for the characters to use (andEnvProp
is extended to allow that). Then we make a new map that matches-
and*
and checks whether we are in an\operatorname
, and if so, parses the characters like variables, otherwise parses them as usual.The
\operatorname
macro is rewritten to parse the arguments itself, rather than using a replacement macro internally, so that we can set themultiLetterIdentifiers
regular expression and theoperatorLetters
environment property. This also means we can handle the following\limits
directly rather than needing the extra\SkipLimits
macro to do that.Finally,
\DeclareMathOperator
is set up to define the macro in terms of\operatorname
rather than\mathop
.Resolves issue mathjax/MathJax#2830