Python: Latex symbols to unicode?
I have fond several answers hinting how to solve unicode to latex symbols conversion. For example turning u'á'
into \'{a}
.
Well I need it the other way around! So I made some research and fond this dictionary. Since the mapping seems to be bijective, I thought of turning the dictionary the other 开发者_开发百科way around. But I can't figure out how to "use" the keys in this dictionary:
u"\u0020": "\\space ",
u"\u0023": "\\#",
u"\u0024": "\\textdollar ",
u"\u0025": "\\%",
How can I turn them inside python to "human readable characters"? Is there mayhaps a better and more complete was to achieve my goal?
The notation u'\u0020'
is just an escape sequence that specifies the space character, only it does so by specifying it by character code. The author of the dictionary probably did it this way so that it would be obvious if something was missing, but you don't need to perform any special conversion to use the dictionary, since u'\u0020' == ' '
.
... What?
>>> print {u'\u0020': '\\space'}[u' ']
\space
(That is, they're already characters; you need do nothing to them.)
精彩评论