commit 5f3ca2c4f7cdee9db989c43641e6e38b9f01419c
Author: Juergen Spitzmueller <[email protected]>
Date: Sun Nov 16 12:01:35 2025 +0100
Escape math delimiter chars if needed (#13250)
This concerns at least "|" in index and nomencl.
---
src/mathed/InsetMathDelim.cpp | 27 +++++++++++++++++++++++++--
src/mathed/InsetMathNest.cpp | 2 +-
src/mathed/MathStream.cpp | 5 +++--
src/mathed/MathStream.h | 9 +++++++--
4 files changed, 36 insertions(+), 7 deletions(-)
diff --git a/src/mathed/InsetMathDelim.cpp b/src/mathed/InsetMathDelim.cpp
index 517bc7590f..93a85027ef 100644
--- a/src/mathed/InsetMathDelim.cpp
+++ b/src/mathed/InsetMathDelim.cpp
@@ -22,6 +22,7 @@
#include "LaTeXFeatures.h"
#include "support/docstring.h"
+#include "support/lstrings.h"
#include "frontends/FontMetrics.h"
@@ -85,8 +86,30 @@ void InsetMathDelim::validate(LaTeXFeatures & features) const
void InsetMathDelim::writeMath(TeXMathStream & os) const
{
MathEnsurer ensurer(os);
- os << "\\left" << convertDelimToLatexName(left_) << cell(0)
- << "\\right" << convertDelimToLatexName(right_);
+ docstring ldelim = convertDelimToLatexName(left_);
+ docstring rdelim = convertDelimToLatexName(right_);
+ // since some chars used for delims ('|' at least)
+ // must be escaped in Index and Nomencl, we have
+ // to handle this (#13250)
+ if (!os.escapeChars().empty()) {
+ odocstringstream ods;
+ for (char_type const c : ldelim) {
+ if (support::contains(os.escapeChars().substr(1), c))
+ ods << os.escapeChars().substr(0,1);
+ ods.put(c);
+ }
+ ldelim = ods.str();
+ ods.clear();
+ ods.str(docstring());
+ for (char_type const c : rdelim) {
+ if (support::contains(os.escapeChars().substr(1), c))
+ ods << os.escapeChars().substr(0,1);
+ ods.put(c);
+ }
+ rdelim = ods.str();
+ }
+ os << "\\left" << ldelim << cell(0)
+ << "\\right" << rdelim;
}
diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp
index e2df762724..aff39557f0 100644
--- a/src/mathed/InsetMathNest.cpp
+++ b/src/mathed/InsetMathNest.cpp
@@ -367,7 +367,7 @@ void InsetMathNest::latex(otexstream & os, OutputParams
const & runparams) const
else
ot = TeXMathStream::wsDefault;
TeXMathStream wi(os, runparams.moving_arg, true, ot,
- runparams.encoding);
+ runparams.encoding, runparams.escape_chars);
wi.strikeoutMath(runparams.inDeletedInset);
if (runparams.inulemcmd) {
wi.ulemCmd(TeXMathStream::UNDERLINE);
diff --git a/src/mathed/MathStream.cpp b/src/mathed/MathStream.cpp
index c95aa26da6..6711e821d4 100644
--- a/src/mathed/MathStream.cpp
+++ b/src/mathed/MathStream.cpp
@@ -439,9 +439,10 @@ TeXMathStream & operator<<(TeXMathStream & ws, docstring
const & s)
TeXMathStream::TeXMathStream(otexrowstream & os, bool fragile, bool latex,
- OutputType output, Encoding const * encoding)
+ OutputType output, Encoding const * encoding,
+ docstring escapechars)
: os_(os), fragile_(fragile), latex_(latex),
- output_(output), encoding_(encoding)
+ output_(output), encoding_(encoding), escape_chars_(escapechars)
{}
diff --git a/src/mathed/MathStream.h b/src/mathed/MathStream.h
index 39fe949fb8..73dd05ea50 100644
--- a/src/mathed/MathStream.h
+++ b/src/mathed/MathStream.h
@@ -145,8 +145,9 @@ public:
};
///
explicit TeXMathStream(otexrowstream & os, bool fragile = false,
- bool latex = false, OutputType output =
wsDefault,
- Encoding const * encoding = nullptr);
+ bool latex = false, OutputType output =
wsDefault,
+ Encoding const * encoding = nullptr,
+ docstring escapechar = docstring());
///
~TeXMathStream();
///
@@ -209,6 +210,8 @@ public:
bool inMathClass() const { return mathclass_; }
/// LaTeX encoding
Encoding const * encoding() const { return encoding_; }
+ ///
+ docstring escapeChars() const { return escape_chars_; }
/// Temporarily change the TexRow information about the outer row entry.
Changer changeRowEntry(TexRow::RowEntry const & entry);
@@ -253,6 +256,8 @@ private:
TexRow::RowEntry row_entry_ = TexRow::row_none;
/// whether we are in a MathClass inset
bool mathclass_ = false;
+ ///
+ docstring escape_chars_;
};
///
--
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs