# Embedding a literal "\u" in a unicode raw string.

OKB (not okblacke) brenNOSPAMbarn at NObrenSPAMbarn.net
Mon Feb 25 18:03:53 CET 2008

```Romano Giannetti wrote:

> Hi,
>
> while writing some LaTeX preprocessing code, I stumbled into this
> problem: (I have a -*- coding: utf-8 -*- line, obviously)
>
>
> Which gave an error because the \u escape is interpreted in raw
> unicode strings, too. So I found that the only way to solve this is
> to write:
>
> s = unicode(r"aÃ±ado \$\uparrow\$", "utf-8")
>
> or
>
>
> The second one is too ugly to live, while the first is at least
> acceptable; but looking around the Python 3.0 doc, I saw that the
> first one will fail, too.
>
> Am I doing something wrong here or there is another solution for
> this?

I too encountered this problem, in the same situation (making
strings that contain LaTeX commands).  One possibility is to separate
out just the bit that has the \u, and use string juxtaposition to attach
it to the others:

It's not ideal, but I think it's easier to read than your solution
#2.

--
--OKB (not okblacke)
Brendan Barnwell