Fix escape do TeXu
This commit is contained in:
parent
bf46105db8
commit
7230d87f6b
1 changed files with 19 additions and 13 deletions
|
@ -27,19 +27,25 @@ class UCWTexGenerator(OutputGenerator):
|
|||
super().__init__(output_file, *args, **kwargs)
|
||||
|
||||
def escape_special_chars(self, text: str) -> str:
|
||||
text = text.replace("&", r"\&")
|
||||
text = text.replace("%", r"\%")
|
||||
text = text.replace("$", r"\$")
|
||||
text = text.replace("#", r"\#")
|
||||
text = text.replace("_", r"\_")
|
||||
text = text.replace("{", r"\{")
|
||||
text = text.replace("}", r"\}")
|
||||
text = text.replace("~", r"\textasciitilde{}")
|
||||
text = text.replace("^", r"\textasciicircum{}")
|
||||
text = text.replace("\\", r"\textbackslash{}")
|
||||
text = text.replace(" ", "~") # We use unicode no-break spaces to force nbsp in output
|
||||
text = text.replace("", "")
|
||||
return text
|
||||
if '\\' in text:
|
||||
print("ESCAPE", text)
|
||||
out = ""
|
||||
for char in text:
|
||||
out += {
|
||||
'&': r"\&",
|
||||
'%': r"\%",
|
||||
'$': r"\$",
|
||||
'#': r"\#",
|
||||
'_': r"\_",
|
||||
'{': r"\{",
|
||||
'}': r"\}",
|
||||
'~': r"\textasciitilde{}",
|
||||
'^': r"\textasciicircum{}",
|
||||
'\\': r"\textbackslash{}",
|
||||
' ': r"~",
|
||||
'': r"",
|
||||
}.get(char, char)
|
||||
return out
|
||||
|
||||
def generate(self, e: Union[Element, ListContainer]):
|
||||
if hasattr(e, "attributes") and "only" in e.attributes and e.attributes["only"] != "tex":
|
||||
|
|
Loading…
Reference in a new issue