Render latex in table

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Render latex in table

maydb
# Description

I want to use asciidoctor table to record some formulas in probability theory, some formulas involves latex.

```
|===
| distribution | parameter | probability distribution | E(x) | D(x)

| binominal distribution
| n \geqslant 1

0 < p < 1
| P{X=k} = \binom{n}{k} p^k (1-p)^{n-k}
| np
| np(1-p)

| poisson distribution
| \lambda > 0
| P{X=k} = \frac{\lambda^k e^{-\lambda}}{k!}, k=0,1 ...
| \lambda
| \lambda

| uniform distribution
| a < b
|
| \frac{a+b}{2}
| \frac{(b-a)^2}{12}

| exponential distribution
| \lambda > 0
|
| \frac{1}{\lambda}
| \frac{1}{\lambda^2}


| normal distribution
| \mu, \sigma > 0
|
| \mu
| \sigma^2

|===
```

# First try failed

I go through the Asciidoctor User Manual, and decide to use stem block

```
= Render formula in table
:stem: latexmath

[stem]
++++
put that table here
++++
```

But it doesn't render table.

# Second try success

Then I try to use inline latexmath macro syntax like `latexmath:[C = \alpha + \beta Y^{\gamma} + \epsilon]`

```
= Render formula in table
:stem: latexmath

[stem]
++++
|===
| distribution | parameter | probability distribution | E(x) | D(x)

| binominal distribution
| n \geqslant 1

0 < p < 1
| latexmath:[P{X=k} = \binom{n}{k} p^k (1-p)^{n-k}]
| np
| np(1-p)

|===
++++
```

It works, but I need to add inline latexmath macro syntax for every formula.

# Better way?

I want to know if there is some easier ways to do that?



Reply | Threaded
Open this post in threaded view
|

Re: Render latex in table

Alexander Schwartz
Adding a latexmath:[] for every formula is the only way it will work AFAIK. This allows you to choose for each cell if it is math or text, and you can even mix math and text within a cell.
Alexander Schwartz (alexander.schwartz@gmx.net)
https://www.ahus1.de
Reply | Threaded
Open this post in threaded view
|

Re: Render latex in table

mojavelinux
Administrator
Alexander is correct. AsciiDoc does not support using raw LaTeX. That would wreak havoc on the parser since there are so many special characters. Wrapping the LaTeX code inside a macro ensures that doesn't happen.

You can use the stem macro if you set the stem document attribute to latexmath.

Best,

-Dan

On Fri, Nov 22, 2019 at 2:25 PM Alexander Schwartz [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Adding a latexmath:[] for every formula is the only way it will work AFAIK. This allows you to choose for each cell if it is math or text, and you can even mix math and text within a cell.
Alexander Schwartz ([hidden email])
https://www.ahus1.de



If you reply to this email, your message will be added to the discussion below:
https://discuss.asciidoctor.org/Render-latex-in-table-tp7366p7367.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML


--
Dan Allen | @mojavelinux | https://twitter.com/mojavelinux