With this work, which is fantastic, it really seems to me like we are ready to start thinking about potentially considering maybe moving toward 2.5.0. Not to be too definitive about it!

JMarc, I'm curious what you think about this, and what plans you might have for improvements, and when you think that might stabilize.

Riki


On 4/27/25 10:20 AM, Juergen Spitzmueller wrote:
commit 34cadc8b6eca9095febc6b47a03d7f71afbac6f5
Author: Juergen Spitzmueller <sp...@lyx.org>
Date:   Sun Apr 27 16:19:32 2025 +0200

     Support formatted references to theorems via refstyle (#8535)
These are not provided by the package, so we create those
     definitions on the fly when needed.
---
  src/LaTeXFeatures.cpp    | 56 ++++++++++++++++++++++++++++++++++++------------
  src/LaTeXFeatures.h      |  1 +
  src/insets/InsetRef.cpp  |  2 ++
  src/support/lstrings.cpp |  9 ++++++++
  src/support/lstrings.h   |  3 +++
  5 files changed, 57 insertions(+), 14 deletions(-)

diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp
index cfa06f747a..072b4a10a1 100644
--- a/src/LaTeXFeatures.cpp
+++ b/src/LaTeXFeatures.cpp
@@ -477,17 +477,6 @@ static docstring const smallLetterFrac_def = from_ascii(
        "  {phantom=c, scale-factor=1.0, slash-left-kern=-.05em}\n"
        "\\NewCommandCopy\\smallLetterFrac\\sfrac\n");
-static docstring const lyxref_def = from_ascii(
-       "\\RS@ifundefined{subsecref}\n"
-       "  {\\newref{subsec}{name = \\RSsectxt}}\n"
-       "  {}\n"
-       "\\RS@ifundefined{thmref}\n"
-       "  {\\def\\RSthmtxt{theorem~}\\newref{thm}{name = \\RSthmtxt}}\n"
-       "  {}\n"
-       "\\RS@ifundefined{lemref}\n"
-       "  {\\def\\RSlemtxt{lemma~}\\newref{lem}{name = \\RSlemtxt}}\n"
-       "  {}\n");
-
  // Make sure the columns are also outputed as rtl
  static docstring const rtloutputdblcol_def = from_ascii(
        "\\def\\@outputdblcol{%\n"
@@ -712,6 +701,7 @@ void LaTeXFeatures::useLayout(docstring const & layoutname, 
int level)
                        thm.parent_counter = layout.thmParentCounter();
                        thm.style = layout.thmStyle();
                        thm.zrefname = layout.thmZRefName();
+                       thm.refprefix = to_ascii(layout.refprefix);
                        usedTheorems_.push_back(thm);
                        require("amsthm");
                }
@@ -1809,8 +1799,23 @@ TexString LaTeXFeatures::getMacros() const
        // floats
        getFloatDefinitions(macros);
- if (mustProvide("refstyle"))
-               macros << lyxref_def << '\n';
+       if (mustProvide("refstyle:subsecref")) {
+               // this is not provided by the package, but we use the prefix
+               // the definition is a copy of secref
+               macros << "\\RS@ifundefined{subsecref}{\n"
+                      << "  \\newref{subsec}{\n"
+                      << "        name      = \\RSsectxt,\n"
+                      << "        names     = \\RSsecstxt,\n"
+                      << "        Name      = \\RSSectxt,\n"
+                      << "        Names     = \\RSSecstxt,\n"
+                      << "        refcmd    = {\\S\\ref{#1}},\n"
+                      << "        rngtxt    = \\RSrngtxt,\n"
+                      << "        lsttwotxt = \\RSlsttwotxt,\n"
+                      << "        lsttxt    = \\RSlsttxt\n"
+                      << "  }\n"
+                      << "}{}\n"
+                      << '\n';
+       }
// change tracking
        if (mustProvide("ct-xcolor-ulem")) {
@@ -1974,7 +1979,7 @@ string const LaTeXFeatures::getThmDefinitions() const
                                }
                        }
                }
-               // or cleveref
+               // cleveref
                else if (thm.counter != "none" && !thm.counter.empty() && 
params_.xref_package == "cleveref") {
                        if (isAvailableAtLeastFrom("LaTeX", 2020, 10))
                                // we have hooks
@@ -1987,6 +1992,19 @@ string const LaTeXFeatures::getThmDefinitions() const
                                    << "\\lyxsave" << thm.name << "}\n";
                        }
                }
