|
@ -10,8 +10,6 @@ from .context import Group |
|
|
from .output_generator import OutputGenerator |
|
|
from .output_generator import OutputGenerator |
|
|
from .images import ImageProcessor |
|
|
from .images import ImageProcessor |
|
|
|
|
|
|
|
|
import re |
|
|
|
|
|
|
|
|
|
|
|
class LaTeXGenerator(OutputGenerator): |
|
|
class LaTeXGenerator(OutputGenerator): |
|
|
def __init__(self, output_file, imageProcessor: ImageProcessor, *args, **kwargs): |
|
|
def __init__(self, output_file, imageProcessor: ImageProcessor, *args, **kwargs): |
|
|
self.imageProcessor = imageProcessor |
|
|
self.imageProcessor = imageProcessor |
|
@ -23,17 +21,17 @@ class LaTeXGenerator(OutputGenerator): |
|
|
super().generate(e) |
|
|
super().generate(e) |
|
|
|
|
|
|
|
|
def escape_special_chars(self, text: str) -> str: |
|
|
def escape_special_chars(self, text: str) -> str: |
|
|
text = re.sub(re.compile(r"&"), "\\&", text) |
|
|
text = text.replace("&", "\\&") |
|
|
text = re.sub(re.compile(r"%"), "\\%", text) |
|
|
text = text.replace("%", "\\%") |
|
|
text = re.sub(re.compile(r"\$"), "\\$", text) |
|
|
text = text.replace("$", "\\$") |
|
|
text = re.sub(re.compile(r"#"), "\\#", text) |
|
|
text = text.replace("#", "\\#") |
|
|
text = re.sub(re.compile(r"_"), "\\_", text) |
|
|
text = text.replace("_", "\\_") |
|
|
text = re.sub(re.compile(r"\{"), "\\{", text) |
|
|
text = text.replace("{", "\\{") |
|
|
text = re.sub(re.compile(r"\}"), "\\}", text) |
|
|
text = text.replace("}", "\\}") |
|
|
text = re.sub(re.compile(r"~"), "\\textasciitilde{}", text) |
|
|
text = text.replace("~", "\\textasciitilde{}") |
|
|
text = re.sub(re.compile(r"\^"), "\\textasciicircum{}", text) |
|
|
text = text.replace("^", "\\textasciicircum{}") |
|
|
text = re.sub(re.compile(r"\\"), "\\textbackslash{}", text) |
|
|
text = text.replace("\\", "\\textbackslash{}") |
|
|
text = re.sub(re.compile(r" "), "~", text) # We use unicode no-break spaces to force nbsp in output |
|
|
text = text.replace(" ", "~") # We use unicode no-break spaces to force nbsp in output |
|
|
return text |
|
|
return text |
|
|
|
|
|
|
|
|
def stag(self, tag: str, attributes: Dict[str,str]={}) -> str: |
|
|
def stag(self, tag: str, attributes: Dict[str,str]={}) -> str: |
|
|