Aligning mathml equations at equal sign - mathml

I have three equations in MathML. I want to align them at equals sign. I certainly can do this using mtable and columnalign. Is there much better and clean way to do this ?

You can use <maligngroup/>

<maligngroup> and its kin were never widely implemented and have not made it into MathML Core. I haven’t found any explicit statement on what’s supposed to be used instead; the W3C MathML Polyfills repo doesn’t even try to replace them.
But I really don’t see anything in Core’s limited element set that would do the job except <mtable>. So that’s almost certainly the way to go.
Here’s a simple(?) example, together with how Firefox renders it on my system using the Latin Modern Math font.
<math display="block">
<mtable>
<mtr>
<mtd><mi>y</mi></mtd>
<mtd><mo>=</mo></mtd>
<mtd>
<mfrac>
<mrow>
<msup><mi>x</mi><mn>2</mn></msup>
<mo>−</mo>
<mn>4</mn>
</mrow>
<mrow>
<mi>x</mi><mo>−</mo><mn>2</mn>
</mrow>
</mfrac>
</mtd>
<mtd></mtd>
</mtr>
<mtr>
<mtd></mtd>
<mtd><mo>=</mo></mtd>
<mtd>
<mfrac>
<mrow>
<mrow>
<mo>(</mo>
<mrow>
<mi>x</mi><mo>+</mo><mn>2</mn>
</mrow>
<mo>)</mo>
</mrow>
<mo>&InvisibleTimes;</mo>
<mrow>
<mo>(</mo>
<mrow>
<mi>x</mi><mo>−</mo><mn>2</mn>
</mrow>
<mo>)</mo>
</mrow>
</mrow>
<mrow>
<mi>x</mi><mo>−</mo><mn>2</mn>
</mrow>
</mfrac>
</mtd>
<mtd></mtd>
</mtr>
<mtr>
<mtd></mtd>
<mtd><mo>=</mo></mtd>
<mtd><mi>x</mi><mo>+</mo><mn>2</mn></mtd>
<mtd>
<mtext>where </mtext>
<mrow><mi>x</mi><mo>&NotEqual;</mo><mn>2</mn></mrow>
</mtd>
</mtr>
</mtable>
</math>
Problem: the table content renders very small, especially in the <mfrac>.
Solution: That’s because <mtable> sets math-style: compact; by default. Use CSS to set math-style: normal; instead. (MathML Core is supposed to integrate better with CSS, so maths can be styled the same way as anything else on the Web.)
Problem: Nothing but Safari actually supports math-style as of this writing.
Solution: Bury your head in your hands and wait for a future browser release. At least Firefox has a config option to enable it, so I can show you how it should look.
Problem: You want your equations to be left-aligned.
Solution: Again, CSS is the way to go… but MathML lacks an equivalent to <col>/<colgroup> for styling a whole table column at once. Work around it using selectors (and possibly classes) to target the relevant cells. In this case, I used mtd:nth-child(3) { text-align: left; }.
Problem: There’s a big whack of spacing at the right side of the equations (the third column), and it’s not part of the cell padding nor of the space between cells.
Solution: ???

Related

Select All Japanese Text, But Without Romanization

Important Edit—
It appears that there's nothing wrong with my language code here, something else somewhere I've done in my CSS has stopped my code from working. This means all my guesses as to why it's not working were completely wrong. (lol)
When I find out what went wrong, I'll update this question; but if I can't find the error, I may just redo it from scratch— the project isn't so monolithic that that still is an option.
For now, the question is effectively solved.
Original Question—
I've been writing a mixed-language HTML document —primarily in English— and have been using different formatting for Japanese language text. For example, since Japanese doesn't use italicized/oblique or bold text, emphasis must be done with text-emphasis instead. However, romanized Japanese —Romaji— inherits these text effects when I'd rather it not.
This initial interaction was expected, so I tried to use :not(:lang(ja-latn)) to prevent this. While admittedly a bit messy, it ought to work… but it does not. I think the issue is that ja-latn, Romaji, is a kind of Japanese as far as HTML & CSS is concerned, and doesn't understand what I'm trying to do. Not labeling the Romaji or changing it to English would be textually inaccurate, confuse screen readers, and generally be a be a bit of a hack.
This is how I had done this (in a condensed form) provided as an example of what I mean. If I made some mistake in formatting not described in this post, that's only because I keep getting "Secure Connection Failed" errors whenever I try to test the snippet, and missed it.
i,em{font-style:italic;}
b,strong{font-weight:bold;}
:is(i,em):lang(ja):not(:lang(ja-latn)){
font-style:normal;
font-weight:normal;
text-emphasis: open currentcolor;
text-emphasis-position: over right;}
ruby{ruby-position:under;}
.goodhappy{color:green}
.wrongangry{color:red; text-emphasis-color:red;}
<div lang="en" >
English text, because I <em class="goodhappy" >don't</em> speak Japanese.<br />
<ruby lang="ja"><!--
-->日<rt lang="ja-hira" >に</rt><!--
-->本<rt lang="ja-hira" >ほん</rt><!--
-->語<rt lang="ja-hira" >ご</rt><!--
--><em class="goodhappy" >わ</em><rt lang="ja-hira" >わ</rt><!--
-->話<rt lang="ja-hira" >はな</rt><!--
-->せません<!--
--></ruby>
<br />
<span lang="ja-latn" >Nihongo <em class="wrongangry" >wa</em> hanasemasen</span>
</div>
How would I go about selecting only CJK japanese characters, but not Romaji text? To be clear, I realize this could be easily done by using a span.class and not using em/i/b/strong etc.. What I mean is, is there a way to accomplish this only in CSS, without more HTML markup than is strictly necessary?
In your question you stated that you tried :not(:lang(ja-latn)) with no success, but in your code you have :not(ja-latn) which is invalid. I changed your code using :not(:lang(ja-latn)) and as you can see it works properly leaving the romaji without the emphasis on top of it
i,em{font-style:italic;}
b,strong{font-weight:bold;}
:is(i,em):lang(ja):not(:lang(ja-latn)){
font-style:normal;
font-weight:normal;
text-emphasis: open currentcolor;
text-emphasis-position: over right;}
ruby{ruby-position:under;}
.goodhappy{color:green}
.wrongangry{color:red; text-emphasis-color:red;}
<div lang="en" >
English text, because I <em class="goodhappy" >don't</em> speak Japanese.
<ruby lang="ja"><!--
-->日<rt lang="ja-hira" >に</rt><!--
-->本<rt lang="ja-hira" >ほん</rt><!--
-->語<rt lang="ja-hira" >ご</rt><!--
--><em class="goodhappy" >わ</em><rt lang="ja-hira" >わ</rt><!--
-->話<rt lang="ja-hira" >はな</rt><!--
-->せません<!--
--></ruby>
<br />
<span lang="ja-latn" >Nihongo <em class="wrongangry" >wa</em> hanasemasen</span>
</div>

MathML: Enclose multiline elements in fences

In trying to learn MathML, I found that the mfenced element used in this tutorial has been deprecated, so that Firefox no longer supports it. This example in the official MathML documentation simply uses <mo>(</mo> and <mo>)</mo>, respectively, to surround fractions in parentheses. When I tried this, I found that the parentheses had normal height and did not stretch to the height of the fraction. Yet the example code had no special attribute to control the parenthesis height, suggesting that it should have adjusted automatically (as it would in LaTeX). What is missing? Below is my code.
<html>
<head>
<title>MathML in HTML5</title>
</head>
<body>
<p>
<math>
<mo>(</mo>
<mfrac linethickness="0">
<mrow><mn>5</mn></mrow>
<mrow><mn>2</mn></mrow>
</mfrac>
<mo>)</mo>
<mo>=</mo><mn>10</mn>
</math>
</p>
</body>
</html>
you also need mrow to surround the mo stuff:
replace <mfenced> with <mrow><mo>(</mo>
replace </mfenced> with <mo>)</mo></mrow>

Anime.js and MathML

I just discovered anime.js and it feels like the right tool for what I need (animating some web tutorials in 2D).
The problem is that I'm using MathML (part of the HTML5 standard), which uses "math" tags.
HTML
<math>
<mrow>
<msqrt>
<mrow>
<msup class="ml4">
<mi class="letter">b</mi>
<mn>2</mn>
</msup>
</mrow>
</msqrt>
</mrow>
</math>
JS
<script type="text/javascript" src="anime.min.js"></script>
<script>
anime.timeline({loop: true})
.add({
targets: '.ml4 .letter',
opacity: [0, 1],
scale: [0.2, 1],
duration: 800
});
</script>
When I try to simply animate letters within a math tag (opacity, scale, duration), I get:
If I use anime.min.js (2.0)
In Firefox
"TypeError: right-hand side of 'in' should be an object, got undefined"
-> anime.min.js:9:136
In Safari
"TypeError: a.style is not an Object. (evaluating 'b in a.style')"
-> "B" -> anime.min.js:9:145
If I use anime.js (2.0)
In Firefox
"TypeError: right-hand side of 'in' should be an object, got undefined"
-> anime.min.js:346:5
In Safari
"TypeError: a.style is not an Object. (evaluating 'b in a.style')"
-> "getCSSValue" -> anime.min.js:346
In both cases, the math formula appears just fine but the animation isn't working.
I tried previous versions of anime.js with the same result.
I toyed with the code and the animation comes back + the error message goes away on Firefox and Safari if I get rid of the "math" tag. But then, of course, the math formula is a mess, which is of no help.
But it seems the issue is related to this math tag alone.
I also tried to style, unstyle the math tag and the inner tags but the error remains.
I could understand that this tag is unsupported by animate.js but the animation works just fine and without any error within my Coda2 (web dev software) on Mac, on its own dedicated browser.
So this seems very browser dependent but so far it's the only browser that seems to consider the script as valid.
I haven't found anything on the web that is addressing both anime.js and the MathML so it's hard to say if it's a bug or an error on my part.
Thank you.
https://jsfiddle.net/bt4u23rh/1/
You can use a wrapper, or you can modify the function getCSSValue on the animejs library. Basically that function looks for the style property for that specific target.
function getCSSValue(el, prop) {
if (prop in el.style) {
return getComputedStyle(el).getPropertyValue(stringToHyphens(prop)) || '0';
}
}
When the code reaches the if line, your mi .letter doesn´t have that attribute and the call to the function fails and bubble up.
Using the proposed workaround, you can create a div that contains your mathML tags:
<div class="letterWrapper">
<math>
<mrow>
<msqrt>
<mrow>
<msup class="ml4">
<mi class="letter">b</mi>
<mn>2</mn>
</msup>
</mrow>
</msqrt>
</mrow>
</math>
</div>
https://jsfiddle.net/bt4u23rh/2/

Are token elements required in MathML?

As the question title states, is it okay to write just
<math>a <msup>x 2</msup> + b x + c</math>
or do you really need to write
<math>
<mrow>
<mi>a</mi> <mo>&InvisibleTimes;</mo> <msup><mi>x</mi><mn>2</mn></msup>
<mo>+</mo><mi>b</mi><mo>&InvisibleTimes;</mo><mi>x</mi>
<mo>+</mo><mi>c</mi>
</mrow>
</math>
As far as Firefox goes it doesn't render a
Invalid Markup
error, but that hardly means other browser might not in the future if the spec actually prohibits it officially.
As the question title states, is it okay to write just
<math>a <msup>x 2</msup> + b x + c</math>
No, it isn't.
do you really need to write
<math>
<mrow>
<mi>a</mi> <mo>&InvisibleTimes;</mo> <msup><mi>x</mi><mn>2</mn></msup>
<mo>+</mo><mi>b</mi><mo>&InvisibleTimes;</mo><mi>x</mi>
<mo>+</mo><mi>c</mi>
</mrow>
</math>
Yes, see http://www.w3.org/TR/MathML3/chapter2.html#fund.syntax.
As far as Firefox goes it doesn't render a "Invalid Markup" error, but that hardly means other browser might not in the future if the spec actually prohibits it officially.
At the begin browsers render a "Invalid Markup" error for anything that doesn't follow the spec. Today browsers try to correct the markup. For example
<p>
<ul>
<li>foo</li>
<li>bar</li>
</ul>
<p>
is invalid since you need to use
<p></p>
<ul>
<li>foo</li>
<li>bar</li>
</ul>
<p></p>
but no browser will stop rendering the page because of it.
MathML is intended for mathematics presentation markup. It is aimed to provide all information needed for correctly typesetting a mathematical formula.
In mathematical typesetting, identifiers (or, simply "variables"), operators and numbers are typeset differently. There are a lot of subtle differences, but to name a few: identifiers are normally italic style (and use a mathematical serif font), whereas numbers are roman style. Operators use subtle spacing rules on either side. These are just a few examples.
As presentation MathML is not intended to describe the meaning of a formula, merely how it looks, all this information must be encoded in the markup. The MathML renderer does not interpret the formula, either. It looks at the markup and renders accordingly.
Authoring MathML directly is not easy, and, in fact, it is mostly done programmatically, rather than inputting directly. If you need a more straightforward way, try ASCIImath or LaTeX. A renderer like MathJax renders those as well.

How to Make an OS X Style Search in XHTML/CSS

Any way to make a OS X Finder "like" but valid XHTML/CSS search textfield with an X to the right, etc.? Even if it only shows up on Safari but degrades that would be fine. I've seen a couple of examples but they seem very complicated.
If you're OK with supporting only the newest WebKit-based browser, you can use the new HTML5 feature like this:
<form>
<input name="q" type="search">
<input type="submit" value="Find">
</form>
That's it, no CSS, no Javascript or whatever!
See an excellent discussion here.

Resources