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

refactor defineEnvironment to also accept HTML and MathML builders #875

Merged
merged 3 commits into from
Sep 20, 2017

Conversation

kevinbarabash
Copy link
Member

fixes #870

@kevinbarabash kevinbarabash force-pushed the refactor_environments branch 3 times, most recently from ed0b28a to 0c1caa5 Compare September 12, 2017 03:46
},
get(envName: string) {
return _environments[envName];
},
Copy link
Member Author

Choose a reason for hiding this comment

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

@marcianx here's what I did for the wrapper around _environments.

* 2. requires all arguments except argType
* It is generated by `defineEnvironment()` below.
*/
type EnvSpec = {|
Copy link
Member Author

Choose a reason for hiding this comment

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

I tightened up some of these types by updating them to use exact object types.

Choose a reason for hiding this comment

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

Meta-comment on GitHub reviews vs. Phabricator: I'm finding it frustrating that comments need to pin to a single line.

@kevinbarabash
Copy link
Member Author

I thought we'd end up with separate files for \*matrix, \*cases, etc., but it turns out they all use the same htmlBuilder and mathmlBuilder so for now they're all in the same file. I still think this is the right direction because it groups all the related code in the same file and it also opens the door to eventually expose defineEnvironment at some point which wasn't possible the way things were structured before.

@@ -581,166 +581,6 @@ groupTypes.genfrac = function(group, options) {
options);
};

groupTypes.array = function(group, options) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Copied to const htmlBuilder = function(group, options) { ... in array.js.

Choose a reason for hiding this comment

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

Thanks for leaving hints like this!

// is part of the source2e.pdf file of LaTeX2e source documentation.
// {darray} is an {array} environment where cells are set in \displaystyle,
// as defined in nccmath.sty.
defineEnvironment({
Copy link
Member Author

Choose a reason for hiding this comment

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

The calls to defineEnvironment look a little different from how they looked in environments.js. All of the existing parameters have been converted props in a single object argument. This was done so it's easier to know which param is which.

return res;
},
htmlBuilder,
mathmlBuilder,
Copy link
Member Author

Choose a reason for hiding this comment

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

These are the two "new" parameters.

@@ -1,326 +1,16 @@
// @flow
Copy link
Member Author

Choose a reason for hiding this comment

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

Everything except for defineEnvironment and the type definitions have been copied over to array.js while the remaining code has gone to defineEnvironment.js.

}
if (mathmlBuilder) {
mathmlGroupTypes[type] = mathmlBuilder;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

The body of defineEnvironment has remained largely the same. The new code adds registers the htmlBuilder and mathmlBuilder args for the given type. This was previously being done in buildHTML.js and buildMathML.js respectively.

Copy link

@rileyjshaw rileyjshaw left a comment

Choose a reason for hiding this comment

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

Awesome! This is a big commit for my first foray into KaTeX, but the refactor looks sound. Since I'm unfamiliar with the library, my approval should be taken with a grain of salt; please test this thoroughly before landing.

I left a few questions, but nothing blocking. The motivation described in #870 makes sense to me.

Thanks for doing this!

postgap?: number,
import {_environments} from "./defineEnvironment";

const environments = {

Choose a reason for hiding this comment

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

Cool! Is the motivation behind this abstraction to limit access to the _environments object? Or do you expect for the bodies of has and get to eventually become more complicated?

If this API was added solely for clarity, I don't think has and get improve readability over hasOwnProperty and [].

Copy link
Member Author

@kevinbarabash kevinbarabash Sep 19, 2017

Choose a reason for hiding this comment

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

The motivation was to limit access. The plan was to do the same for _functions and _symbols. Not sure how necessary it is so I'm going to let this simmer for a while.

@@ -581,166 +581,6 @@ groupTypes.genfrac = function(group, options) {
options);
};

groupTypes.array = function(group, options) {

Choose a reason for hiding this comment

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

Thanks for leaving hints like this!

let row = [];
const body = [row];
const rowGaps = [];
for (;;) {

Choose a reason for hiding this comment

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

I know this is a copypasta, but while(true) would be clearer here.

Copy link
Member Author

Choose a reason for hiding this comment

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

It was originally while(true), but a previous commit changed it after removing a top level eslint-disable. I can add it back in with a eslint-disable-line.

* 2. requires all arguments except argType
* It is generated by `defineEnvironment()` below.
*/
type EnvSpec = {|

Choose a reason for hiding this comment

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

Meta-comment on GitHub reviews vs. Phabricator: I'm finding it frustrating that comments need to pin to a single line.

"vmatrix",
"Vmatrix",
],
props: {},

Choose a reason for hiding this comment

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

Should props be optional?

Copy link
Member Author

@kevinbarabash kevinbarabash Sep 19, 2017

Choose a reason for hiding this comment

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

That's a good question. defineFunction requires numArgs on props even if it's 0. I'm not sure how useful that is, but I'd rather be consistent so I'll make it mandatory here too.

* - numOptionalArgs: (default 0) Just like for a function
*/
type EnvProps = {
numArgs?: number,

Choose a reason for hiding this comment

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

I only see numArgs used in this review, but I imagine the rest are used elsewhere / externally?

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 catch. We may want to add those at some point in the future, but if they're not being used no reason to include them now.

@kevinbarabash kevinbarabash merged commit ca6ea4c into master Sep 20, 2017
@kevinbarabash kevinbarabash deleted the refactor_environments branch November 27, 2017 01:03
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.

refactor defineEnvironment to look more like the new defineFunction
2 participants