olivierverdier / python-latex-highlighting

LaTeX style for Python highlighting
BSD 3-Clause "New" or "Revised" License
453 stars 125 forks source link

How do you render special utf 8 characters in it? #13

Closed ghost closed 5 months ago

ghost commented 3 years ago

It won't render a µ

\documentclass[a4paper,12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{pythonhighlight}

\begin{document}
\begin{python}
µ = 5
\end{python}
\end{document}

Package inputenc Error: Invalid UTF-8 byte "B5.

Tremeschin commented 3 years ago

I managed to achieve this but using other package, looks like this repo here isn't really unicode friendly (so does latex by nature in my experience, actually the listings package it uses), pythonhighlight might work amazing for English written tex files, will definitely use it in the future, but I have to write one in Portuguese as of right now.

I'm using minted now successfully, including my python files this way, the problem I had in the past is that I didn't read the log and knew it needed --shell-escape flag for Linux, which for the coding environment I use (VSCodium / VSCode) I found instructions here for the LaTeX workshop extension on adding this argument.

Just be sure to have python and python-pygments installed and available on PATH otherwise minted might do nothing.

I did try modifying this repo's .sty file by looking here first for any clues where to start, then found this for Portuguese languages (and some other special chars people commented).. but no luck making this package to work using listings package.

Also I have absolutely no experience writing tex extensions previous than this, could also be texlive/xelatex/pdflatex troubles as well (AFAIK they are the "compiler, final rendered, the one that processes the files").

I tried :( also I'm a few months late on answering this lol

olivierverdier commented 5 months ago

Using XeLaTeX compiles the code without any issue.

Tremeschin commented 5 months ago

Oh this is old, I've moved to Tectonic long ago and I don't have to think of nuances anymore, it just works

olivierverdier commented 5 months ago

Tectonic seems to be using XeLaTeX, which solves many problems indeed.