From 6495cd135f15c3775613c79b008ad62f6726573e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Matos?= Date: Tue, 9 May 2017 16:53:32 +0100 Subject: [PATCH] make python string compliant with python 2 and 3 python 2 does not allow to declare a string as raw byte so we double the backslashes and remove the r preffix python 3 accepts rb"..." meaning a byte string that is raw. In this context raw means that the backslash does not has any special meaning and thus it is not escaped. This is usefull together with regular expressions where the backslashes are special. In the worst possible case, like this one, we must use 4 backslashes to represent one in the regular expression... --- lib/scripts/lyxpreview2bitmap.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/scripts/lyxpreview2bitmap.py b/lib/scripts/lyxpreview2bitmap.py index 68d0a4d37b..094e8f915b 100755 --- a/lib/scripts/lyxpreview2bitmap.py +++ b/lib/scripts/lyxpreview2bitmap.py @@ -161,7 +161,9 @@ def extract_metrics_info(dvipng_stdout): def fix_latex_file(latex_file, pdf_output): - def_re = re.compile(rb"(\\newcommandx|\\global\\long\\def)(\\[a-zA-Z]+)") + # python 2 does not allow to declare a string as raw byte so we double + # the backslashes and remove the r preffix + def_re = re.compile(rb"(\\\\newcommandx|\\\\global\\\\long\\\\def)(\\\\[a-zA-Z]+)") tmp = mkstemp() -- 2.39.5