How to turn off escaping letters when using Goldmark

There is a lot of math in my posts. In LaTeX, I break the lines using ‘\’. However when I generate the html files using hugo, it is translated into '', making further rendering by MathJax unavailable.
A possible solution to this is to use ‘\\’ instead of ‘\’. But I want my markdown files to be consistent with my original ones. In fact ‘\’ works fine for vscode preview, I don’t want to ‘translate’ my posts before I publish them using Hugo.
So is there any way to turn off such escaping ?

No, there is not.

Did you try Pandoc instead of Goldmark?

I realize this is an old thread, but for what it’s worth, what I ended up landing on was using a Lua filter in conjunction with pandoc to preprocess my markdown files to programmatically handle these cases.

Eg

function Math(elem)
	-- Check if the math block is a display math block and contains \begin{align}
	if elem.mathtype == "DisplayMath" and elem.text:find("\\begin{align}") then
		-- Replace line breaks \\ within \begin{align} ... \end{align} blocks with \\\\
		elem.text = elem.text:gsub("(%\\begin{align}.-%\\end{align}[%a]*)", function(alignBlock)
			return alignBlock:gsub("\\\\", "\\\\\\\\")
		end)
	end

	-- Replace \# with \\# and \\ with \\\\
	elem.text = elem.text:gsub("\\#", "\\\\#")

	return elem
end

return {
	{ Math = Math }
}

You can then apply this filter by running:

pandoc input.md --lua-filter=filter.lua -o output.md

You can recursively apply this to your set of markdown files. I’ve found it to be a practical compromise as long as it’s not possible to have Goldmark natively handle this for us. For me I just embedded this into my release pipeline when building/deploying my Hugo site.

You can even modify the Lua script to use the global pandoc object

function Math(elem)
	local content = elem.text
	content = content:gsub("\\#", "\\\\#")
	return pandoc.Math(elem.mathtype, content)
e