Pyx unicode text
<p>So I am trying to generate postscript from Python.
Currently trying with PyX 0.14.1 on Python3.4.2,
but I am open to suggestions, if you know something simpler.</p>

<p>I was following mostly the suggestions found on the PyX
mailing list in <a href="https://sourceforge.net/p/pyx/mailman/message/3224499/" rel="nofollow noreferrer">this thread</a>. This was Python2 and is quite old.
The following shows my current code after many changes:</p>

<pre><code>from pyx import *

text.set(cls=text.LatexRunner, texenc='utf-8')
text.preamble(r'\usepackage{ucs}')
text.preamble(r'\usepackage[utf8x]{inputenc}')

c = canvas.canvas()
c.text(5, 5, "Sören Sundstrøm".encode("utf8"))

p = document.page(c, paperformat=document.paperformat.A4,
    centered=0)
d = document.document([p])
d.writePSfile('test.ps')
</code></pre>

<p>PyX stops with a TexResultError. The interesting part of the error
shows what's happening in TeX:</p>

<pre><code>pyx.text.TexResultError: unhandled TeX response (might be an error)
The expression passed to TeX was:
  \ProcessPyXBox{b'S\xc3\xb6ren Sundstr\xc3\xb8m'%
  }{1}%
  \PyXInput{7}%
After parsing the return message from TeX, the following was left:
  *
  *! Undefined control sequence.
  &lt;argument&gt; b'S\xc 
                    3\xb 6ren Sundstr\xc 3\xb 8m'
  &lt;*&gt; }{1}
  (cut after 5 lines; use errordetail.full for all output)
</code></pre>

<p>So it looks like latex is receiving not utf-8,
but an escaped representation of utf-8.
My question: How do I pass the string to canvas.text correctly?
Or is my preamble wrong?</p>

<p>I also tried to follow <a href="https://stackoverflow.com/questions/26481965/inserting-a-unicode-text-into-pyx-canvas">this answer by wobsta</a> here on SO,
but besides being much too complicated, it does not work for me either.
(Looks like PyX does not understand a metafont message in this case).</p>

<p>Running latex directly on a simple utf-8 input file with the same preamble
works fine by the way.</p>