首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用pylaTex处理所有UNICODE字符?

如何使用pylaTex处理所有UNICODE字符?
EN

Stack Overflow用户
提问于 2017-08-20 09:42:56
回答 1查看 632关注 0票数 1

我有一个网站运行一个烧瓶应用程序(python 3),当我试图生成一个pdf时,我得到了以下错误:

代码语言:javascript
复制
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

守则:

代码语言:javascript
复制
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)获得了特定的错误:

代码语言:javascript
复制
! Package inputenc Error: Unicode char ‐ (U+2010)
(inputenc)                not set up for use with LaTeX.

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

代码语言:javascript
复制
\DeclareUnicodeCharacter{2010}{-}% support older LaTeX version  

而且起作用了!

,但是我如何使用PYLATEX?来处理这种情况呢?因为在我看来,设置所有无法用乳胶处理的UnicodeCharacter太难了。

EN

回答 1

Stack Overflow用户

发布于 2017-09-02 04:16:51

我修正了修改编译器。XeTeX和LuaTeX将允许您输入unicode,而无需抱怨。

代码语言:javascript
复制
    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)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45780722

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档