如何解决使用 Sphinx 使用包含西里尔字符的 LaTeX 公式生成 Confluence 文档时“ascii”编解码器无法解码的错误?

问题描述 投票:0回答:1

我正在尝试为 Confluence 生成文档。源数据是包含 LaTeX 公式的 RST 文档,其中有时包含西里尔字符。

这是我的conf.py配置文件:

extensions = [
    'sphinxcontrib.confluencebuilder',
]

confluence_publish = True
confluence_space_key = 'user_space'
confluence_server_url = 'https://confluence.com'
confluence_page_hierarchy = True
confluence_page_generation_notice = True
confluence_prev_next_buttons_location = 'top'

confluence_server_user = 'login'
confluence_server_pass = 'password'
source_encoding = 'utf-8'

平台:linux; (Linux-5.15.153.1-microsoft-standard-WSL2-x86_64-with-glibc2.29)

扩展:

  • sphinx.ext.mathjax (7.1.2)
  • 雪花石膏(0.7.13)
  • sphinxcontrib.applehelp (1.0.4)
  • sphinxcontrib.devhelp (1.0.2)
  • sphinxcontrib.html帮助(2.0.1)
  • sphinxcontrib.serializinghtml (1.1.5)
  • sphinxcontrib.qthelp (1.0.3)
  • sphinxcontrib.confluencebuilder (2.5.2)

当我运行构建命令时

sphinx-build -b confluence path/to/rst tmp/path

我遇到以下回溯:

Traceback (most recent call last):
    File "/usr/local/lib/python3.8/dist-packages/sphinx/cmd/build.py", line 290, in build_main
    app.build(args.force_all, args.filenames)
    File "/usr/local/lib/python3.8/dist-packages/sphinx/application.py", line 351, in build
    self.builder.build_update()
    File "/usr/local/lib/python3.8/dist-packages/sphinx/builders/__init__.py", line 290, in build_update
    self.build(to_build,
    File "/usr/local/lib/python3.8/dist-packages/sphinx/builders/__init__.py", line 360, in build
    self.write(docnames, list(updated_docnames), method)
    File "/usr/local/lib/python3.8/dist-packages/sphinx/builders/__init__.py", line 556, in write
    self.prepare_writing(docnames)
    File "/usr/local/lib/python3.8/dist-packages/sphinxcontrib/confluencebuilder/builder.py", line 317, in prepare_writing
    self._prepare_doctree_writing(docname, doctree)
    File "/usr/local/lib/python3.8/dist-packages/sphinxcontrib/confluencebuilder/builder.py", line 399, in _prepare_doctree_writing
    doctree_transmute(self, doctree)
    File "/usr/local/lib/python3.8/dist-packages/sphinxcontrib/confluencebuilder/transmute/__init__.py", line 90, in doctree_transmute
    prepare_math_images(builder, doctree)
    File "/usr/local/lib/python3.8/dist-packages/sphinxcontrib/confluencebuilder/transmute/__init__.py", line 132, in prepare_math_images
    mf, depth = imgmath.render_math(mock_translator, node.astext())
    File "/usr/local/lib/python3.8/dist-packages/sphinx/ext/imgmath.py", line 259, in render_math
    dvipath = compile_math(latex, self.builder)
    File "/usr/local/lib/python3.8/dist-packages/sphinx/ext/imgmath.py", line 143, in compile_math
    subprocess.run(command, capture_output=True, cwd=tempdir, check=True,
    File "/usr/lib/python3.8/subprocess.py", line 495, in run
    stdout, stderr = process.communicate(input, timeout=timeout)
    File "/usr/lib/python3.8/subprocess.py", line 1028, in communicate
    stdout, stderr = self._communicate(input, endtime, timeout)
    File "/usr/lib/python3.8/subprocess.py", line 1906, in _communicate
    stdout = self._translate_newlines(stdout,
    File "/usr/lib/python3.8/subprocess.py", line 905, in _translate_newlines
    data = data.decode(encoding, errors)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 1403: ordinal not in range(128)

当从包含带有西里尔字符的 LaTeX 公式的 RST 文件生成 Confluence 文档时,我该如何解决 Sphinx 构建过程中的“ascii”编解码器无法解码错误?

python linux latex python-sphinx confluence
1个回答
0
投票

我的解决方案是

我将此代码添加到我的conf.py中

confluence_latex_macro = {
    'block-macro': 'mathblock',
    'inline-macro': 'mathinline',
    'inline-macro-param': 'body',
}

链接:https://sphinxcontrib-confluencebuilder.readthedocs.io/en/latest/guide-math/

© www.soinside.com 2019 - 2024. All rights reserved.