[prev in list] [next in list] [prev in thread] [next in thread] 

List:       lyx-cvs
Subject:    [LyX/master] Always validate a macro definition
From:       Enrico Forestieri <forenr () lyx ! org>
Date:       2022-05-31 19:36:21
Message-ID: 20220531193621.8BB1D280660 () lyx ! lyx ! org
[Download RAW message or body]

commit 0aad23015412d6a3a97c73a842079ee22b91ca09
Author: Enrico Forestieri <forenr@lyx.org>
Date:   Tue May 31 22:13:52 2022 +0200

    Always validate a macro definition
    
    If a user-defined macro appears only in the argument of another
    macro its definition is not validated and this leads to errors.
    
    Fixes bug #12524.
---
 src/mathed/InsetMathMacro.cpp |   35 ++++++++++++++++++++---------------
 1 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/src/mathed/InsetMathMacro.cpp b/src/mathed/InsetMathMacro.cpp
index d2c35c7..f6efc70 100644
--- a/src/mathed/InsetMathMacro.cpp
+++ b/src/mathed/InsetMathMacro.cpp
@@ -967,23 +967,28 @@ void InsetMathMacro::validate(LaTeXFeatures & features) const
 			features.require(data->required());
 	}
 
-	if (name() == "binom")
-		features.require("binom");
-
-	// validate the cells and the definition
-	if (displayMode() == DISPLAY_NORMAL) {
-		// Don't update requirements if the macro comes from
-		// the symbols file and has not been redefined.
-		MathWordList const & words = mathedWordList();
-		MathWordList::const_iterator it = words.find(name());
-		MacroNameSet macros;
-		buffer().listMacroNames(macros);
-		if (it == words.end() || it->second.inset != "macro"
-		    || macros.find(name()) != macros.end()) {
-			d->definition_.validate(features);
+	// Validate the cells and the definition.
+	// However, don't validate the definition if the macro is
+	// from the symbols file and has not been redefined, because
+	// in this case the definition is only used for screen display.
+	MathWordList const & words = mathedWordList();
+	MathWordList::const_iterator it = words.find(name());
+	MacroNameSet macros;
+	buffer().listMacroNames(macros);
+	if (it == words.end() || it->second.inset != "macro"
+	    || macros.find(name()) != macros.end()) {
+		if (displayMode() == DISPLAY_NORMAL) {
+				d->definition_.validate(features);
+		} else if (displayMode() == DISPLAY_INIT) {
+			MathData ar(const_cast<Buffer *>(&buffer()));
+			MacroData const * data = buffer().getMacro(name());
+			if (data) {
+				asArray(data->definition(), ar);
+				ar.validate(features);
+			}
 		}
-		InsetMathNest::validate(features);
 	}
+	InsetMathNest::validate(features);
 }
 
 
-- 
lyx-cvs mailing list
lyx-cvs@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-cvs
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic