commit 8f23f91e1beeb47b7a1c06fad32ba518e213f6db
Author: Koji Yokota <[email protected]>
Date: Wed Jun 4 08:53:01 2025 +0900
Introducing LaTeX support for \intertext and \shortintertext
Squashed commit of the following:
commit 8514efb45e568521192e0b73ee20edebe2d95831
Author: Koji Yokota <[email protected]>
Date: Mon May 12 20:33:20 2025 +0900
Adjusting drawing dimensions of intertext
commit 23f39432ab4c2e4b364b807b9baebad68087a54c
Author: Koji Yokota <[email protected]>
Date: Sat May 10 22:37:45 2025 +0900
Add support for DocBook/ePub export
commit 34d51e674ea33ef692fd3d0bf1e94fad9b1f7fdb
Author: Koji Yokota <[email protected]>
Date: Fri May 2 22:52:14 2025 +0900
Removing unnecessary comment-outs
commit 6c96b227557a32b09a14a2870f74680622b277d2
Author: Koji Yokota <[email protected]>
Date: Fri May 2 21:20:34 2025 +0900
Accommodating the case of long intertexts
commit 300ebbc7fdf2ae5ab5ced0d5eec26877c698d06f
Author: Koji Yokota <[email protected]>
Date: Fri May 2 21:17:48 2025 +0900
Fixing traces of rough drafts
commit 89679013ab720f4feea1ed128ac088ebb3b0bcc8
Author: Koji Yokota <[email protected]>
Date: Fri May 2 17:47:37 2025 +0900
Simplifying metrics calculus
commit 84c33568d6f45751794c6419a2bbcc5b7d21a840
Author: Koji Yokota <[email protected]>
Date: Fri May 2 11:53:25 2025 +0900
Add main new files
commit 99556226f0106eeb02cce7becc5d4b733c92a147
Author: Koji Yokota <[email protected]>
Date: Fri May 2 11:38:16 2025 +0900
Add LaTeX support for \intertext and \shortintertext
---
lib/symbols | 2 +
src/Cursor.cpp | 3 +-
src/Makefile.am | 2 +
src/insets/Inset.cpp | 1 +
src/insets/InsetCode.h | 34 ++++++------
src/mathed/InsetMath.h | 3 ++
src/mathed/InsetMathIntertext.cpp | 108 ++++++++++++++++++++++++++++++++++++++
src/mathed/InsetMathIntertext.h | 57 ++++++++++++++++++++
src/mathed/MathFactory.cpp | 3 ++
9 files changed, 196 insertions(+), 17 deletions(-)
diff --git a/lib/symbols b/lib/symbols
index 689bd0d203..7c4cb76963 100644
--- a/lib/symbols
+++ b/lib/symbols
@@ -248,6 +248,8 @@ overset overset none
mbox mbox forcetext
tag mbox forcetext
tag* mbox forcetext
+intertext intertext forcetext
+shortintertext intertext forcetext
#newcommand newcommand none
#label label none
#left left none
diff --git a/src/Cursor.cpp b/src/Cursor.cpp
index 099b6f2a58..10dc27726c 100644
--- a/src/Cursor.cpp
+++ b/src/Cursor.cpp
@@ -1816,7 +1816,8 @@ bool Cursor::macroModeClose(bool cancel)
|| (it != words.end() && (it->second.inset == "font"
|| it->second.inset == "oldfont"
|| it->second.inset == "textsize"
- || it->second.inset == "mbox"));
+ || it->second.inset == "mbox"
+ || it->second.inset == "intertext"));
bool ert_macro = !user_macro && it == words.end() && atomAsMacro;
if (in && in->currentMode() == Inset::TEXT_MODE
diff --git a/src/Makefile.am b/src/Makefile.am
index 7117232822..f3edd9d339 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -430,6 +430,8 @@ liblyxmathed_a_SOURCES = \
mathed/InsetMathGrid.h \
mathed/InsetMathHull.cpp \
mathed/InsetMathHull.h \
+ mathed/InsetMathIntertext.cpp \
+ mathed/InsetMathIntertext.h \
mathed/InsetMathKern.cpp \
mathed/InsetMathKern.h \
mathed/InsetMathLefteqn.cpp \
diff --git a/src/insets/Inset.cpp b/src/insets/Inset.cpp
index d60e4a8078..8884906b8e 100644
--- a/src/insets/Inset.cpp
+++ b/src/insets/Inset.cpp
@@ -147,6 +147,7 @@ static void build_translator()
insetnames[MATH_GRID_CODE] = InsetName("mathgrid");
insetnames[MATH_CODE] = InsetName("math");
insetnames[MATH_HULL_CODE] = InsetName("mathhull");
+ insetnames[MATH_INTERTEXT_CODE] = InsetName("mathintertext");
insetnames[MATH_KERN_CODE] = InsetName("mathkern");
insetnames[MATH_LEFTEQN_CODE] = InsetName("mathlefteqn");
insetnames[MATH_LIM_CODE] = InsetName("mathlim");
diff --git a/src/insets/InsetCode.h b/src/insets/InsetCode.h
index 6082e76395..e7d113ef1a 100644
--- a/src/insets/InsetCode.h
+++ b/src/insets/InsetCode.h
@@ -165,11 +165,13 @@ enum InsetCode {
///
MATH_HULL_CODE,
///
+ MATH_INTERTEXT_CODE,
+ ///
MATH_KERN_CODE,
///
- MATH_LEFTEQN_CODE,
+ MATH_LEFTEQN_CODE, // 75
///
- MATH_LIM_CODE, // 75
+ MATH_LIM_CODE,
///
MATH_MATRIX_CODE,
///
@@ -177,9 +179,9 @@ enum InsetCode {
///
MATH_NEST_CODE,
///
- MATH_NUMBER_CODE,
+ MATH_NUMBER_CODE, // 80
///
- MATH_OVERSET_CODE, // 80
+ MATH_OVERSET_CODE,
///
MATH_PAR_CODE,
///
@@ -187,9 +189,9 @@ enum InsetCode {
///
MATH_REF_CODE,
///
- MATH_ROOT_CODE,
+ MATH_ROOT_CODE, // 85
///
- MATH_SCRIPT_CODE, // 85
+ MATH_SCRIPT_CODE,
///
MATH_SIZE_CODE,
///
@@ -197,9 +199,9 @@ enum InsetCode {
///
MATH_SPECIALCHAR_CODE,
///
- MATH_SPLIT_CODE,
+ MATH_SPLIT_CODE, // 90
///
- MATH_SQRT_CODE, // 90
+ MATH_SQRT_CODE,
///
MATH_STACKREL_CODE,
///
@@ -207,9 +209,9 @@ enum InsetCode {
///
MATH_SUBSTACK_CODE,
///
- MATH_SYMBOL_CODE,
+ MATH_SYMBOL_CODE, // 95
///
- MATH_TABULAR_CODE, // 95
+ MATH_TABULAR_CODE,
///
MATH_TEXTSIZE_CODE,
///
@@ -217,9 +219,9 @@ enum InsetCode {
///
MATH_UNKNOWN_CODE,
///
- MATH_XARROW_CODE,
+ MATH_XARROW_CODE, // 100
///
- MATH_XYMATRIX_CODE, // 100
+ MATH_XYMATRIX_CODE,
///
MATH_MACRO_CODE,
///
@@ -227,9 +229,9 @@ enum InsetCode {
///
PREVIEW_CODE,
///
- MATH_DIAGRAM_CODE,
+ MATH_DIAGRAM_CODE, // 105
///
- SCRIPT_CODE, // 105
+ SCRIPT_CODE,
///
IPA_CODE,
///
@@ -237,9 +239,9 @@ enum InsetCode {
///
IPADECO_CODE,
///
- MATH_CLASS_CODE,
+ MATH_CLASS_CODE, // 110
///
- COUNTER_CODE, // 110
+ COUNTER_CODE,
///
INDEXMACRO_CODE,
///
diff --git a/src/mathed/InsetMath.h b/src/mathed/InsetMath.h
index 7e10264130..f6d8fcb8c6 100644
--- a/src/mathed/InsetMath.h
+++ b/src/mathed/InsetMath.h
@@ -88,6 +88,7 @@ class InsetMathFrac;
class InsetMathFont;
class InsetMathGrid;
class InsetMathHull;
+class InsetMathIntertext;
class InsetMathMatrix;
class InsetMathNest;
class InsetMathScript;
@@ -170,6 +171,8 @@ public:
virtual InsetMathGrid const * asGridInset() const { return
nullptr; }
virtual InsetMathHull * asHullInset() { return
nullptr; }
virtual InsetMathHull const * asHullInset() const { return
nullptr; }
+ virtual InsetMathIntertext * asIntertextInset() { return
nullptr; }
+ virtual InsetMathIntertext const * asIntertextInset() const { return
nullptr; }
virtual InsetMathMacro * asMacroInset() { return
nullptr; }
virtual InsetMathMacro const * asMacroInset() const { return
nullptr; }
virtual InsetMathMacroTemplate * asMacroTemplateInset() {
return nullptr; }
diff --git a/src/mathed/InsetMathIntertext.cpp
b/src/mathed/InsetMathIntertext.cpp
new file mode 100644
index 0000000000..8b9003b268
--- /dev/null
+++ b/src/mathed/InsetMathIntertext.cpp
@@ -0,0 +1,108 @@
+/**
+ * \file InsetMathIntertext.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Koji Yokota
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "InsetMathIntertext.h"
+
+#include "Buffer.h"
+#include "BufferView.h"
+#include "Dimension.h"
+#include "InsetMathChar.h"
+#include "LaTeXFeatures.h"
+#include "MathData.h"
+#include "MathFactory.h"
+#include "MathStream.h"
+#include "MathSupport.h"
+#include "MetricsInfo.h"
+#include "support/docstream.h"
+#include "support/lstrings.h"
+
+using lyx::support::escape;
+
+
+namespace lyx {
+
+InsetMathIntertext::InsetMathIntertext(Buffer * buf, docstring const & name)
+ : InsetMathNest(buf, 1), name_(name)
+{}
+
+
+void InsetMathIntertext::write(TeXMathStream & os) const
+{
+ ModeSpecifier specifier(os, TEXT_MODE);
+ os << '\\' << name_ << '{' << cell(0) << '}';
+}
+
+
+Inset * InsetMathIntertext::clone() const
+{
+ return new InsetMathIntertext(*this);
+}
+
+
+void InsetMathIntertext::metrics(MetricsInfo & mi, Dimension & dim) const
+{
+ Changer dummy = mi.base.changeFontSet("text");
+ cell(0).metrics(mi, dim);
+ if (name_ == "shortintertext")
+ dim.asc += 2 * dim.asc + dim.des + spacer_;
+ else
+ dim.asc += 3 * dim.asc + 2 * (dim.des + spacer_);
+}
+
+
+void InsetMathIntertext::draw(PainterInfo & pi, int x, int y) const
+{
+ Changer dummy = pi.base.changeFontSet("text");
+ Dimension const dim = dimension(*pi.base.bv);
+ int text_y;
+ // note that dim.asc is already updated in metrics()
+ if (name_ == "shortintertext")
+ text_y = y - (dim.asc + dim.des + spacer_)/2;
+ else
+ text_y = y - (dim.asc - dim.des + spacer_)/2;
+ cell(0).draw(pi, x, text_y);
+}
+
+
+docstring InsetMathIntertext::name() const
+{
+ return name_;
+}
+
+
+void InsetMathIntertext::mathmlize(MathMLStream & ms) const
+{
+ ms << MTagInline("mtext", "style=\"position:absolute;left:0px\"");
+ for (size_type i=0; i<cell(0).size(); ++i)
+ ms << cell(0)[i]->asCharInset()->getChar();
+ ms << ETagInline("mtext");
+ // make a new line
+ ms << ETag("mtd") << ETag("mtr")
+ << MTag("mtr", "style=\"height:3ex\"") << ETag("mtr")
+ << MTag("mtr") << MTag("mtd");
+}
+
+
+void InsetMathIntertext::infoize(odocstream & os) const
+{
+ os << "Intertext ";
+}
+
+
+void InsetMathIntertext::validate(LaTeXFeatures & features) const
+{
+ if (name_ == "shortintertext" && features.runparams().isLaTeX())
+ features.require("mathtools");
+ InsetMathNest::validate(features);
+}
+
+} // namespace lyx
diff --git a/src/mathed/InsetMathIntertext.h b/src/mathed/InsetMathIntertext.h
new file mode 100644
index 0000000000..30db04c9ff
--- /dev/null
+++ b/src/mathed/InsetMathIntertext.h
@@ -0,0 +1,57 @@
+// -*- C++ -*-
+/**
+ * \file InsetMathIntertext.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Koji Yokota
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef MATH_INTERTEXTINSET_H
+#define MATH_INTERTEXTINSET_H
+
+#include "InsetMathNest.h"
+
+#include "support/docstring.h"
+
+
+namespace lyx {
+
+
+/// Support for LaTeX's \\intertext command
+
+class InsetMathIntertext : public InsetMathNest {
+public:
+ ///
+ explicit InsetMathIntertext(Buffer * buf, docstring const & name);
+ ///
+ mode_type currentMode() const override { return TEXT_MODE; }
+ ///
+ docstring name() const override;
+ ///
+ void metrics(MetricsInfo & mi, Dimension & dim) const override;
+ ///
+ void draw(PainterInfo & pi, int x, int y) const override;
+ ///
+ void write(TeXMathStream & os) const override;
+ ///
+ void mathmlize(MathMLStream & ms) const override;
+ ///
+ void infoize(odocstream & os) const override;
+ ///
+ InsetCode lyxCode() const override { return MATH_INTERTEXT_CODE; }
+ ///
+ void validate(LaTeXFeatures &) const override;
+
+private:
+ Inset * clone() const override;
+ /// the string
+ docstring name_;
+ int spacer_ = 10;
+};
+
+
+} // namespace lyx
+#endif
diff --git a/src/mathed/MathFactory.cpp b/src/mathed/MathFactory.cpp
index f03915925e..f39bef3d96 100644
--- a/src/mathed/MathFactory.cpp
+++ b/src/mathed/MathFactory.cpp
@@ -27,6 +27,7 @@
#include "InsetMathFont.h"
#include "InsetMathFontOld.h"
#include "InsetMathFrac.h"
+#include "InsetMathIntertext.h"
#include "InsetMathLefteqn.h"
#include "InsetMathOverset.h"
#include "InsetMathPhantom.h"
@@ -568,6 +569,8 @@ MathAtom createInsetMath(docstring const & s, Buffer * buf)
return MathAtom(new InsetMathBox(buf, l->name));
// if (inset == "fbox")
// return MathAtom(new InsetMathFBox(l));
+ if (inset == "intertext")
+ return MathAtom(new InsetMathIntertext(buf, l->name));
if (inset == "style")
return MathAtom(new InsetMathSize(buf, l));
if (inset == "font")
--
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs