sympy / sphinx-math-dollar

Sphinx extension to let you write LaTeX math using $$
https://www.sympy.org/sphinx-math-dollar/
MIT License
33 stars 11 forks source link

Issue with absolute values #16

Open asmeurer opened 4 years ago

asmeurer commented 4 years ago

The math $|y| \geq |x^e|$ produces an error

WARNING: Inline substitution_reference start-string without end-string.

Changing the transformer priority to lower than that of substitutions doesn't seem to fix it. http://docutils.sourceforge.net/docs/ref/transforms.html

asmeurer commented 4 years ago

This happens at the parser level. I think the node level that we are currently working at is too late in the process. Even if we could reconstruct it from the node, the warning will already be omitted. So I think we need to modify the extension to work at the parser level. The node level may also be necessary to prevent math from being used inside of code blocks.

asmeurer commented 4 years ago

I guess we can make a parser subclass and register it. https://www.sphinx-doc.org/en/master/extdev/parserapi.html

asmeurer commented 4 years ago

I don't know how easy this will be to fix. For now, if you get a warning like this from using dollar math, you should just use the :math: role as a workaround.

webknjaz commented 4 years ago

$|y| \geq |x^e|$

Have you tried it like this $\ |y| \geq |x^e|\ $?

asmeurer commented 4 years ago

That doesn't work. The problem is that Sphinx parses out the |y| and |x^e| as substitutions before the sphinx-math-dollar extension parsers the dollar signs as math. The substitution parsing happens very early in the RST parser, even earlier than the creation of the AST.

sylee957 commented 3 years ago

I think that it is possible to make a workaround like ${ | y | \geq | x^e | }$ where

  1. You add extra spacing before and after every vertical bars |
  2. Wrap the whole LaTeX with braces {}