asciidoctor / asciidoctor-mathematical

An extension for Asciidoctor that converts the content of STEM blocks and inline macros using Mathematical.
MIT License
50 stars 45 forks source link

AsciiMath support for asciidoctor-pdf #87

Closed mcp292 closed 3 years ago

mcp292 commented 3 years ago

Currently there is no support for asciimath for PDF, only latexmath.

mojavelinux commented 3 years ago

The AsciiMath gem can now produce LaTeX output. That means this extension could use the API provided by that gem to convert the expression to LaTeX, then pass that result to mathematical to get an image out of it.

mojavelinux commented 3 years ago

Aha! I see this has already been done (by PR #85).

However, it's not quite right. The extension is not honoring the value of the stem attribute. If the stem attribute is set on the document, then the stem block or inline macro should be processed as AsciiMath. This is not currently happening.

Here's an example:

:stem:

stem:[sqrt(2)]
mojavelinux commented 3 years ago

This logic is incorrect:

    case document.attr 'stem'
    when 'latexmath'
      support_stem_prefix = true
      stem_rx = LatexmathInlineMacroRx
    when 'asciimath'
      support_stem_prefix = true
      stem_rx = AsciiMathInlineMacroRx
    else
      support_stem_prefix = false
      stem_rx = StemInlineMacroRx
    end

Setting the stem attribute to an empty value is the same as setting it to asciimath. When the stem attribute is set, the stem inline macro should always be processed. Whether it should be processed as AsciiMath or LaTex depends on the value of the stem attribute. It should only be processed as LaTeX if the value of the stem attribute is latexmath.

mojavelinux commented 3 years ago

It's possible to workaround this problem by using the asciimath inline macro in place of the stem inline macro. (e.g., asciimath:[sqrt(2)]). However, I'd like to see this fixed so that the behavior is compliant with other converters.

mojavelinux commented 3 years ago

The problem with the processing of the stem inline macro has been reported separately as #89. Therefore, I'm going to close this issue since we know now that AsciiMath is supported.