jterrace / sphinxtr

The Sphinx Thesis Resource
http://jterrace.github.com/sphinxtr
Other
153 stars 50 forks source link

ext/latex_mods: Fix TypeError for alt tags #15

Closed erikbgithub closed 10 years ago

erikbgithub commented 10 years ago

When not using alt tags on figures, latex_mods.py failed with a TypeError. The problem was, that the strings are not necessarily unicode, but the escape_map used only works with unicodes.

Fixes #12

Signed-off-by: Erik Bernoth erik.bernoth@gmail.com

erikbgithub commented 10 years ago

How I got there:

>>> from sphinx.util.texescape import tex_escape_map
>>> ''.translate(tex_escape_map)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: expected a character buffer object
>>> 'a'.translate(tex_escape_map)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: expected a character buffer object
>>> 'abcdef'.translate(tex_escape_map)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: expected a character buffer object
>>> 
>>> 
>>>
>>> u''.translate(tex_escape_map)
u''
>>> u'abcd'.translate(tex_escape_map)
u'abcd'
>>> unicode('').translate(tex_escape_map)
u''

The idea for unicode() came up when I saw that tex_escape_map contained values much bigger then 256.

jterrace commented 10 years ago

thanks!