for trans_tuple in translate1:
# pat, debug
print "replacing " + trans_tuple[0]
text = re.sub(trans_tuple[0], trans_tuple[1], text)
print "done"
translate1 = [
( '<!--[^<!--]*-->' , r'' ),
( '→' , r'\\rightarrow' ),
( '-->' , r'\\longrightarrow' ),
# pat: => could come in the document
# ( '=>' , r'\\Rightarrow' ),
( '==>' , r'\\Longrightarrow' ),
( '<--' , "\\longleftarrow" ),
( '<-' , "\\leftarrow" ),
( '<==' , "\\Longleftarrow" ),
# pat: <= could come in the document (smaller and equal)
# ( '<=' , "\\Leftarrow" ),
( "(?s)<!--.*?-->" , '' ),
( '\[\[[a-z]{2,6}(?:-..)?:.*?\]\]' , '' ), # delete links to other languages
( '{{.*?}}' , '' ), # delete {{VARIABLES}} and {{Templates}}
( '__[A-Z]+__' , '' ),
#JM : due to the modification on the words with an '_'
( '\_\_[A-Z]+\_\_' , '' ),
# ( '(?m)^ (.*?)$' , pre_formatted ),
( '\n----+' , "\\\\vspace{2mm}\n\\hline\n" ),
( '<hr>' , "\\\\vspace{2mm}\n\\hline\n" ),
( '&' , r'\&' ),
# ( '\^' , r'\^{}' ),
( 'tableand' , r'&' ),
( "\\$" , r'\$' ),
# ( 'latexmath' , r'$' ),
( '(?s)<code>(.*?)</code>' , r'\\verb| \1 |' ),
( '(?s)<nowiki>(.*?)</nowiki>' , r'\\verb| \1 |' ),
( '§' , r'\\S'),
( '(?s)<pre>(.*?)</pre>' , r'\\fbox{\parbox{\pagewidth}{\1}}' ),
( '(?s)<blockquote>(.*?)</blockquote>' , r'\\begin{quotation}\emph{\1}\end{quotation}' ),
( '(?s)<ref>(.*?)</ref>' , r'\\begin{quotation}\1\end{quotation}' ),
( '(?s)<includeonly>(.*?)</includeonly>',r'' ),
( '(?s)<noinclude>(.*?)</noinclude>',r' ' ),
( '<br.*?>' , r'\\newline{}' ), # \\ doesn't work inside tables
# ( '^' , '^' ),
( '</?div.*>' , '' ),
( "''' *(.+?) *'''" , r'\\textbf{\1}' ),
( "'' *(.+?) *''" , r'\\textit{\1}' ),
( "(?m)^====+ *(.+?) *====+" , r'\\subsubsection{\1}' ),
( "(?m)^=== *(.+?) *===" , r'\\subsubsection{\1}' ),
( "(?m)^== *(.+?) *==" , r'\\subsection{\1}' ),
( "(?m)^= *(.+?) *=" , r'\\section{\1}' ),
( "\"(.*?)\"" , config_begindoublequote[ code ] + r'\1' + config_enddoublequote[ code ] ),
( r'(?<!\[)(http://.+?)(?=[ $\n\)])' , ExternalURL2 ),
( "\\[(http://|ftp://|mailto:)(.+?)(?: +([^\\]]+))?\\]" , ExternalURL ),
( '(?s)<sub>(.*?)</sub>' , r'$_{\\textrm{\\scriptsize \1}}$' ),
( '(?s)<sup>(.*?)</sup>' , r'$^{\\textrm{\\scriptsize \1}}$' ),
( '(?s)<center>(.*?)</center>' , r'{\\centering \1 \\\\}' ),
( '(?s)<s>(.*?)</s>' , r'{\\sout{\1}' ),
( '(?s)<u>(.*?)</u>' , r'{\\uline{\1}' ),
( '(?s)<tt>(.*?)</tt>' , r'{\\texttt{\1}' ),
( '(?s)<small>(.*?)</small>' , r'{\\small{\1}' ),
( '~' , r'{\\textasciitilde}' ),
( r'%' , r'\%' ),
( "\[\[([^\|]+?)\]\]" , WikiURL1 ),
( "\[\[([^\|]+?)\|([^\|]+?)\]\]", WikiURL2 ),
]