prevent pandoc from converting $ into mediawiki <math>

谁说我不能喝 提交于 2019-12-08 03:36:55

问题


I am converting a markdown file into mediawiki table using pandoc:

content of file mtcars.md:

|   |c1   |c2 |
|:--|:----|:--|
|7  |P$A |A  |
|8  |AB  |B  |
|9  |P$A |C  |

Then I do (I am using Ubuntu 64 bits and pandoc version 1.13.2)

pandoc -t mediawiki -o mtcars.txt mtcars.md

But the two $ signs are interpreted as <math>...</math>:

{|
!
!c1
!c2
|-
|7
|P<math>A |A | |8 |AB |B | |9 |P</math>A
|C
|}

How can I get the dollar signs instead?


回答1:


The pandoc documentation says:

Anything between two $ characters will be treated as TeX math. The opening $ must have a non-space character immediately to its right, while the closing $ must have a non-space character immediately to its left, and must not be followed immediately by a digit. Thus, $20,000 and $30,000 won’t parse as math. If for some reason you need to enclose text in literal $ characters, backslash-escape them and they won’t be treated as math delimiters.

So, one way is to put a backslash in front of the $:

|   |c1   |c2 |
|:--|:----|:--|
|7  |P\$A |A  |
|8  |AB  |B  |
|9  |P\$A |C  |

Output:

| |c1 |c2 | |:--|:----|:--| |7 |P$A |A | |8 |AB |B | |9 |P$A |C |

(I don't seem to get the same mediawiki output formatting as you, but you get the point).

Another way is to put a space after the $, although that adds a space in the output.

The interpretation of the $ signs are part of a markdown extension called tex_math_dollars - you should be able to suppress that altogether by specifying an input format of markdown-tex_math_dollars or markdown_strict (although that did not work on the older version of pandoc that I have here).



来源:https://stackoverflow.com/questions/29553312/prevent-pandoc-from-converting-into-mediawiki-math

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!