Skip to content

Substituting latex command in equation and math environment #10486

Answered by deb75
deb75 asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks for your answer.

I wrote this

function Math(el)
    el.text = string.gsub(el.text, "\\ket{(.-)}", "\\vert %1 \\rangle")
end

in a file filter-math.lua.

Then, I tested it with :

printf "$\ket{eaaza}$ hello" | pandoc --from latex -t native  --lua-filter filter-math.lua

It returned :

[ Para
    [ Math InlineMath "\\ket{eaaza}" , Space , Str "hello" ]
]

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 :

function Math(el)
    el.text = string.gsub

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@jgm
Comment options

jgm Dec 23, 2024
Maintainer

Answer selected by deb75
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants