jgm / pandoc

Universal markup converter
https://pandoc.org
Other
33.89k stars 3.34k forks source link

Dokuwiki math support [enhancement] #5319

Open bachmeil opened 5 years ago

bachmeil commented 5 years ago

Conversion from Dokuwiki doesn't support math. The standard way to add math to a Dokuwiki page is with the MathJax plugin, and the syntax is the same as markdown. This currently fails:

$$y_{i} = \varepsilon_{i}$$

with message

Error at "source" (line 5, column 5):
unexpected "i"
expecting "{{"
$$y_{i} = \varepsilon_{i}$$
    ^

The error message says expecting "{{" but that's because it's trying to link to an image. That doesn't help with math.

RyanGreenup commented 4 years ago

Yeah I just ran into this, I tried:

pandoc -f dokuwiki+tex_math_double_dollars -t latex 

and it returns an error saying that there is no support.

I would love to see this implemented because dokuwiki is very common and as opposed to mediawiki does not require a database making it more portable.

A workaround that I hope continues to work is to do this:

pandoc input.txt -f dokuwiki -t org | pandoc -f org -t pdf -o file.pdf

This isn't too bad because org-mode supports a tonne of markup and so should handle most things fairly well.


Edit:

A more reliable solution would be to use the Dokuwiki Parser out of the gate, this will only work if the MathJax Extension is installed, assuming that Dokuwiki is installed in /srv/http/dokuwiki, take some exemplar file.dw and convert it like so:

sudo \
/srv/http/dokuwiki/bin/render.php  < file.dw |\
pandoc -f html+raw_tex+tex_math_dollars+tex_math_single_backslash -t latex |\
pandoc -f latex -t html --mathjax -s -o /tmp/file.html
xdg-open file.html & disown

the output should have all the math working as would be expected

Output
Source Output
file.dw
This is some text

====== H1 ======

===== H2 =====

==== H3 ====

=== H4 ===

== H5 ==

- H6 should become a bullet item

====== What Should Work ======

===== LaTeX AMSmath Align =====

I don't know what a raw block is

\begin{align}
8 &= 8x^2+  4x +  3 \\
0 &= 8x^2 +  4x - 5 \\
x &= \frac{- b \pm \sqrt{b^2- 4\times 8\times \left( - 5 \right) }  }{2\times 8} 
\end{align}

====== What could appear ======

===== KaTeX Aligned =====

$$\begin{aligned}
8 &= 8x^2+  4x +  3 \\
0 &= 8x^2 +  4x - 5 \\
x &= \frac{- b \pm \sqrt{b^2- 4\times 8\times \left( - 5 \right) }  }{2\times 8} 
\end{aligned}$$

===== Dollars Align =====
This isn't valid LaTeX but works in MathJax and should be interpreted.

$$
\begin{align}
8 &= 8x^2+  4x +  3 \\
0 &= 8x^2 +  4x - 5 \\
x &= \frac{- b \pm \sqrt{b^2- 4\times 8\times \left( - 5 \right) }  }{2\times 8} 
\end{align}
$$

===== Backslash Align =====
This isn't valid LaTeX but works in MathJax and should be interpreted.
\[
\begin{align}
8 &= 8x^2+  4x +  3 \\
0 &= 8x^2 +  4x - 5 \\
x &= \frac{- b \pm \sqrt{b^2- 4\times 8\times \left( - 5 \right) }  }{2\times 8} 
\end{align}
\]

RyanGreenup commented 3 years ago

To go in the other direction from org-mode to dokuwiki without losing raw LaTeX this filter could be used:

#!/usr/bin/env python

"""
Pandoc filter to convert raw tex to paragraph for dokuwiki
"""

from pandocfilters import toJSONFilter, Emph, Para

def raw_to_para(key, value, format, meta):
  if key == 'RawBlock' and value[0] == 'latex':
    math_content = value[1]
    math_value=[{
            "t": "Str",
            "c": math_content
                }]

    return Para(math_value)

if __name__ == "__main__":
  toJSONFilter(raw_to_para)

so save that in filter.py and then run:

chmod +x filter.py
pip install pandocfilters
pandoc file.txt -f dokuwiki -t org --filter ./filter.py