Skip to content

Improve rule coding, including for \sqrt.#776

Merged
k4b7 merged 3 commits intoKaTeX:masterfrom
kohler:rule-css
Aug 6, 2017
Merged

Improve rule coding, including for \sqrt.#776
k4b7 merged 3 commits intoKaTeX:masterfrom
kohler:rule-css

Conversation

@kohler
Copy link
Copy Markdown
Collaborator

@kohler kohler commented Jul 31, 2017

  • Rule widths (overline, underline, fraction, sqrt) actually scale
    with the current font size in AMS-TeX. Implement that. (Sqrt is
    a special case: the rule width depends on the font size of the
    surd
    .)
  • Change the CSS coding for rules. The old, complex coding prevented
    variable-width lines and may have contributed to issues like poor spacing in fraction inside square root (depends on rendering environment) #696.
    Its purpose, according to 0a3a227,
    was IE8 support; but KaTeX no longer supports IE8.

@kohler
Copy link
Copy Markdown
Collaborator Author

kohler commented Jul 31, 2017

Example difference, using \frac towers (an example from @ronkok). Before:
screen shot 2017-07-30 at 11 41 21 pm

After:
screen shot 2017-07-30 at 11 40 47 pm

Note that the rules are less unruly.

@k4b7
Copy link
Copy Markdown
Member

k4b7 commented Jul 31, 2017

@kohler I'll review this evening. The screenshots look good.

@k4b7 k4b7 self-requested a review July 31, 2017 16:01
@ronkok ronkok mentioned this pull request Aug 3, 2017
@k4b7
Copy link
Copy Markdown
Member

k4b7 commented Aug 3, 2017

I'll review this evening

I was overly optimistic. I'll try to get to it this weekend.

@k4b7
Copy link
Copy Markdown
Member

k4b7 commented Aug 5, 2017

The \sqrt rule looks a lot better. I've found the smaller font sizes to be more troublesome. Here are some renderings using 12px sized font.

Safari
screen shot 2017-08-04 at 10 25 13 pm

Safari @ 400%
screen shot 2017-08-04 at 10 30 48 pm

Chrome
screen shot 2017-08-04 at 10 25 32 pm

Chrome @ 400%
screen shot 2017-08-04 at 10 30 57 pm

I tried out some other font sizes. 18px was the worst.

Safari @ 400%
screen shot 2017-08-04 at 10 34 17 pm

Chrome @ 400%
screen shot 2017-08-04 at 10 34 34 pm

My guess is that the \sqrt rule is a bit to high on Chrome for 18px and is getting clipped. This also happens at 11px and might happen for other font sizes. I zoomed to 100% just in case the zoom was causing an issue and the rule was still missing. This should be fixed before merging.

kohler added 2 commits August 5, 2017 08:41
* Rule widths (overline, underline, fraction, sqrt) actually scale
  with the current font size in AMS-TeX. Implement that. (Sqrt is
  a special case: the rule width depends on the font size *of the
  surd*.)
* Change the CSS coding for rules. The old, complex coding prevented
  variable-width lines and may have contributed to issues like KaTeX#696.
  Its purpose, according to 0a3a227,
  was IE8 support; but KaTeX no longer supports IE8.
@kohler
Copy link
Copy Markdown
Collaborator Author

kohler commented Aug 5, 2017

Hi @kevinbarabash, I rebased on top of the current master & pushed. I cannot replicate a missing \sqrt rule on Chrome, with either 11px or 18px, at any mag. Here's the diff I made to main.css. Version 59.0.3071.115 (Official Build) (64-bit) on Mac. Can you help me replicate? There's no clipping in the CSS coding, so your proposed explanation doesn't make sense to me.

--- a/static/main.css
+++ b/static/main.css
@@ -1,7 +1,7 @@
 body {
     margin: 0px;
     padding: 0px;
-    font-size: 72px;
+    font-size: 11px;
 }
 
 #input {

@k4b7
Copy link
Copy Markdown
Member

k4b7 commented Aug 5, 2017

I'm running a dev version of Chrome. It said it was ready to upgrade so I upgraded and the problem went away. This also resulted in better positioning at 12px. The sort-line is no longer floating a little bit above the square root symbol.

Copy link
Copy Markdown
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.

Looks good, just a few questions in the comments. I'm surprised that the position of the some of the subscripts changed in the screenshots. Any idea of why that happened?

options);
const delimChar = delimiter.customSizedDelim("\\surd", minDelimiterHeight,
false, options, group.mode);
const delim = makeSpan(["sqrt-sign"], [delimChar], options);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thanks for breaking this up

const ruleWidth = line.height;
// Calculate the minimum size for the \surd delimiter
const metrics = options.fontMetrics();
const theta = metrics.defaultRuleThickness;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is theta the official name for this metric in the TeXBook?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes

src/buildHTML.js Outdated
let ruleWidth;
if (group.value.hasBarLine) {
rule = makeLineSpan("frac-line", options);
ruleWidth = ruleSpacing = rule.height;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you change this to:

ruleWidth = rule.height;
ruleSpacing = ruleWidth;

I misread this and thought that ruleSpacing wasn't being defined in this block.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

done

const makeLineSpan = function(className, options) {
const baseOptions = options.havingBaseStyle();
const line = makeSpan(
[className].concat(baseOptions.sizingClasses(options)),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are the sizing classes not necessary b/c we're manually figuring setting the borderBottomWidth?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes. The sizing classes were necessary because previously we wanted all rules to have the same thickness, and that thickness was specified in katex.less in base-sized em units. Now that we're specifying the thickness in local em units, no sizing classes.

@kohler
Copy link
Copy Markdown
Collaborator Author

kohler commented Aug 6, 2017

When a nucleus has both sub & sub, the defaultRuleThickness is part of the calculation involved in separating the subscript from the superscript. The screenshotter subscript positions changed in scriptscript mode because now defaultRuleThickness is relatively larger for script and scriptscript fonts—e.g., the script defaultRuleThickness is 0.049em, not 0.04em.

The previous KaTeX implementation differed. It used 0.04em as the thickness for purposes of separating sup+sub, but it should have used 0.04em base-size units for consistency with the TeXbook (since previously all rules were 0.04em base-size units thick). Instead it used 0.04em script-size units (in scriptscript mode).

@k4b7
Copy link
Copy Markdown
Member

k4b7 commented Aug 6, 2017

@kohler thanks for the PR. The updated horizontal rules look great.

@k4b7 k4b7 merged commit dcdca73 into KaTeX:master Aug 6, 2017
@kohler kohler deleted the rule-css branch August 8, 2017 11:14
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.

2 participants