I need to create latex formatted tables from python code. I save the tabulate returning string to a .tex file and direct include them to a parent .tex file (with the appropriated packages).
Thus, this procedure does not compile without a change in the string format.
I solve this issue using regex to replace unwanted characters:
def convert2LatexString(s):
r = r'(\^\{\})'; s = re.sub(r, "^", s)
s = re.sub(r'\\([\$\_\{\}\^])', r'\1', s)
s = re.sub(r'(\\textbackslash{})', r'\\', s)
return s
I need to create latex formatted tables from python code. I save the tabulate returning string to a
.tex
file and direct include them to a parent.tex
file (with the appropriated packages).Result:
Thus, this procedure does not compile without a change in the string format.
I solve this issue using regex to replace unwanted characters:
Converted string:
This converted string I can save and direct include via
\include{filename.tex}
in my parent.tex
file.My question is if there is a more robust approach to get the appropriated formatted latex string, since I am not an expert on python/string handling.
Thank you