]> git.lyx.org Git - features.git/commitdiff
lyxpreview_tools.py: fix a regular expression
authorScott Kostyshak <skostysh@lyx.org>
Sat, 15 Feb 2020 18:27:45 +0000 (13:27 -0500)
committerScott Kostyshak <skostysh@lyx.org>
Sun, 16 Feb 2020 02:57:30 +0000 (21:57 -0500)
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

index 05c5aad6163467df62ed76768ccd8fc3ce2418cc..93964083a5d8f604ea0b2f7586b409fe199d71aa 100644 (file)
@@ -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")