+               // and refstyle
+               else if (params_.xref_package == "refstyle") {
+                       tmp << "\\newref{" << thm.refprefix << "}{\n"
+                           << "        name      = \\RS" << thm.name << 
"txt,\n"
+                           << "        names     = \\RS" << thm.name << 
"stxt,\n"
+                           << "        Name      = \\RS" << capitalize(thm.name) << 
"txt,\n"
+                           << "        Names     = \\RS" << capitalize(thm.name) << 
"stxt,\n"
+                           << "        rngtxt    = \\RSrngtxt,\n"
+                           << "        lsttwotxt = \\RSlsttwotxt,\n"
+                           << "        lsttxt    = \\RSlsttxt\n"
+                           << "}\n"
+                           << '\n';
+               }
        }
return tmp.str();
@@ -2220,6 +2238,16 @@ docstring const LaTeXFeatures::getThmI18nDefs(Layout const 
& lay) const
                    << "name-pl = _(" << lowercase(tnp) << ")"
                    << "}\n";
                return ods.str();
+       } else if (params_.xref_package == "refstyle" && 
!lay.thmXRefName().empty()) {
+               docstring const tn = from_utf8(lay.thmXRefName());
+               docstring const tnp = from_utf8(lay.thmXRefNamePl());
+               odocstringstream ods;
+               docstring const thmname = from_utf8(lay.thmName());
+               ods << "\\def\\RS" << thmname << "txt{_(" << lowercase(tn) << 
")~}\n"
+                   << "\\def\\RS" << thmname << "stxt{_(" << lowercase(tnp) << 
")~}\n"
+                   << "\\def\\RS" << capitalize(thmname) << "txt{_(" << tn << 
")~}\n"
+                   << "\\def\\RS" << capitalize(thmname) << "stxt{_(" << tnp << 
")~}\n";
+               return ods.str();
        }
        return docstring();
  }
diff --git a/src/LaTeXFeatures.h b/src/LaTeXFeatures.h
index 4a1c593b95..55cb1b5ac1 100644
--- a/src/LaTeXFeatures.h
+++ b/src/LaTeXFeatures.h
@@ -40,6 +40,7 @@ struct ThmInfo {
        std::string parent_counter;
        std::string style;
        std::string zrefname;
+       std::string refprefix;
  };
diff --git a/src/insets/InsetRef.cpp b/src/insets/InsetRef.cpp
index 055aca8174..77db418ae4 100644
--- a/src/insets/InsetRef.cpp
+++ b/src/insets/InsetRef.cpp
@@ -891,6 +891,8 @@ void InsetRef::validate(LaTeXFeatures & features) const
                        features.require("refstyle");
                        if (prefix == "cha")
                                
features.addPreambleSnippet(from_ascii("\\let\\charef=\\chapref"));
+                       else if (prefix == "subsec")
+                               features.require("refstyle:subsecref");
                        else if (!prefix.empty()) {
                                docstring lcmd = 
"\\AtBeginDocument{\\providecommand" +
                                                fcmd + "[1]{\\ref{" + prefix + 
":#1}}}";
diff --git a/src/support/lstrings.cpp b/src/support/lstrings.cpp
index 6cc99ad176..e26955dfb8 100644
--- a/src/support/lstrings.cpp
+++ b/src/support/lstrings.cpp
@@ -550,6 +550,15 @@ docstring const uppercase(docstring const & a)
  }
+string capitalize(string const & s)
+{
+       string ret = s;
+       char t = uppercase(ret[0]);
+       ret[0] = t;
+       return ret;
+}
+
+
  docstring capitalize(docstring const & s) {
        docstring ret = s;
        char_type t = uppercase(ret[0]);
diff --git a/src/support/lstrings.h b/src/support/lstrings.h
index 715d9b0b02..07888c6b3a 100644
--- a/src/support/lstrings.h
+++ b/src/support/lstrings.h
@@ -181,6 +181,9 @@ docstring const token(docstring const & a, char_type delim, 
int n);
  int tokenPos(std::string const & a, char delim, std::string const & tok);
  int tokenPos(docstring const & a, char_type delim, docstring const & tok);
+///
+std::string capitalize(std::string const & s);
+
  ///
  docstring capitalize(docstring const & s);


--
----------------------------
Richard Kimberly (Riki) Heck
Professor of Philosophy and Professor of Linguistics
Brown University

Pronouns: they/them/their
Website:  http://rkheck.frege.org/

--
lyx-devel mailing list
lyx-devel@lists.lyx.org
https://lists.lyx.org/mailman/listinfo/lyx-devel

Reply via email to