'Pandoc: How can I not escape backslashes in YAML metadata?

Pandoc can use a YAML header in Markdown or a defaults or metadata file for all source types where one can store variables to use in the template. Is it possible to not escape backslashes and LaTeX commands inside these metadata variables?

For example, I'd have this line in my YAML header: phone: +49\,123\,456789. When converting, Pandoc escapes the backslashes, so it becomes +49\textbackslash,123\textbackslash,456789. This is unwanted, as I want LaTeX to interpret \, and turn it into thin spaces.

I also tried wrapping it in '' or as block with |, so YAML itself doesn't escape anything, but this seems to be Pandoc itself doing the conversion, not the YAML interpreter.

Minimum reproducible example

src.md:

Some text

defaults.yaml:

template: ./tpl.tex
metadata:
  phone: +49\,123\,456789

tpl.tex:

Phone number: $phone$

Markdown body:
$body$

Output with pandoc --defaults defaults.yaml src.md --to latex:

Phone number: +49\textbackslash,123\textbackslash,456789

Markdown body:
Some text

Should be:

Phone number: +49\,123\,456789

Markdown body:
Some text


Solution 1:[1]

You can use this unicode character: https://www.compart.com/en/unicode/U+202F

Then

template: ./tpl.tex
metadata:
  phone: +49?123?456789

gets translated via pandoc --defaults defaults.yaml src.md --to latex -o test.tex to the following .tex file:

Phone number: +49\,123\,456789

Markdown body:
Some text

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 samcarter_is_at_topanswers.xyz