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

Math expressions syntax #64

Closed jfernandz closed 4 years ago

jfernandz commented 4 years ago

I was wondering why the extension does not support the typical syntax for math expressions, I mean, when you use

:stem: latexmath

= Title

whatever expression you want \(\quad \rightarrow \quad a^2 + b_c = \sqrt{h\cdot d}\)

It is not being rendered, it is necessary to use always latexmath:[] or stem:[] to get them rendered? I find this pretty bothering. I'd prefer a more latex-like behaviour.

ProgramFan commented 4 years ago

The \( \) are not part of the asciidoc syntax, so they do not go through this extension. asciidoctor-latex can handle it.

jfernandz commented 4 years ago

@ProgramFan asciidoctor-latex is not as functional as I would like with tables and lists, see https://github.com/asciidoctor/asciidoctor-latex/issues/85 so ... what do you recommend me to produce a readable pdf when I'm using \(\) latex syntax inside tables or lists?

ProgramFan commented 4 years ago

Maybe one can write a preprocessor to convert this to stem:[]. But before this happens, there seems no direct support for the \(\) syntax. Would you mind using a regex replace to change them into the standard asciidoc stem syntax?

jfernandz commented 4 years ago

@ProgramFan that's a good suggestion, but the point is in LaTex the \(\) is not the same than \[\] (which I'm also using in my docu despite it does not appear in initial MWE).

The second one is used to force a displayed math environment, so you'll get the equation in a new line.

The first one is used to inline math mode. As you can see here

I guess there is not such a difference like this in asciidoc unfortunately.

ProgramFan commented 4 years ago

Regex would be a much simpler tool. In most cases, cat <FILE> | sed -e 's/\(/stem:[/g' | sed -e 's/\)/] will do the first and a similar one will do the second.

jfernandz commented 4 years ago

Oh, yes, but I was talking about differences between inline math mode and display math mode in asciidoc there exist those different modes? Or maybe are just all stem:[]?

ProgramFan commented 4 years ago

Yes. The following is for display mode:

[stem]
++++
x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
++++
jfernandz commented 4 years ago

And could be that used inside nested lists or tables? I mean, to illustrate, I've been watching in here that stem blocks are supported inside tables (don't know about nested tables but I guess they also are). However not for list or nested lists, like this MWE shows.

This is not even rendering

* What about a stem block
** Inside a
[stem]
++++
a^2+b^2=c^2
++++
nested list?

And this one:

* What about a stem block
** Inside a

[stem]
++++
a^2+b^2=c^2
++++
nested list?

Does render but nested list? is not being part of the nested list.

ProgramFan commented 4 years ago

Insert a plus sign after the "Inside a":

* What about a stem block
** Inside a
+
[stem]
++++
a^2+b^2=c^2
++++
nested list?

You should do this in the original asciidoc file, too. It's asciidoc's rule to force continuation of a multiline list item.

jfernandz commented 4 years ago

@ProgramFan Thank you for your help, this one-liner did the work

cat <file> | sed -e 's/\\(/stem:[/g' | sed -e 's/\\)/]/g' | sed -e 's/\\\[/\n+\n[stem]\n++++\n/g' | sed -e 's/\\]/\n++++\n/g' > <file_converted>

However ... there is still a situation where I don't get properly results, when I have something like

\(\frac{[E]}{d}\)

The conversion will be

stem:[\frac{[E]}{d}]

Which is interpreted like stem:[\frac{[E] so ... how could I use [] inside stem:[] ? is there a kind of escape character?

EDIT: I've realised that I must include \ before ]

stem:[\frac{[E\]}{d}]
ProgramFan commented 4 years ago

IMO, stem:[\frac{[E]}{d}] should work since using brackets is very common in math typesetting.

jfernandz commented 4 years ago

IMO, stem:[\frac{[E]}{d}] should work since using brackets is very common in math typesetting.

I thought exactly that, square brackets are so common in math syntax and this should be rendered usually, but did not work in my case and you have not any similar example in here with those squared brackets, I mean. I've not got a proper render even using the \left[ \right] latex syntax

Could you try and confirm me? Also I've detected a few render issues that I'm going to report in #67