How can I escape LaTeX special characters inside django templates?

后端 未结 2 1782
无人共我
无人共我 2020-12-31 07:09

I have this django template which I use to generate LaTeX files

\\documentclass[11pt]{report}

\\begin{document}
\\begin{table}
    \\centering
    \\begin{t         


        
2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-31 07:38

    Something like this should do:

    CHARS = {
        '&':  r'\&',
        '%':  r'\%', 
        '$':  r'\$', 
        '#':  r'\#', 
        '_':  r'\letterunderscore{}', 
        '{':  r'\letteropenbrace{}', 
        '}':  r'\letterclosebrace{}',
        '~':  r'\lettertilde{}', 
        '^':  r'\letterhat{}', 
        '\\': r'\letterbackslash{}',
    }
    
    print("".join([CHARS.get(char, char) for char in "&%$#_{}~^\\"]))
    

    Create you own template filter to filter your variables

    [edit]:

    This was the special characters for ConText, for LaTex, adapt with:

    \& \% \$ \# \_ \{ \} \textasciitilde{} \^{} \textbackslash{}
    

提交回复
热议问题