Pandoc:如何才能不转义 YAML 元数据中的反斜杠?
Pandoc 可以在 Markdown 中使用 YAML 标头,或者对所有源类型使用默认值或元数据文件,其中可以存储要在模板中使用的变量。是否可以在这些元数据变量中不转义反斜杠和 LaTeX 命令?
例如,我的 YAML 标头中包含以下行:phone: +49\,123\,456789
。转换时,Pandoc 会对反斜杠进行转义,因此变为 +49\textbackslash,123\textbackslash,456789。这是不需要的,因为我希望 LaTeX 解释 \,
并将其转换为薄空格。
我还尝试将其包装在 ''
中或用 |
作为块,因此 YAML 本身不会转义任何内容,但这似乎是 Pandoc 本身在进行转换,而不是YAML 解释器。
最小可重现示例
src.md:
Some text
defaults.yaml:
template: ./tpl.tex
metadata:
phone: +49\,123\,456789
tpl.tex:
Phone number: $phone$
Markdown body:
$body$
使用 pandoc --defaults defaults.yaml src.md --to Latex
输出:
Phone number: +49\textbackslash,123\textbackslash,456789
Markdown body:
Some text
应该是:
Phone number: +49\,123\,456789
Markdown body:
Some text
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
元数据总是会被转义;最简单的方法是做你想做的事,定义一个变量而不是元数据。
与元数据值相反,变量被逐字插入到模板中。
Metadata will always be escaped; the easiest way is to do what you want is to define a variable instead of metadata.
Contrary to metadata values, variables are inserted verbatim into the template.
您可以使用以下 unicode 字符: https://www.compart.com/en/unicode /U+202F
然后
通过
pandoc --defaults defaults.yaml src.md --to Latex -o test.tex
翻译为以下.tex
文件:You can use this unicode character: https://www.compart.com/en/unicode/U+202F
Then
gets translated via
pandoc --defaults defaults.yaml src.md --to latex -o test.tex
to the following.tex
file: