def encode(self, text): text = CustomLaTeXTranslator.encode(self, text) if not isinstance(text, unicode): decoded = True text = text.decode('utf-8') else: decoded = False text = text.replace(u"”", u"''") \ .replace(u"“", u"``") \ .replace(u"–", u"--") \ .replace(u"’", u"'") if decoded: text = text.encode('utf-8') return text