]> git.lyx.org Git - features.git/commitdiff
Fix another couple of issues spotted by Guillaume
authorEnrico Forestieri <forenr@lyx.org>
Sat, 20 Jun 2015 14:37:12 +0000 (16:37 +0200)
committerEnrico Forestieri <forenr@lyx.org>
Sat, 20 Jun 2015 14:37:12 +0000 (16:37 +0200)
* Take into account macro redefinitions in the legacy route
* Take into account macros inside nested macro definitions

lib/scripts/lyxpreview_tools.py
src/mathed/InsetMathHull.cpp

index 6766b5f08dcb85076aeac98d0f4c0cebcd399d96..de2e5c5762cc98942560bf483206a4ac4d45e4af 100644 (file)
@@ -272,11 +272,13 @@ 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(r"(\\newcommandx|\\renewcommandx|\\global\\long\\def)(\\[a-zA-Z]+)(.+)")
     source_file = open(source_path, "r")
     destination_file = open(destination_path, "w")
 
     page_index = 0
     skip_page = False
+    macros = []
     for line in source_file:
         # We found a new page
         if line.startswith("\\begin{preview}"):
@@ -285,6 +287,14 @@ def filter_pages(source_path, destination_path, pages_to_keep):
             skip_page = page_index not in pages_to_keep
 
         if not skip_page:
+            match = def_re.match(line)
+            if match != None:
+                definecmd = match.group(1)
+                macroname = match.group(2)
+                if not macroname in macros:
+                    macros.append(macroname)
+                    if definecmd == "\\renewcommandx":
+                        line = line.replace(definecmd, "\\newcommandx")
             destination_file.write(line)
 
         # End of a page, we reset the skip_page bool
index e1e339dacb70ead10c1c5a7d545e374e7a272721..d8850e835ec339e832355a20e6e29c4c640790ee 100644 (file)
@@ -37,6 +37,7 @@
 #include "LyXRC.h"
 #include "MacroTable.h"
 #include "MathMacro.h"
+#include "MathMacroTemplate.h"
 #include "output_xhtml.h"
 #include "Paragraph.h"
 #include "ParIterator.h"
@@ -635,6 +636,7 @@ void InsetMathHull::usedMacros(MathData const & md, DocIterator const & pos,
 
        for (size_t i = 0; i < md.size(); ++i) {
                MathMacro const * mi = md[i].nucleus()->asMacro();
+               MathMacroTemplate const * mt = md[i].nucleus()->asMacroTemplate();
                InsetMathScript const * si = md[i].nucleus()->asScriptInset();
                InsetMathFracBase const * fi = md[i].nucleus()->asFracBaseInset();
                InsetMathGrid const * gi = md[i].nucleus()->asGridInset();
@@ -662,6 +664,10 @@ void InsetMathHull::usedMacros(MathData const & md, DocIterator const & pos,
                                asArray(data->definition(), ar);
                        }
                        usedMacros(ar, pos, macros, defs);
+               } else if (mt) {
+                       MathData ar(pos.buffer());
+                       asArray(mt->definition(), ar);
+                       usedMacros(ar, pos, macros, defs);
                } else if (si) {
                        if (!si->nuc().empty())
                                usedMacros(si->nuc(), pos, macros, defs);