Attached is a patch for lyxpreview_tools.py, but I don't know Python
well and I don't know how to test whether this code works as intended
now or not. All I know is it gets rid of the error.

I originally saw that error on master when opening the User Guide with
Preview enabled.

Can someone give the patch a check?

Best,

Scott
From b3e30d0f2c21d195415e7d44fbf7b9d17d084c52 Mon Sep 17 00:00:00 2001
From: Scott Kostyshak <[email protected]>
Date: Sat, 15 Feb 2020 13:27:45 -0500
Subject: [PATCH] lyxpreview_tools.py: fix a regular expression

Three backslashes are needed before a LaTeX command, not one. Before
this commit, the code gave the following error with Python >= 3.6:

  re.error: bad escape \g at position 29

This error was introduced with Python 3.6, as documented [1] by the
following line of documentation:

  Changed in version 3.6: Unknown escapes in pattern consisting of
  '\' and an ASCII letter now are errors.

Although previous Python versions did not give an error, the regular
expression was not working as intended: for example, the "\\n" in
"\\newcommandx" would be interpreted as a new line.

[1] https://docs.python.org/3.6/library/re.html#re.sub
---
 lib/scripts/lyxpreview_tools.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/scripts/lyxpreview_tools.py b/lib/scripts/lyxpreview_tools.py
index 05c5aad616..93964083a5 100644
--- a/lib/scripts/lyxpreview_tools.py
+++ b/lib/scripts/lyxpreview_tools.py
@@ -219,7 +219,7 @@ def write_metrics_info(metrics_info, metrics_file):
 # Reads a .tex files and create an identical file but only with
 # pages whose index is in pages_to_keep
 def filter_pages(source_path, destination_path, pages_to_keep):
-    def_re = re.compile(b"(\\newcommandx|\\renewcommandx|\\global\\long\\def)(\\[a-zA-Z]+)(.+)")
+    def_re = re.compile(b"(\\\\newcommandx|\\\\renewcommandx|\\\\global\\\\long\\\\def)(\\[a-zA-Z]+)(.+)")
     source_file = open(source_path, "rb")
     destination_file = open(destination_path, "wb")
 
-- 
2.20.1

Attachment: signature.asc
Description: PGP signature

-- 
lyx-devel mailing list
[email protected]
http://lists.lyx.org/mailman/listinfo/lyx-devel

Reply via email to