Repository: phfaist/pylatexenc

Issue:
ur"Expected exactly (...)" string gives SyntaxError: invalid syntax
Got syntax error when importing ```pylatexenc.latex2text``` module (Python 3.6, Mac, Anaconda3 distrubution):

```
import pylatexenc.latex2text

  File "/Users/rasmus/anaconda/envs/tts/lib/python3.6/site-packages/pylatexenc/latex2text.py", line 501
    logger.warning(ur"Expected exactly one argument for '\input' ! Got = %r", n.nodeargs)
                                                                           ^
SyntaxError: invalid syntax
```

Python 3.5+ does not support `ur` prefix. To fix, use either `u` or `r` string but not both.

Comments:

Patch:
diff --git a/pylatexenc/latex2text.py b/pylatexenc/latex2text.py
index 874ae8d..da2694e 100644
--- a/pylatexenc/latex2text.py
+++ b/pylatexenc/latex2text.py
@@ -23,11 +23,17 @@
 #
 
 
+from __future__ import print_function, absolute_import
 import os
 import re
 import unicodedata
-import latexwalker
 import logging
+import sys
+if sys.version_info.major > 2:
+    def unicode(string): return string
+    basestring = str
+
+from pylatexenc import latexwalker
 
 
 logger = logging.getLogger(__name__);
@@ -498,7 +504,7 @@ class LatexNodes2Text(object):
         #
         
         if (len(n.nodeargs) != 1):
-            logger.warning(ur"Expected exactly one argument for '\input' ! Got = %r", n.nodeargs)
+            logger.warning(u"Expected exactly one argument for '\\input' ! Got = %r", n.nodeargs)
 
         inputtex = self.read_input_file(self.nodelist_to_text([n.nodeargs[0]]).strip())
 
@@ -663,17 +669,17 @@ if __name__ == '__main__':
 
         import fileinput
 
-        print "Please type some latex text (Ctrl+D twice to stop) ..."
+        print("Please type some latex text (Ctrl+D twice to stop) ...")
 
         latex = ''
         for line in fileinput.input():
             latex += line;
 
 
-        print '\n--- WORDS ---\n'
-        print latex2text(latex.decode('utf-8')#, keep_inline_math=True
-                         ).encode('utf-8')
-        print '\n-------------\n'
+        print('\n--- WORDS ---\n')
+        print(latex2text(latex.decode('utf-8')#, keep_inline_math=True
+                         ).encode('utf-8'))
+        print('\n-------------\n')
 
     except:
         import pdb;
@@ -681,8 +687,8 @@ if __name__ == '__main__':
         import sys;
         (exc_type, exc_value, exc_traceback) = sys.exc_info()
         
-        print "\nEXCEPTION: " + unicode(sys.exc_value) + "\n"
-        
+        print("\nEXCEPTION: " + unicode(sys.exc_info()[1]) + "\n")
+
         pdb.post_mortem()
 
 
diff --git a/pylatexenc/latexencode.py b/pylatexenc/latexencode.py
index 0b54878..98b87fb 100644
--- a/pylatexenc/latexencode.py
+++ b/pylatexenc/latexencode.py
@@ -24,8 +24,13 @@
 #
 
 
+from __future__ import print_function, absolute_import
 import unicodedata;
 import logging
+import sys
+if sys.version_info.major > 2:
+    def unicode(string): return string
+    basestring = str
 
 log = logging.getLogger(__name__)
 
@@ -873,20 +878,20 @@ if __name__ == '__main__':
 
         import fileinput
 
-        print "Please type some unicode text (Ctrl+D twice to stop) ..."
+        print("Please type some unicode text (Ctrl+D twice to stop) ...")
 
         latex = ''
         for line in fileinput.input():
             latex += line;
 
-        print '\n--- LATEX ---\n'
-        print utf8tolatex(latex.decode('utf-8')).encode('utf-8')
-        print '\n-------------\n'
+        print('\n--- LATEX ---\n')
+        print(utf8tolatex(latex.decode('utf-8')).encode('utf-8'))
+        print('\n-------------\n')
 
     except:
         import pdb;
         import sys;
-        print "\nEXCEPTION: " + unicode(sys.exc_info()[1]) + "\n"
+        print("\nEXCEPTION: " + unicode(sys.exc_info()[1]) + "\n")
         pdb.post_mortem()
 
 
diff --git a/pylatexenc/latexwalker.py b/pylatexenc/latexwalker.py
index eef3e4b..7fcbe3f 100644
--- a/pylatexenc/latexwalker.py
+++ b/pylatexenc/latexwalker.py
@@ -23,12 +23,16 @@
 #
 
 
+from __future__ import print_function, absolute_import
 import logging
 logger = logging.getLogger(__name__)
 
 import re
 from collections import namedtuple
-
+import sys
+if sys.version_info.major > 2:
+    def unicode(string): return string
+    basestring = str
 
 
 class LatexWalkerError(Exception):
@@ -1223,9 +1227,9 @@ def disp_node(n, indent=0, context='* ', skip_group=False):
         title = '\\begin{%s}' %(n.envname)
         iterchildren.append(('* ', n.nodelist, False));
     else:
-        print "UNKNOWN NODE TYPE: %s"%(n.nodeType().__name__)
+        print("UNKNOWN NODE TYPE: %s"%(n.nodeType().__name__))
 
-    print ' '*indent + context + title + '  '+comment
+    print(' '*indent + context + title + '  '+comment)
 
     for context, nodelist, skip in iterchildren:
         for nn in nodelist:
@@ -1252,18 +1256,18 @@ if __name__ == '__main__':
 
         (nodes, pos, llen) = get_latex_nodes(latex);
 
-        print '\n--- NODES ---\n'
-        print repr(nodes);
-        print '\n-------------\n'
+        print('\n--- NODES ---\n')
+        print(repr(nodes))
+        print('\n-------------\n')
 
-        print '\n--- NODES ---\n'
+        print('\n--- NODES ---\n')
         for n in nodes:
             disp_node(n)
-        print '\n-------------\n'
+        print('\n-------------\n')
 
     except:
         import pdb;
         import sys;
-        print "\nEXCEPTION: " + unicode(sys.exc_info()[1]) + "\n"
+        print("\nEXCEPTION: " + unicode(sys.exc_info()[1]) + "\n")
         pdb.post_mortem()
 


Test patch:
diff --git a/test/test_latexwalker.py b/test/test_latexwalker.py
index 5acf7d3..2be6f0f 100644
--- a/test/test_latexwalker.py
+++ b/test/test_latexwalker.py
@@ -1,4 +1,8 @@
 import unittest
+import sys
+if sys.version_info.major > 2:
+    def unicode(string): return string
+    basestring = str
 
 from pylatexenc.latexwalker import (
     MacrosDef, LatexWalker, LatexToken, LatexCharsNode, LatexGroupNode, LatexCommentNode,