Code Monkey home page Code Monkey logo

Comments (3)

gpoore avatar gpoore commented on August 19, 2024

The fact that you're getting a Python error means that things are going wrong in Pygments. That may or may not indicate that this is a Pygments issue, though.

minted is running pygmentize, and somewhere between LaTeX and Pygments there are character encoding issues. The first thing you need to try is downloading the latest minted.sty (v2.0alpha2), and using encoding=utf8 (or whatever is appropriate for your file) as the first optional argument for the minted environment. (You can just put the new minted.sty in the same directory as your document for testing purposes.)

If that doesn't work, there may be system encoding issues. Can you type/paste these Chinese characters into the terminal? What is your terminal's encoding? (One way to get that is to open a terminal, start Python, and then type import sys; sys.stdout.encoding.)

It's possible that even if all that is fine, pygmentize won't accept anything but ASCII from the command line. This Pygments issue suggests that that may indeed be the case. If that's the cause of the problem, then this is a Pygments issue.

If possible, you could also try all of this with Python 3.2+.

One workaround is to put your label in a macro, say \newcommand{\mylabel}{main函数}, and then in the minted optional argument use label=\mylabel.

from minted.

ssendeavour avatar ssendeavour commented on August 19, 2024

thanks for your quick response.

I have solved my problem with your suggestion.

  1. I first tried lastest minted.sty(v2.0alpha2) and using encoding=utf8 as first argument, do not work.
  2. My terminal's encoding is UTF8, and environment variable LANG=en_US.UTF8. it can copy/paste Chinese.
  3. your workaround works.
  4. Use python3 works, but have to use encoding=utf8 as first optional argument to minted environment to get it work. I removed python-pygments installed from Ubuntu repository, and installed python3, download Pygments-1.6.tar.gz from pypi.python.org, extract and install it with sudo python3 setup.py install. This way python remain linked to python2.7 and I can use pygmentize with python3 (the first line of /usr/local/bin/pygmentize set to #!/usr/bin/python3).

also have to use latest minted.sty(v2.0alpha2). minted 1.7 do not work, get error

! Package keyval Error: encoding undefined.

See the keyval package documentation for explanation.
Type H for immediate help.

from minted.

gpoore avatar gpoore commented on August 19, 2024

Thanks for the nice summary. It looks like the Pygments issue I referenced is responsible for the problem under Python 2.7.

minted 1.7 won't work because it doesn't support the encoding option; only the latest versions of minted support it.

I am closing this issue since the only existing issue is on the Pygments side. I will also add a note in the documentation for the next release about this use case.

from minted.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.