mathjax / MathJax-node

MathJax for Node
Apache License 2.0
615 stars 97 forks source link

[CommonHTML] displayIndent not working #223

Closed pkra closed 8 years ago

pkra commented 8 years ago

I couldn't get displayIndent to work. Hopefully with a correct configuration this time:

var tape = require('tape');
var mjAPI = require("./lib/mj-single.js");
var jsdom = require('jsdom').jsdom;

tape('displayAlign:left in HTML output', function(t) {
  t.plan(1);
  mjAPI.config({MathJax: {displayIndent: '10em'}});
  mjAPI.start();
  var tex = 'x';
  expected = -1;

  mjAPI.typeset({
    math: tex,
    format: "TeX",
    html: true
  }, function(data) {
    var document = jsdom(data.html);
    var window = document.defaultView;
    var element = window.document.getElementsByClassName('MJXc-display')[0];
    var result = element.getAttribute('style').indexOf('margin-left');
console.log(result);
    t.ok(result > expected, 'style includes a margin');
  });
});

Perhaps another jsdom bug (like #220)?

pkra commented 8 years ago

FWIW, this setting always seemed like something the page author should be able handle via regular CSS (though I can think of a number of reasons why it's necessary with MathJax 2.x)

dpvc commented 8 years ago

Perhaps another jsdom bug?

No, the test doesn't look at the right thing. The displayIndent does not set the margin-left for the display element; I'm afraid things are more complicated than that. The displayIndent basically acts as the default setting for the MathML indentshift setting, and its interaction with things like tags, the various shift values, and other content are not simple, and where in the DOM the value shows up differs for equations with labels and those without.

this setting always seemed like something the page author should be able handle via regular CSS

I don't think that would be easy to accomplish, as the required CSS would differ for the different output renderers, and for the different equations (e.g., labeled versus non-labeled). That would make for some complicated CSS rules that every author would have to understand and get right. From the kinds of questions we've seen in the past, I don't have high hopes for that.

Also, since MathJax needs to know this value to get the layout correct, I don't think that having the author specify it in CSS is going to be the right approach.

dpvc commented 8 years ago

PS, you are right that for some equations, margin-left is used, but not all.

dpvc commented 8 years ago

You are right that displayIndent isn't working in the case where the equation has no label. That is because mj-single neglected to set the outerEm value, and so a computation for the margin was returning NaN. The issue223 branch resolves that.

pkra commented 8 years ago

I'm afraid things are more complicated than that. [...]

Thanks for background!

I don't think that having the author specify it in CSS is going to be the right approach.

Copy that.

dpvc commented 8 years ago

==> Merged.