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

Associate font metrics with Options, not Style. #743

Merged
merged 3 commits into from
Jun 30, 2017

Conversation

kohler
Copy link
Collaborator

@kohler kohler commented Jun 28, 2017

Font metrics are associated with a given font and size combination.
Before KaTeX understood sizing commands, sizes were associated with
a Style. That's not true now. So instead of style.metrics, use
options.fontMetrics(), since options knows the font and the
size.

This is a cleanup commit with no direct effect; it will make
other changes possible later.

Font metrics are associated with a given font and size combination.
Before KaTeX understood sizing commands, sizes were associated with
a Style. That's not true now. So instead of `style.metrics`, use
`options.fontMetrics()`, since `options` knows the font and the
size.

This is a cleanup commit with no visible effects on most tests (there
could be some small effect on size + style combinations). It will
make other changes possible later.
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.

Looks good. A few minor nits/questions.

// they correspond to the font parameters of the extension fonts (family 3).
// See the TeXbook, page 441. In AMSTeX, the extension fonts scale; to
// match cmex7, we'd use cmex7.tfm values for script and scriptscript
// values.
Copy link
Member

Choose a reason for hiding this comment

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

I'm surprised that the third value in each of the arrays isn't determined by cmex5 similar to how cmsy5 is used for the values above.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There is no cmex5. AMSTeX supplies cmex7, cmex8, cmex9 to TeX's cmex10.

doubleRuleSep: doubleRuleSep,
// The space between adjacent `|` columns in an array definition. From
// `\showthe\doublerulesep` in LaTeX. Equals 2.0 / ptPerEm.
doubleRuleSep: [0.2, 0.2, 0.2],
};
Copy link
Member

Choose a reason for hiding this comment

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

Now that this object also includes xis as well as sigmas maybe we should change the name of it. Maybe fontMetrics.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OK

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Called it sigmasAndXis

if (sigmas.hasOwnProperty(key)) {
metrics[key] = sigmas[key][sizeIndex];
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Object.keys(sigmas).forEach(key => metrics[key] = sigmas[key][sizeIndex])

is another possibility. I'm okay either way.

@@ -1,6 +1,3 @@
/* eslint no-unused-vars:0 */

const Style = require("./Style");
Copy link
Member

Choose a reason for hiding this comment

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

Nice. I ended up removing this dep in another PR. I missed the comment at the top.

*/
Options.prototype.fontMetrics = function() {
if (!this._fontMetrics) {
this._fontMetrics = fontMetrics.getFontMetrics(this.size);
Copy link
Member

Choose a reason for hiding this comment

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

When I first looked at this I thought this might create a lot of objects but then I remembered that getFontMetrics also stores a copy of each unique object it returns which means there's a small number of objects being created.

src/Options.js Outdated
@@ -24,6 +26,7 @@ const sizeStyleMap = [
];

const sizeMultipliers = [
// fontMetrics.js:getFontMetrics also uses size indexes.
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure what this comment means.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It means that if you change size indexes you should change getFontMetrics

@kohler
Copy link
Collaborator Author

kohler commented Jun 30, 2017

Hi! Responded to the review; any other comments?

@edemaine
Copy link
Member

FYI, merging your #745 ended up making a small conflict here.

@kohler
Copy link
Collaborator Author

kohler commented Jun 30, 2017

Fixed the conflict (assuming a squash-merge later, didn't bother to rebase).

@kevinbarabash
Copy link
Member

@kohler looks good. Thanks cleaning this up.

@kevinbarabash kevinbarabash merged commit f23bf3f into KaTeX:master Jun 30, 2017
@kohler kohler deleted the metrics branch June 30, 2017 19:10
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