如何使用Pandoc和LaTeX从docx转换为pdf时解决“缺失字符”的警告?

9

目标

我有几千个高棉语的.docx文件,希望使用Pandoc将它们转换为.pdf格式。

背景

我使用MacPorts安装了Pandoc。Pandoc需要LaTeX才能进行PDF转换,所以我安装了MacTeX。安装似乎已经正确完成,我已经能够轻松将英语语言的.docx文件转换为.pdf

尝试1

当我尝试将一份高棉语文件(您可以在https://briancroxall.net/pandoc/transcription.docx找到一个示例)转换为PDF时,我使用以下命令:

pandoc transcription.docx  -s -o transcript.pdf


我收到了以下错误信息:

Error producing PDF.
! Package inputenc Error: Unicode character អ (U+17A2)
(inputenc)                not set up for use with LaTeX.

See the inputenc package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.64 ...�នៅសម័យប៉ុល ពត។}

Try running pandoc with --pdf-engine=xelatex.

第二次尝试

按照这个建议,我使用了这个命令:

pandoc --pdf-engine=xelatex transcription.docx  -s -o transcript.pdf

Pandoc 在文本中遇到每个高棉字符时都会抛出一个错误消息:

[WARNING] Missing character: There is no អ in font [lmroman10-bold]:mapping=tex-text;!
[WARNING] Missing character: There is no ្ in font [lmroman10-bold]:mapping=tex-text;!
[WARNING] Missing character: There is no ន in font [lmroman10-bold]:mapping=tex-text;!
...

这个过程会生成一个PDF文件(参见https://briancroxall.net/pandoc/transcript.pdf),但是该文件内容几乎为空。
问题:
据我所知,这意味着我尝试使用的LaTeX引擎中没有可用的高棉字字符号。无论如何,我该如何成功地进行此文件转换?

1
尝试将 mainfont 设置为 Khmer MNKhmer Sangam MN,请参见 https://pandoc.org/MANUAL.html#fonts(以及 https://alvinalexander.com/macos/list-xetex-xelatex-fonts-available-mactex)... 也许还可以参考 https://tex.stackexchange.com/a/234796/33952。 - mb21
1个回答

11

mb21的评论帮助我弄清了这个问题。由于我的系统安装了一些高棉语字体,所以我必须将mainfont设置为其中一个。

$ pandoc --pdf-engine=xelatex transcription.docx \ 
      -V 'mainfont:Khmer MN' -s -o transcription.pdf

这将生成一个包含高棉字符且没有错误信息的PDF文档。

然而,PDF文件似乎存在问题,即部分高棉短语会超出页面边缘。我认为这是由于分段问题,Word可以处理但在转换为PDF时出现了问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接