max-heller / mdbook-pandoc

A mdbook backend powered by Pandoc.
Apache License 2.0
97 stars 7 forks source link

! LaTeX Error: Unicode character 中 (U+4E2D) not set up for use with LaTeX. #94

Closed deerchao closed 3 months ago

deerchao commented 3 months ago

With the first non-ascii char in my book.toml, there comes an error:

[book]
title = "中文"

[output.pandoc.profile.pdf]
output-file = "output.pdf"
to = "latex"

and this is the log:

2024-06-06 18:19:37 [INFO] (mdbook::book): Book building has started
2024-06-06 18:19:37 [INFO] (mdbook::book): Running the pandoc backend
2024-06-06 18:19:37 [INFO] (mdbook::renderer): Invoking the "pandoc" renderer
Error producing PDF.
! LaTeX Error: Unicode character 中 (U+4E2D)
               not set up for use with LaTeX.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...

l.98

pandoc exited unsuccessfully
2024-06-06 18:19:39 [ERROR] (mdbook::renderer): Renderer exited with non-zero return code.
2024-06-06 18:19:39 [ERROR] (mdbook::utils): Error: Rendering failed
2024-06-06 18:19:39 [ERROR] (mdbook::utils):    Caused By: The "pandoc" renderer failed
max-heller commented 3 months ago

The default LaTeX renderer, pdflatex, cannot handle general unicode characters. You can use a different one such as LuaLaTex or XeLaTex to get better support, and you'll need to use fonts that support the necessary characters as well. Here's an example configuration from the test suite that should be enough to get started:

https://github.com/max-heller/mdbook-pandoc/blob/a4c27032fba8b3b0d56cd81659a0e983c8bb51c8/src/lib.rs#L501-L520

Note the font configuration to use Noto CJK SC (Simplified Chinese), this is likely the main font you'll need. See also the section on fonts in Pandoc's manual.

Closing since this is really a LaTeX configuration question but let me know if there's anything else I can do to help.