asciidoctor / asciidoctor-mathematical

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

Failed to parse mtexFailed #63

Open aldib opened 4 years ago

aldib commented 4 years ago

I'm getting a Failed to parse mtexFailed and asciidoctor: WARNING: could not embed image: /documents/stem-7fc90f81ed556fcd40a8504532a4dfb9.svg; The data supplied is not a valid SVG document. when trying to render Latex block in PDF or HTML using asciidoctor-mathematical . The problem is easy to reproduce:

  1. create a test.adoc:
    
    # Test
    :doctype: article
    :stem: latexmath
    :icons: font

Probability distribution

Probability distributions describe uncertainty by describing the behaviour of random variables. In mathematical terms, a probability distribution function stem:[Pr(x)] with domain stem:[ \Omega ] is defined as follows:

. stem:[ f(x) \ge 0 \text{ } \forall x \in \Omega ]. . stem:[ \sum_{x \in X} Pr(x) = 1 ]

2. Convert it to HTML (or PDF) using `docker run --rm -v `pwd`:/documents/ --workdir /documents asciidoctor/docker-asciidoctor:latest asciidoctor --trace -r asciidoctor-mathematical -a mathematical-format=svg test.adoc`

I'm using the latest Docker image `asciidoctor/docker-asciidoctor:latest` to render the document and the versions of the libraries are:

ARG asciidoctor_version=2.0.10 ARG asciidoctor_confluence_version=0.0.2 ARG asciidoctor_pdf_version=1.5.0.beta.5 ARG asciidoctor_diagram_version=1.5.18 ARG asciidoctor_epub3_version=1.5.0.alpha.9 ARG asciidoctor_mathematical_version=0.3.1 ARG asciidoctor_revealjs_version=2.0.0



The text renders without problems using MathJax or plain Latex.

Any help would be appreciated.
lurch commented 4 years ago

It might be worth trying to narrow down your testcase and identify exactly which of the STEM snippets isn't working? The simpler the testcase, the easier it'll be for the developers to debug it.

lurch commented 4 years ago

... I had a bit of spare time this evening, so I decided to have a go at creating my own minimal test case :wink:

I'm not using the docker container, but these locally-installed versions: (according to gem info) asciidoctor (2.0.10) asciidoctor-mathematical (0.3.1)

With the (simpler) test-file below, the symbols next to "Omega 1", "Omega 2" and "Omega 4" get displayed correctly, but the symbol next to "Omega 3" doesn't get displayed.

:stem: latexmath

Omega 1:
[stem]
++++
\Omega
++++

Omega 2:
[stem]
++++
 \Omega 
++++

Omega 3:
stem:[ \Omega ]

Omega 4:
stem:[\Omega]

I'm using the command asciidoctor --trace -r asciidoctor-mathematical -a mathematical-format=svg test.adoc, and as above the only error-output on the command-line is Failed to parse mtex.

jfernandz commented 4 years ago

@lurch I'm having a similar issue, in my case the error message is

Failed to parse mtexasciidoctor: WARNING: could not embed image: /path/to/stem-xxxxxx.png; image file is an unrecognised format; install prawn-gmagick gem to add support
asciidoctor: WARNING: could not embed image: /path/to/stem-xxxxxx.png; image file is an unrecognised format; install prawn-gmagick gem to add support

I've got prawn-gmagick already installed but the issue persist. Indeed the stem-xxxxxx.png file generated is not a valid .png file cause I cannot open it with a picture viewer like eog. So I guess something must be generating bad this particular stem-xxxxxx.png file.

I would like to know at least how to debug which particular stem:[] macro is responsible for this bad png file. But I don't know how to do that.

Mauville commented 4 years ago

I've also experienced this issue. As an addition to the cases above, I found yet more that do not output correct PNGs or SVGs.

:stem: latexmath

. Calculate \(\nabla f   \) with \( \nabla f =<fx,fy>\)
:stem: latexmath

stem:[
\int_{\theta_1}^{\theta_2} \int_{r_1}^{r_2} (\operatorname{pol}\left(f\left(x\right)\right)-\operatorname{pol}\left(g\left(x\right)\right)) \cdot r \cdot dr dt
 ]

Finally, although this one is pushing it a bit since it's not surrounded by anything, the following syntax works perfectly with MathJax but does not even get recognized by mathematical.

:stem: latexmath

\begin{aligned}
&x=x_{0}+f_{x}\left(x_{0}, y_{0}\right)t\\
&y=y_{0}+f_{y}\left(x_{0}, y_{0}\right)t\\
&z=z_0-t
\end{aligned}