commit da7185daaaac1b657d3eb442f907ecaa409d47ac
Author: Juergen Spitzmueller <[email protected]>
Date: Thu Aug 27 08:53:03 2026 +0200
Handle math scripts in alltt
---
lib/layouts/beamer.layout | 2 +-
lib/layouts/ltx-talk.layout | 2 +-
lib/layouts/lyxmacros.inc | 2 +-
src/mathed/InsetMathHull.cpp | 4 ++--
src/mathed/InsetMathNest.cpp | 3 +--
src/mathed/InsetMathScript.cpp | 23 +++++++++++++++++------
src/mathed/MathStream.h | 10 +++++-----
7 files changed, 28 insertions(+), 18 deletions(-)
diff --git a/lib/layouts/beamer.layout b/lib/layouts/beamer.layout
index 0d301c5540..c24b23ba84 100644
--- a/lib/layouts/beamer.layout
+++ b/lib/layouts/beamer.layout
@@ -1427,7 +1427,7 @@ Style Code
KeepEmpty 1
Newline 0
ParbreakIsNewline 1
- PassThruChars " ~$"
+ PassThruChars " ~$^_"
Requires alltt
Font
Family Typewriter
diff --git a/lib/layouts/ltx-talk.layout b/lib/layouts/ltx-talk.layout
index 3b9ab85f81..f678824c2e 100644
--- a/lib/layouts/ltx-talk.layout
+++ b/lib/layouts/ltx-talk.layout
@@ -1342,7 +1342,7 @@ Style Code
KeepEmpty 1
Newline 0
ParbreakIsNewline 1
- PassThruChars " ~$"
+ PassThruChars " ~$^_"
Requires alltt
Font
Family Typewriter
diff --git a/lib/layouts/lyxmacros.inc b/lib/layouts/lyxmacros.inc
index 275688c141..fdfbb8e8a0 100644
--- a/lib/layouts/lyxmacros.inc
+++ b/lib/layouts/lyxmacros.inc
@@ -23,7 +23,7 @@ Style Code
KeepEmpty 1
NewLine 0
ParbreakIsNewline 1
- PassThruChars " ~$"
+ PassThruChars " ~$^_"
Requires alltt
Font
Family Typewriter
diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp
index 544805705d..170162b561 100644
--- a/src/mathed/InsetMathHull.cpp
+++ b/src/mathed/InsetMathHull.cpp
@@ -1261,7 +1261,7 @@ void InsetMathHull::header_writeMath(TeXMathStream & os)
const
case hullSimple:
if (os.ulemCmd())
os << "\\mbox{";
- if (os.LaTeXDelims())
+ if (support::contains(os.passThruChars(), '$'))
os << "\\(";
else
os << '$';
@@ -1329,7 +1329,7 @@ void InsetMathHull::footer_writeMath(TeXMathStream & os)
const
break;
case hullSimple:
- if (os.LaTeXDelims())
+ if (support::contains(os.passThruChars(), '$'))
os << "\\)";
else
os << '$';
diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp
index 4b911b17f5..1ba250ac5e 100644
--- a/src/mathed/InsetMathNest.cpp
+++ b/src/mathed/InsetMathNest.cpp
@@ -380,8 +380,7 @@ void InsetMathNest::latex(otexstream & os, OutputParams
const & runparams) const
wi.canBreakLine(os.canBreakLine());
Changer dummy = wi.changeRowEntry(TexRow::textEntry(runparams.lastid,
runparams.lastpos));
- // Use LaTeX inline delimiters if $ is a pass-thru char
- wi.useLaTeXDelims(support::contains(runparams.pass_thru_chars, '$'));
+ wi.setPassThruChars(runparams.pass_thru_chars);
writeMath(wi);
// Reset parbreak and command termination status after a math inset.
os.lastChar(0);
diff --git a/src/mathed/InsetMathScript.cpp b/src/mathed/InsetMathScript.cpp
index 05a74ac377..48edaf14d6 100644
--- a/src/mathed/InsetMathScript.cpp
+++ b/src/mathed/InsetMathScript.cpp
@@ -25,6 +25,7 @@
#include "support/debug.h"
#include "support/lassert.h"
+#include "support/lstrings.h"
using namespace std;
@@ -517,18 +518,28 @@ void InsetMathScript::writeMath(TeXMathStream & os) const
os << "{}";
if (hasUp() /*&& !up().empty()*/) {
+ docstring const m = support::contains(os.passThruChars(), '^')
+ ? from_ascii("\\sp")
+ : from_ascii("^");
// insert space if up() is empty or an empty brace inset
// (see bug 8305)
if (os.latex() && (up().empty() ||
(up().size() == 1 && up().back()->asBraceInset() &&
- up().back()->asBraceInset()->cell(0).empty())))
- os << "^ {}";
- else
- os << "^{" << up() << '}';
+ up().back()->asBraceInset()->cell(0).empty()))) {
+ os << m;
+ if (m == "^")
+ os << " ";
+ os << "{}";
+ } else
+ os << m << "{" << up() << '}';
}
- if (hasDown() /*&& !down().empty()*/)
- os << "_{" << down() << '}';
+ if (hasDown() /*&& !down().empty()*/) {
+ docstring const m = support::contains(os.passThruChars(), '_')
+ ? from_ascii("\\sb")
+ : from_ascii("_");
+ os << m << "{" << down() << '}';
+ }
// Avoid double superscript errors by writing an
// empty group {} when a prime immediately follows
diff --git a/src/mathed/MathStream.h b/src/mathed/MathStream.h
index af5bec0a76..1fcbcff78b 100644
--- a/src/mathed/MathStream.h
+++ b/src/mathed/MathStream.h
@@ -212,10 +212,10 @@ public:
Encoding const * encoding() const { return encoding_; }
///
docstring escapeChars() const { return escape_chars_; }
- /// record whether we have to use LaTeX inline delimiters
- void useLaTeXDelims(bool ltd) { latex_delims_ = ltd; }
- /// tell whether to use LaTeX inline delimiters
- bool LaTeXDelims() const { return latex_delims_; }
+ ///
+ void setPassThruChars(docstring const & s) { pass_thru_chars_ = s; }
+ ///
+ docstring passThruChars() const { return pass_thru_chars_; }
/// Temporarily change the TexRow information about the outer row entry.
Changer changeRowEntry(TexRow::RowEntry const & entry);
@@ -263,7 +263,7 @@ private:
///
docstring escape_chars_;
///
- bool latex_delims_ = false;
+ docstring pass_thru_chars_;
};
///
--
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs