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

Improve MathML for environments #1910

Merged
merged 14 commits into from
Apr 4, 2019
Merged

Improve MathML for environments #1910

merged 14 commits into from
Apr 4, 2019

Conversation

ronkok
Copy link
Collaborator

@ronkok ronkok commented Mar 27, 2019

This PR improves the MathML of array environments. Specifically, it improves

  • row spacing
  • column spacing
  • column alignment
  • vertical lines in {array} environments
  • horizontal lines from \hline and \hdashline.

To aid review, I have changed the page at webmathcomparison.net so that it runs a version of KaTeX that includes this PR.

@codecov-io
Copy link

codecov-io commented Mar 27, 2019

Codecov Report

Merging #1910 into master will increase coverage by 0.05%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1910      +/-   ##
==========================================
+ Coverage   94.77%   94.82%   +0.05%     
==========================================
  Files          79       79              
  Lines        4723     4776      +53     
  Branches      822      842      +20     
==========================================
+ Hits         4476     4529      +53     
  Misses        223      223              
  Partials       24       24
Flag Coverage Δ
#screenshotter 89.14% <100%> (+0.12%) ⬆️
#test 85.9% <3.7%> (-0.93%) ⬇️
Impacted Files Coverage Δ
src/parseNode.js 84.21% <ø> (ø) ⬆️
src/environments/array.js 98.61% <100%> (+0.31%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ab7b782...42f4d8b. Read the comment docs.


// {aligned} and {alignedat} get 0 column spacing.
// The others get 1em.
table.setAttribute("columnspacing", group.isAlign ? "0em" : "1em");
Copy link
Member

Choose a reason for hiding this comment

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

Is postgap somehow related to this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes. The HTML part of the code creates a colsep span whose width is either 0, or 1em (1qquad), or the default arraycolsep. The align environment gets a pregap defined as 1em, but I cannot see how this makes any difference. The end result of all the colsep, arraycolsep, logic works out in effect to just two choices and I chose to simplify it into this one line of code.

I have plans to add more environments. I will revisit this line of code when I do that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I figured out what pregap does. The latest commit improves the column spacing for the aligned environment.

@@ -25,6 +25,10 @@ export type AlignSpec = { type: "separator", separator: string } | {
postgap?: number,
};

// Constants to indicate column separation
const ALIGN = 1;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const ALIGN = 1;

@@ -25,6 +25,10 @@ export type AlignSpec = { type: "separator", separator: string } | {
postgap?: number,
};

// Constants to indicate column separation
const ALIGN = 1;
const ALIGNAT = 2;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const ALIGNAT = 2;
export type ColSeparationType = "align" | "alignat";

hskipBeforeAndAfter?: boolean,
addJot?: boolean,
cols?: AlignSpec[],
arraystretch?: number,
colSeparationType?: number,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
colSeparationType?: number,
colSeparationType?: ColSeparationType,

Copy link
Member

Choose a reason for hiding this comment

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

Is this needed? It seems there is no parseArray calls with colSeparationType.

src/environments/array.js Show resolved Hide resolved
let columnLines = "";
let prevTypeWasAlign = false;
let iStart = 0;
let iEnd = group.cols.length;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
let iEnd = group.cols.length;
let iEnd = cols.length;

spacing += i % 2 ? "0em " : "1em ";
}
table.setAttribute("columnspacing", spacing.trim());
} else if (group.colSeparationType === ALIGNAT) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
} else if (group.colSeparationType === ALIGNAT) {
} else if (group.colSeparationType === "alignat") {

src/environments/array.js Show resolved Hide resolved
@@ -448,6 +566,7 @@ const alignedHandler = function(context, args) {
postgap: 0,
};
}
res.colSeparationType = isAligned ? ALIGN : ALIGNAT;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
res.colSeparationType = isAligned ? ALIGN : ALIGNAT;
res.colSeparationType = isAligned ? "align" : "alignat";

src/parseNode.js Outdated
@@ -28,6 +28,7 @@ type ParseNodeTypes = {
type: "array",
mode: Mode,
loc?: ?SourceLocation,
colSeparationType?: number,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
colSeparationType?: number,
colSeparationType?: ColSeparationType,

@@ -28,6 +28,7 @@ type ParseNodeTypes = {
type: "array",
Copy link
Member

Choose a reason for hiding this comment

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

I think it's better to make ColSeparationType a type and import it here like AlignSpec.

@ronkok
Copy link
Collaborator Author

ronkok commented Apr 4, 2019

The most recent commit picks up the review comments.

@ylemkimon ylemkimon merged commit ec777b8 into KaTeX:master Apr 4, 2019
@ylemkimon
Copy link
Member

@ronkok Thank you for your hard work! 😄

@ronkok
Copy link
Collaborator Author

ronkok commented Apr 4, 2019

@ylemkimon Thank you for the valuable reviews!

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