MathJax-node icon indicating copy to clipboard operation
MathJax-node copied to clipboard

in command line not able to escape single quote character in mathml

Open gbala2412 opened this issue 6 years ago • 6 comments

Error: bash: syntax error near unexpected token `<'

Not able to escape single quote character node /usr/local/lib/node_modules/mathjax-node-cli/bin/mml2svg '<math><mi>μ</mi><msup><mrow><mo>'</mo></mrow><mrow><mn>2</mn></mrow></msup></math>' > eqn.svg

gbala2412 avatar Jun 27 '19 12:06 gbala2412

CLI issues belong in its repository https://github.com/mathjax/mathjax-node-cli

But I suspect it's just the apostrophe in the mml expression that is closing the argument.

pkra avatar Jun 27 '19 12:06 pkra

Peter is correct, the problem is the internal ' which closes the initial ' being used as the quotation mark, so the rest of the MathML is being interpreted by bash as part of the command. Try

bin/mml2svg "<math><mi>μ</mi><msup><mrow><mo>'</mo></mrow><mrow><mn>2</mn></mrow></msup></math>" > eqn.svg

instead.

dpvc avatar Jun 27 '19 14:06 dpvc

Sorry I am already tried the double quotes also which I forgot to mention. That also throws error if the mathml contains attributes.

node /usr/local/lib/node_modules/mathjax-node-cli/bin/mml2svg "<math><mi mathvariant="normal">μ</mi><msup><mrow><mo>'</mo></mrow><mrow><mn>2</mn></mrow></msup></math>" > eqn.svg MathML - Error parsing MathML: Unquoted attribute value Column: 66 Char: n

gbala2412 avatar Jun 27 '19 17:06 gbala2412

Yes, these are the issues you face when trying to pass content containing quotation marks to command-line programs. One solution would be to use single quotes for the attribute values

bin/mml2svg "<math><mi mathvariant='normal'>μ</mi><msup><mrow><mo>'</mo></mrow><mrow><mn>2</mn></mrow></msup></math>" > eqn.svg

as this is still valid MathML. Alternatively, you can replace the internal ' with &prime;:

bin/mml2svg '<math><mi mathvariant="normal">μ</mi><msup><mrow><mo>&prime;</mo></mrow><mrow><mn>2</mn></mrow></msup></math>' > eqn.svg

But you will have to modify the original string in some way if it contains both " and ' internally. Either that, or you will need to modify mml2svg in order to take its input from STDIN instead of as a parameter, for example, so that you can pass the MathML string to it directly as input rather than as a command-line parameter, which avoids the problem with command-line special characters.

dpvc avatar Jun 27 '19 20:06 dpvc

In any case, none of these are problems with mathjax-node itself, but with your interaction with your command shell, so are really outside the scope of this issue tracker.

dpvc avatar Jun 27 '19 20:06 dpvc

Thank you!

gbala2412 avatar Jun 28 '19 08:06 gbala2412