【问题标题】:How to handle all UNICODE characters with pylaTex?如何使用 pylaTex 处理所有 UNICODE 字符?
【发布时间】:2017-08-20 09:42:56
【问题描述】:

我有一个运行烧瓶应用程序(python 3)的网站,当我尝试生成 pdf 时出现此错误:

Traceback (most recent call last):
  File "./web/frontend/printr.py", line 204, in generate_files
  File "/env/flask3/lib/python3.5/site-packages/pylatex/document.py", line 228, in generate_pdf
    stderr=subprocess.STDOUT)
  File "/usr/lib/python3.5/subprocess.py", line 626, in check_output
    **kwargs).stdout
  File "/usr/lib/python3.5/subprocess.py", line 708, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['latexmk', '--pdf', '--interaction=nonstopmode', 'a05f271c-1a7b-4996-9533-1c8ff17a90bf.tex']' returned non-zero exit status 12

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/env/flask3/lib/python3.5/site-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "/env/flask3/lib/python3.5/site-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/env/flask3/lib/python3.5/site-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/env/flask3/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/env/flask3/lib/python3.5/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/env/flask3/lib/python3.5/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/env/flask3/lib/python3.5/site-packages/flask_login/utils.py", line 228, in decorated_view
    return func(*args, **kwargs)
  File "./web/frontend/views.py", line 690, in report
  File "./web/frontend/printr.py", line 206, in generate_files
  File "/env/flask3/lib/python3.5/site-packages/pylatex/document.py", line 228, in generate_pdf
    stderr=subprocess.STDOUT)
  File "/usr/lib/python3.5/subprocess.py", line 626, in check_output
    **kwargs).stdout
  File "/usr/lib/python3.5/subprocess.py", line 708, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['xetex', '--interaction=nonstopmode', 'a05f271c-1a7b-4996-9533-1c8ff17a90bf.tex']' returned non-zero exit status 1

代码:

try:
    doc.generate_pdf(file,clean_tex=True)
except Exception as e:
    doc.generate_pdf(file,clean=False,compiler='xetex')

选项 clean=False 转储了许多包含 *.tex 的文件,因此在服务器上使用命令行我再次尝试 (pdflatex file_name.text) e 得到特定错误:

! Package inputenc Error: Unicode char ‐ (U+2010)
(inputenc)                not set up for use with LaTeX.

检查一个解决方案here 我手动在文件中添加以下行:

\DeclareUnicodeCharacter{2010}{-}% support older LaTeX version  

并且成功了!

但是我如何使用 PYLATEX 来做到这一点? 有其他方法来处理这种情况吗?因为在我看来,设置所有不能用latex处理的UnicodeCharacter太难了。

【问题讨论】:

    标签: python-3.x unicode latex pdflatex latex-environment


    【解决方案1】:

    我修复了更改编译器的问题。 XeTeX 和 LuaTeX 将让您输入 unicode 而不会抱怨。

        if output == 'pdf':
            try:
                doc.generate_pdf(file,clean_tex=True)
            except Exception as e:
                doc.generate_pdf(file,clean=False,compiler='lualatex')
        else:
            doc.generate_tex(file)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-20
      • 2018-12-05
      • 1970-01-01
      • 2012-03-03
      • 1970-01-01
      • 2021-12-02
      • 2016-02-20
      • 2011-02-22
      相关资源
      最近更新 更多