commit a45cf357af980ee5c6b56073c6904618a4326bca
Author: Juergen Spitzmueller <[email protected]>
Date: Mon Aug 11 12:06:46 2025 +0200
Amend 5d8bfddeece
Use proper prettyformat for equations
---
src/insets/InsetFlex.cpp | 2 +-
src/insets/InsetLabel.cpp | 56 ++++++++++++++++++++++++++++++++++++++++----
src/insets/InsetLabel.h | 2 +-
src/mathed/InsetMathHull.cpp | 20 ++++++++++++----
4 files changed, 70 insertions(+), 10 deletions(-)
diff --git a/src/insets/InsetFlex.cpp b/src/insets/InsetFlex.cpp
index e4a79370e6..a77591414b 100644
--- a/src/insets/InsetFlex.cpp
+++ b/src/insets/InsetFlex.cpp
@@ -174,7 +174,7 @@ void InsetFlex::updateBuffer(ParIterator const & it,
UpdateType utype, bool cons
cnts.newCounter(equation, parentequation,
eqlabel + from_ascii("\\alph{equation}"),
eqlabel + from_ascii("\\alph{equation}"),
- eqlabel + from_ascii("\\alph{equation}"),
+ from_ascii("Equation|Equations ##"),
cnts.guiName(parentequation));
InsetCollapsible::updateBuffer(it, utype, deleted);
// reset equation counter as it was.
diff --git a/src/insets/InsetLabel.cpp b/src/insets/InsetLabel.cpp
index 74ac080028..4740e66bcf 100644
--- a/src/insets/InsetLabel.cpp
+++ b/src/insets/InsetLabel.cpp
@@ -40,6 +40,7 @@
#include "support/convert.h"
#include "support/gettext.h"
#include "support/lstrings.h"
+#include "support/textutils.h"
using namespace std;
using namespace lyx::support;
@@ -169,6 +170,46 @@ docstring InsetLabel::formattedCounter(bool const lc, bool
const pl) const
}
+void InsetLabel::setFormattedCounter(docstring const & fc, bool const lc, bool
const pl)
+{
+ if (pl) {
+ if (lc)
+ formatted_counter_lc_pl_ = fc;
+ else
+ formatted_counter_pl_ = fc;
+ } else {
+ if (lc)
+ formatted_counter_lc_ = fc;
+ else
+ formatted_counter_ = fc;
+ }
+}
+
+
+namespace {
+docstring stripSubrefs(docstring const & in, bool const parens){
+ docstring res;
+ bool have_digit = false;
+ size_t const len = in.length();
+ for (size_t i = 0; i < len; ++i) {
+ // subref can be an alphabetic letter or '?'
+ // as soon as we encounter this, break
+ if (have_digit && (isLetterChar(in[i]) || in[i] == '?'))
+ return parens ? res + ")" : res;
+ else {
+ if (isNumberChar(in[i]) && !have_digit) {
+ if (parens)
+ res += "(";
+ have_digit = true;
+ }
+ res += in[i];
+ }
+ }
+ return parens ? res + ")" : res;
+}
+}
+
+
void InsetLabel::updateBuffer(ParIterator const & it, UpdateType, bool const
/*deleted*/)
{
docstring const & label = getParam("name");
@@ -261,10 +302,11 @@ void InsetLabel::updateBuffer(ParIterator const & it,
UpdateType, bool const /*d
if (equation) {
// FIXME: special code just for the
subequations module (#13199)
// replace with a genuine solution
long-term!
- formatted_counter_ = "(" +
trim(formatted_counter_, "?") + ")";
- formatted_counter_pl_ = "(" +
trim(formatted_counter_pl_, "?") + ")";
- formatted_counter_lc_ = "(" +
trim(formatted_counter_lc_, "?") + ")";
- formatted_counter_lc_pl_ = "(" +
trim(formatted_counter_lc_pl_, "?") + ")";
+ counter_value_ = stripSubrefs(counter_value_,
false);
+ formatted_counter_ =
stripSubrefs(formatted_counter_, true);
+ formatted_counter_pl_ =
stripSubrefs(formatted_counter_pl_, true);
+ formatted_counter_lc_ =
stripSubrefs(formatted_counter_lc_, true);
+ formatted_counter_lc_pl_ =
stripSubrefs(formatted_counter_lc_pl_, true);
}
} else {
// For equations, the counter value and pretty counter
@@ -272,11 +314,17 @@ void InsetLabel::updateBuffer(ParIterator const & it,
UpdateType, bool const /*d
counter_value_ = from_ascii("#");
pretty_counter_ = from_ascii("");
formatted_counter_ = from_ascii("");
+ formatted_counter_lc_ = from_ascii("");
+ formatted_counter_pl_ = from_ascii("");
+ formatted_counter_lc_pl_ = from_ascii("");
}
} else {
counter_value_ = from_ascii("#");
pretty_counter_ = from_ascii("#");
formatted_counter_ = from_ascii("#");
+ formatted_counter_lc_ = from_ascii("#");
+ formatted_counter_pl_ = from_ascii("#");
+ formatted_counter_lc_pl_ = from_ascii("#");
}
if (!active_counter_.empty()) {
if (active_counter_ == (*it).layout().counter) {
diff --git a/src/insets/InsetLabel.h b/src/insets/InsetLabel.h
index 154f332ab5..f786dc5843 100644
--- a/src/insets/InsetLabel.h
+++ b/src/insets/InsetLabel.h
@@ -38,7 +38,7 @@ public:
///
void setPrettyCounter(docstring const & pc) { pretty_counter_ = pc; }
///
- void setFormattedCounter(docstring const & fc) { formatted_counter_ =
fc; }
+ void setFormattedCounter(docstring const & fc, bool lc = false, bool pl
= false);
///
int rowFlags() const override { return CanBreakBefore | CanBreakAfter; }
/// Updates only the label string, doesn't handle undo nor references.
diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp
index 09e1eea45c..c8b5d19bc4 100644
--- a/src/mathed/InsetMathHull.cpp
+++ b/src/mathed/InsetMathHull.cpp
@@ -243,11 +243,11 @@ void InsetMathHull::updateBuffer(ParIterator const & it,
UpdateType utype, bool
return;
}
+ BufferParams const & bp = buffer_->params();
+ string const & lang = it->getParLanguage(bp)->code();
// if any of the equations are numbered, then we want to save the values
// of some of the counters.
if (haveNumbers()) {
- BufferParams const & bp = buffer_->params();
- string const & lang = it->getParLanguage(bp)->code();
Counters & cnts =
buffer_->masterBuffer()->params().documentClass().counters();
@@ -285,8 +285,20 @@ void InsetMathHull::updateBuffer(ParIterator const & it,
UpdateType utype, bool
for (row_type row = 0; row != nrows(); ++row) {
if (numbered(row) && labels_[row]) {
labels_[row]->setCounterValue(numbers_[row]);
- labels_[row]->setPrettyCounter("(" + numbers_[row] +
")");
- labels_[row]->setFormattedCounter("(" + numbers_[row] +
")");
+ docstring const embraced_num = "(" + numbers_[row] +
")";
+ labels_[row]->setPrettyCounter(embraced_num);
+ // lowercase singular
+ docstring pf = translateIfPossible(from_ascii("equation
##"), lang);
+ labels_[row]->setFormattedCounter(subst(pf,
from_ascii("##"), embraced_num), true, false);
+ // lowercase plural
+ pf = translateIfPossible(from_ascii("equations ##"),
lang);
+ labels_[row]->setFormattedCounter(subst(pf,
from_ascii("##"), embraced_num), true, true);
+ // uppercase singular
+ pf = translateIfPossible(from_ascii("Equation ##"),
lang);
+ labels_[row]->setFormattedCounter(subst(pf,
from_ascii("##"), embraced_num), false, false);
+ // uppercase plural
+ pf = translateIfPossible(from_ascii("Equations ##"),
lang);
+ labels_[row]->setFormattedCounter(subst(pf,
from_ascii("##"), embraced_num), false, true);
}
}
--
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs