Pages: 1
Print
Author Topic: CSS set specific style to second child element  (Read 725 times)
JS_Nbg_DE
Member

Posts: 2


« on: December 21, 2017, 09:38:27 AM »

Hello,

is it possible to set a specific style to the second child element?
In this sample i want the second child element of msub should be shown with vertical-align sub in xMax.

<math><mrow><mi>X</mi><mo>=</mo><msub><mi>F</mi><mi>ab</mi></msub><mo>x</mo><mi>Y</mi></mrow></math>

This don't work:

msub > *[2] {
  display: inline;
  vertical-align: sub;
  font-size: 0.8em;
}

Thanks
Josef
Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 2579



WWW
« Reply #1 on: December 21, 2017, 02:35:55 PM »

This type of selector isn't supported. The following would do it but only for this specific case:

msub > mi mi {
  vertical-align: sub
}

That's going to affect all <mi> elements that have a <mi> before them.

If you are going to have content where there are more than two <mi> elements you would have to write a script to affect just one and not the others. Something similar to the following would do that:

Code:
//XMetaL Script Language JScript:
//create a Range we can move around to alter style(s) for specific elements
var rng = ActiveDocument.Range;
//get all nodes that are the second mi sibling inside msub:
var nodes = ActiveDocument.getNodesByXPath("//msub/mi[2]");
//loop through the list of nodes, move the Range to each, and set the style(s):
for(i=0; i<nodes.length; i++) {
rng.SelectNodeContents(nodes.item(i));
rng.ContainerStyle = "display:inline; vertical-align:sub; font-size:0.8em";
}

Note to anyone that wants to use this approach for DITA: Please don't try. Modifying the DITA customization's scripts is not supported.

Regarding MathML:
If you are trying to style MathML to make it easier to edit in XMetaL Author I think that's going to be a lot of work unless you use a very small specific subset and perhaps only use some specific equation layouts. If you use MathML on a regular basis I would highly recommend Design Science's "MathFlow Editor" for XMetaL Author (it works with XMAX as well): https://www.dessci.com/en/products/mathflow/mf_for_xmetal.htm
« Last Edit: December 21, 2017, 02:38:19 PM by Derek Read » Logged
Pages: 1
Print
Jump to: