]> git.lyx.org Git - lyx.git/commitdiff
Extract vert, langle, rangle in MathExtern like parentheses and brackets.
authorThibaut Cuvelier <tcuvelier@lyx.org>
Mon, 11 Mar 2024 00:22:12 +0000 (01:22 +0100)
committerThibaut Cuvelier <tcuvelier@lyx.org>
Mon, 11 Mar 2024 00:22:12 +0000 (01:22 +0100)
This patch is part of a series that aims at solving https://www.lyx.org/trac/ticket/12891. It is an excerpt of the patch that lynx published at https://www.lyx.org/trac/ticket/12270.

src/mathed/MathExtern.cpp

index b07c08b56e049cc58e7105a83c0aa37bfdf86eeb..e273aac7916345779e4a12a15c6d2ebbc1dd0254 100644 (file)
@@ -292,6 +292,19 @@ bool testString(MathAtom const & at, char const * const str)
        return testString(at, from_ascii(str));
 }
 
+
+bool testSymbol(MathAtom const & at, docstring const & name)
+{
+       return at->asSymbolInset() && at->asSymbolInset()->name() == name;
+}
+
+
+bool testSymbol(MathAtom const & at, char const * const name)
+{
+       return testSymbol(at, from_ascii(name));
+}
+
+
 // search end of nested sequence
 MathData::iterator endNestSearch(
        MathData::iterator it,
@@ -523,12 +536,52 @@ MathAtom replaceBracketDelims(const MathData & ar)
 }
 
 
-// replace '('...')' and '['...']' sequences by a real InsetMathDelim
+bool testOpenVert(MathAtom const & at)
+{
+       return testSymbol(at, "lvert");
+}
+
+
+bool testCloseVert(MathAtom const & at)
+{
+       return testSymbol(at, "rvert");
+}
+
+
+MathAtom replaceVertDelims(const MathData & ar)
+{
+       return MathAtom(new InsetMathDelim(const_cast<Buffer *>(ar.buffer()),
+               from_ascii("lvert"), from_ascii("rvert"), ar, true));
+}
+
+
+bool testOpenAngled(MathAtom const & at)
+{
+       return testSymbol(at, "langle");
+}
+
+
+bool testCloseAngled(MathAtom const & at)
+{
+       return testSymbol(at, "rangle");
+}
+
+
+MathAtom replaceAngledDelims(const MathData & ar)
+{
+       return MathAtom(new InsetMathDelim(const_cast<Buffer *>(ar.buffer()),
+               from_ascii("langle"), from_ascii("rangle"), ar, true));
+}
+
+
+// replace '('...')', '['...']', '|'...'|', and '<'...'>' sequences by a real InsetMathDelim
 void extractDelims(MathData & ar)
 {
        //lyxerr << "\nDelims from: " << ar << endl;
        replaceNested(ar, testOpenParen, testCloseParen, replaceParenDelims);
        replaceNested(ar, testOpenBracket, testCloseBracket, replaceBracketDelims);
+       replaceNested(ar, testOpenVert, testCloseVert, replaceVertDelims);
+       replaceNested(ar, testOpenAngled, testCloseAngled, replaceAngledDelims);
        //lyxerr << "\nDelims to: " << ar << endl;
 }
 
@@ -622,18 +675,6 @@ void extractFunctions(MathData & ar, ExternalMath kind)
 // search integrals
 //
 
-bool testSymbol(MathAtom const & at, docstring const & name)
-{
-       return at->asSymbolInset() && at->asSymbolInset()->name() == name;
-}
-
-
-bool testSymbol(MathAtom const & at, char const * const name)
-{
-       return testSymbol(at, from_ascii(name));
-}
-
-
 bool testIntSymbol(MathAtom const & at)
 {
        return testSymbol(at, from_ascii("int"));