blob: 31bdff2fd7c2c4e463adfba2c3768d678c5c7424 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Embellished operators</title>
<link rel="stylesheet" type="text/css" href="/fonts/ahem.css" />
<link rel="help" href="https://mathml-refresh.github.io/mathml-core/#embellished-operators">
<link rel="help" href="https://mathml-refresh.github.io/mathml-core/#definition-of-space-like-elements">
<link rel="help" href="https://mathml-refresh.github.io/mathml-core/#layout-of-mrow">
<meta name="assert" content="Verify definition of embellished operators">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/mathml/support/feature-detection.js"></script>
<script src="/mathml/support/box-navigation.js"></script>
<style>
/* Default spacing of operator 'X' is 0.2777777777777778em so quite different
from the measured/specified 0em and 1em. */
math, math * {
font: 25px/1 Ahem;
}
mn {
color: black;
}
.testedElement mo {
color: yellow !important;
}
.testedElement, .testedElement * {
color: blue !important;
background: blue !important;
}
.oof1 {
position: absolute;
}
.oof2 {
position: fixed;
}
.nobox {
display: none;
}
</style>
<script>
function spaceBeforeElement(id) {
var element = document.getElementById(id);
var mnBefore = previousInFlowSibling(element);
return element.getBoundingClientRect().left - mnBefore.getBoundingClientRect().right;
}
function spaceBeforeCoreOperator(id) {
var element = document.getElementById(id);
var coreMo = element.getElementsByTagName("mo")[0];
return coreMo.getBoundingClientRect().left - element.getBoundingClientRect().left;
}
setup({ explicit_done: true });
window.addEventListener("load", runTests);
function runTests() {
var epsilon = 1;
var emToPx = 25;
["mrow", "mstyle", "mphantom", "mpadded"].forEach(tag => {
test(function() {
assert_true(MathMLFeatureDetection.has_operator_spacing());
assert_approx_equals(spaceBeforeElement(`${tag}-op-1`), 2 * emToPx, epsilon);
assert_approx_equals(spaceBeforeCoreOperator(`${tag}-op-1`), 0, epsilon);
}, `${tag} (embellished operator)`);
test(function() {
assert_true(MathMLFeatureDetection.has_operator_spacing());
assert_approx_equals(spaceBeforeElement(`${tag}-op-2`), 2 * emToPx, epsilon);
assert_approx_equals(spaceBeforeCoreOperator(`${tag}-op-2`), 0, epsilon);
}, `${tag} (embellished operator, from in-flow children)`);
test(function() {
assert_true(MathMLFeatureDetection.has_operator_spacing());
assert_approx_equals(spaceBeforeElement(`${tag}-nonop-1`), 0, epsilon);
assert_approx_equals(spaceBeforeCoreOperator(`${tag}-nonop-1`), 2 * emToPx, epsilon);
}, `${tag} (not embellished operator)`);
test(function() {
assert_true(MathMLFeatureDetection.has_operator_spacing());
assert_approx_equals(spaceBeforeElement(`${tag}-nonop-2`), 0, epsilon);
assert_approx_equals(spaceBeforeCoreOperator(`${tag}-nonop-2`), 2 * emToPx, epsilon);
}, `${tag} (not embellished operator, from in-flow children)`);
});
done();
}
</script>
</head>
<body>
<div id="log"></div>
<!-- mrow is an embellished operator if its in-flow children consist
of one embellished operator and zero or more space-like elements. -->
<p>
<math>
<mn>X</mn>
<mrow id="mrow-op-1" class="testedElement">
<mo lspace="2em" rspace="0em">X</mo>
<mtext class="space-like">X</mtext>
</mrow>
<mn>X</mn>
</math>
</p>
<p>
<math>
<mn>X</mn>
<mrow id="mrow-nonop-1" class="testedElement">
<mo lspace="2em" rspace="0em">X</mo>
<mn>X</mn> <!-- "mn" is not space-like -->
</mrow>
<mn>X</mn>
</math>
</p>
<p>
<math>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mn>X</mn>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mrow id="mrow-op-2" class="testedElement">
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mo lspace="2em" rspace="0em">X</mo>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mtext class="space-like">X</mtext>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
</mrow>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mn>X</mn>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
</math>
</p>
<p>
<math>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mn>X</mn>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mrow id="mrow-nonop-2" class="testedElement">
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mo lspace="2em" rspace="0em">X</mo>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mn>X</mn> <!-- "mn" is not space-like -->
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
</mrow>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mn>X</mn>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
</math>
</p>
<!-- mstyle is an embellished operator if its in-flow children consist
of one embellished operator and zero or more space-like elements. -->
<p>
<math>
<mn>X</mn>
<mstyle id="mstyle-op-1" class="testedElement">
<mo lspace="2em" rspace="0em">X</mo>
</mstyle>
<mn>X</mn>
</math>
</p>
<p>
<math>
<mn>X</mn>
<mstyle id="mstyle-nonop-1" class="testedElement">
<mo lspace="2em" rspace="0em">X</mo>
<mn>X</mn> <!-- "mn" is not space-like -->
</mstyle>
<mn>X</mn>
</math>
</p>
<p>
<math>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mn>X</mn>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mstyle id="mstyle-op-2" class="testedElement">
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mo lspace="2em" rspace="0em">X</mo>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
</mstyle>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mn>X</mn>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
</math>
</p>
<p>
<math>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mn>X</mn>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mstyle id="mstyle-nonop-2" class="testedElement">
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mo lspace="2em" rspace="0em">X</mo>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mn>X</mn> <!-- "mn" is not space-like -->
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
</mstyle>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mn>X</mn>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
</math>
</p>
<!-- mphantom is an embellished operator if its in-flow children consist
of one embellished operator and zero or more space-like elements. -->
<p>
<math>
<mn>X</mn>
<mphantom id="mphantom-op-1" class="testedElement">
<mo lspace="2em" rspace="0em">X</mo>
</mphantom>
<mn>X</mn>
</math>
</p>
<p>
<math>
<mn>X</mn>
<mphantom id="mphantom-nonop-1" class="testedElement">
<mo lspace="2em" rspace="0em">X</mo>
<mn>X</mn> <!-- "mn" is not space-like -->
</mphantom>
<mn>X</mn>
</math>
</p>
<p>
<math>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mn>X</mn>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mphantom id="mphantom-op-2" class="testedElement">
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mo lspace="2em" rspace="0em">X</mo>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
</mphantom>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mn>X</mn>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
</math>
</p>
<p>
<math>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mn>X</mn>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mphantom id="mphantom-nonop-2" class="testedElement">
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mo lspace="2em" rspace="0em">X</mo>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mn>X</mn> <!-- "mn" is not space-like -->
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
</mphantom>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mn>X</mn>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
</math>
</p>
<!-- mpadded is an embellished operator if its children consist
of one embellished operator and zero or more space-like elements. -->
<p>
<math>
<mn>X</mn>
<mpadded id="mpadded-op-1" class="testedElement">
<mo lspace="2em" rspace="0em">X</mo>
</mpadded>
<mn>X</mn>
</math>
</p>
<p>
<math>
<mn>X</mn>
<mpadded id="mpadded-nonop-1" class="testedElement">
<mo lspace="2em" rspace="0em">X</mo>
<mn>X</mn> <!-- "mn" is not space-like -->
</mpadded>
<mn>X</mn>
</math>
</p>
<p>
<math>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mn>X</mn>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mpadded id="mpadded-op-2" class="testedElement">
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mo lspace="2em" rspace="0em">X</mo>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
</mpadded>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mn>X</mn>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
</math>
</p>
<p>
<math>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mn>X</mn>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mpadded id="mpadded-nonop-2" class="testedElement">
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mo lspace="2em" rspace="0em">X</mo>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mn>X</mn> <!-- "mn" is not space-like -->
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
</mpadded>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
<mn>X</mn>
<mn class="oof1">0</mn><mn class="oof2">1</mn><mn class="nobox">2</mn>
</math>
</p>
</body>
</html>