-
I use pandoc to convert from org file to docx. It works quite well except that I have some defined latex commands that are not translated in the finale docx document. I would like to use filters to change on the fly my latex commands to something pandoc understands. As an example, I have difficulties to understand how pandoc lua filters work. How would you do with this simple example ? Regards |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
simple example: function Math(el)
el.text = string.gsub(el.text, "\\ket", "something else")
end |
Beta Was this translation helpful? Give feedback.
-
Thanks for your answer. I wrote this function Math(el)
el.text = string.gsub(el.text, "\\ket{(.-)}", "\\vert %1 \\rangle")
end in a file Then, I tested it with : printf "$\ket{eaaza}$ hello" | pandoc --from latex -t native --lua-filter filter-math.lua It returned :
Pandoc did not return any errors (exit code=0). What am i doting wrong ? EDIT1 : I checked directly in lua interpreter that the lua code works as expected, it seems that EDIT2: Got it ! You must return the element function Math(el)
el.text = string.gsub(el.text, "\\ket{(.-)}", "\\vert %1 \\rangle")
return el
end If you have several replacements to do in math environments, do you have to make them in the same function |
Beta Was this translation helpful? Give feedback.
Thanks for your answer.
I wrote this
in a file
filter-math.lua
.Then, I tested it with :
It returned :
Pandoc did not return any errors (exit code=0). What am i doting wrong ?
EDIT1 : I checked directly in lua interpreter that the lua code works as expected, it seems that
pandoc
just not applies it.EDIT2: Got it ! You must return the element
el
at the end of lua function. So the working code is :