Pandoc Markdown 转换为 PDF:如何修复缺失字符警告?

8

我看过如何使用Pandoc和LaTeX将docx转换为pdf时修复“缺失字符”警告?,但不幸的是,那里的建议似乎不适用于这个测试案例:

$ git clone https://github.com/raspberrypi/documentation.git
$ cd documentation/configuration
$ pandoc *.md --pdf-engine=xelatex -o result.pdf
[WARNING] Missing character: There is no ┌ (U+250C) in font [lmmono10-regular]:!
[WARNING] Missing character: There is no ─ (U+2500) in font [lmmono10-regular]:!
[WARNING] Missing character: There is no ─ (U+2500) in font [lmmono10-regular]:!
[WARNING] Missing character: There is no ─ (U+2500) in font [lmmono10-regular]:!
[WARNING] Missing character: There is no ─ (U+2500) in font [lmmono10-regular]:!
...
[WARNING] Missing character: There is no ─ (U+2500) in font [lmmono10-regular]:!
[WARNING] Missing character: There is no ─ (U+2500) in font [lmmono10-regular]:!
[WARNING] Missing character: There is no ┘ (U+2518) in font [lmmono10-regular]:!

所以,有一些特定的“方框绘制”字形,在Latin Modern Mono中缺失-因此它们可能在代码片段的上下文中使用。
在这种情况下,是否有一种提供“后备字体”的方法?或者我如何解决这个问题,以便通过pandoc从这些markdown文件生成(Latex)PDF?
编辑:找到: ...所以我尝试了: header-includes.yaml:
---
header-includes: |
    \usepackage{combofont}
    \setupcombofont{multiscript-regular}
    {
      {file:lmsans10-regular.otf:\combodefaultfeat} at #1pt,
      {file:DejaVuSans.ttf} at #1pt,
      {file:NotoSansCJK-Regular.ttc(0)} at #1pt
    }
    {
       {} ,
       fallback,
       fallback
    }
    \DeclareFontFamily{TU}{multiscript}{}
    \DeclareFontShape {TU}{multiscript}{m}{n} {<->combo*multiscript-regular}{}
    \fontfamily{multiscript}\selectfont
...

然后我尝试了一下(注意,这里只使用了存储库中的单个文件raspi-config.md):

$ pandoc header-includes.yaml ./raspi-config.md --pdf-engine=lualatex -o result.pdf
Error producing PDF.
! Paragraph ended before \setupcombofont  was complete.
<to be read again>
\par
l.61

...所以,无法使这种方法奏效...


1
我认为你需要修复头文件包含中的换行符。尝试在每个命令之前加上“- ”,并避免在命令内部换行。 - samcarter_is_at_topanswers.xyz
1
要找到包含这些字形的字体,您可以使用神奇的 https://gitlab.com/islandoftex/albatross。 - samcarter_is_at_topanswers.xyz
感谢@samcarter_is_at_topanswers.xyz - albatross看起来很棒!我可以看出它来自与Tex用户组有关的人,我希望它已经在texlive中了,但是我找不到它...所以我尝试着自己编译它,但它是用Kotlin编写的,需要使用gradlew进行构建,而我并不是一个Java专家,所以也无法做到。否则,我将使用https://jdhao.github.io/2018/04/08/matplotlib-unicode-character/中列出的Python方法。 - sdbbs
据我所知,Albatros昨天已上传至ctan,因此它应该会在未来几天内出现在texlive中。 - samcarter_is_at_topanswers.xyz
1
@sdbbs 你不需要自己编译。在仓库页面上选择下载箭头,然后选择build:linux:jdk8构件。里面有可执行的JAR文件。如果你使用的是Windows系统,你可能想从windows-paths分支下载它,因为第一个版本没有准备好奇怪的操作系统路径 ;) - TeXnician
1个回答

2

您可以通过检查pandoc如何解析输入来了解正在发生的情况,例如将其转换回Markdown:pandoc -t native -s -t markdown -V header-includes='' header-includes.yaml

---
header-includes: |
  ```{=tex}
  \usepackage{combofont}
  \setupcombofont{multiscript-regular}
  ```
  { {file:lmsans10-regular.otf:`\combodefaultfeat`{=tex}} at \#1pt,
  {file:DejaVuSans.ttf} at \#1pt, {file:NotoSansCJK-Regular.ttc(0)} at
  \#1pt } { {} , fallback, fallback }
  `\DeclareFontFamily{TU}{multiscript}{}`{=tex}
  `\DeclareFontShape {TU}{multiscript}{m}{n}`{=tex}
  {\<-\>combo\*multiscript-regular}{}
  `\fontfamily{multiscript}`{=tex}`\selectfont`{=tex}
---

请注意,有些部分被识别为纯文本而不是TeX。通过使用原始属性语法将其强制解释为LaTeX块:

---
header-includes: |
  - ```{=latex}
    \usepackage{combofont}
    \setupcombofont{multiscript-regular}
    {
      {file:lmsans10-regular.otf:\combodefaultfeat} at #1pt,
      {file:DejaVuSans.ttf} at #1pt,
      {file:NotoSansCJK-Regular.ttc(0)} at #1pt
    }
    {
       {} ,
       fallback,
       fallback
    }
    \DeclareFontFamily{TU}{multiscript}{}
    \DeclareFontShape {TU}{multiscript}{m}{n} {<->combo*multiscript-regular}{}
    \fontfamily{multiscript}\selectfont
    ```
...

或者您可以将TeX代码片段写入文件,并通过-H选项传递该文件,这将无修改地将文件内容插入中间LaTeX文件。


只是想知道问题是否已经解决了... - Yueguoguo
@Yueguoguo 你是什么意思?这个答案是否解决了问题? - tarleb
我尝试了同样的方法,但它没有起作用。无论如何,我通过将ASCII编码的树形结构添加到Markdown文件中来绕过这个问题,这样生成的PDF看起来很好,没有问题。 - Yueguoguo

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