commit 1eb8713f9a891e0c175d0eed4798c20974c21c68
Author: Juergen Spitzmueller <[email protected]>
Date:   Thu Aug 14 15:14:44 2025 +0200

    Implement formatted reference to itemize item ("enu:")
    
    This is already supported by cleveref and zref
    
    refstyle produced an error
---
 lib/layouts/stdcounters.inc |  8 ++---
 lib/layouts/stdlists.inc    |  4 +++
 src/LaTeXFeatures.cpp       | 74 ++++++++++++++++++++++++++++++++++-----------
 src/LaTeXFeatures.h         |  2 ++
 src/insets/InsetRef.cpp     |  4 ++-
 5 files changed, 69 insertions(+), 23 deletions(-)

diff --git a/lib/layouts/stdcounters.inc b/lib/layouts/stdcounters.inc
index cb818eb953..02fdaf41f0 100644
--- a/lib/layouts/stdcounters.inc
+++ b/lib/layouts/stdcounters.inc
@@ -49,28 +49,28 @@ End
 Counter enumi
        GuiName "Numbered List (Level 1)"
        LabelString          "\arabic{enumi}."
-       PrettyFormat         "(\arabic{enumi})"
+       PrettyFormat         "Item \arabic{enumi}"
 End
 
 Counter enumii
        GuiName "Numbered List (Level 2)"
        Within               enumi
        LabelString          "(\alph{enumii})"
-       PrettyFormat         "(\alph{enumii})"
+       PrettyFormat         "Item \arabic{enumi}\alph{enumii}"
 End
 
 Counter enumiii
        GuiName "Numbered List (Level 3)"
        Within               enumii
        LabelString          "\roman{enumiii}."
-       PrettyFormat         "(\roman{enumiii})"
+       PrettyFormat         "Item \arabic{enumi}(\alph{enumii})\roman{enumiii}"
 End
 
 Counter enumiv
        GuiName "Numbered List (Level 4)"
        Within               enumiii
        LabelString          "\Alph{enumiv}."
-       PrettyFormat         "(\Alph{enumiv})"
+       PrettyFormat         "Item 
\arabic{enumi}(\alph{enumii})\roman{enumiii}\Alph{enumiv}"
 End
 
 Counter bibitem
diff --git a/lib/layouts/stdlists.inc b/lib/layouts/stdlists.inc
index db2bce5c8c..a7da240ecb 100644
--- a/lib/layouts/stdlists.inc
+++ b/lib/layouts/stdlists.inc
@@ -71,6 +71,10 @@ Style Enumerate
        HTMLItem              li
        HTMLLabel             NONE
        RefPrefix             enu
+       # FIXME This is a workaround to get this into l7n
+       # Implement a dedicated tag
+       TheoremCrossRefName   "Item[[enumerate]]"
+       TheoremCrossRefPluralName "Items[[enumerate]]"
        Argument item:1
                LabelString   "Custom Item|s"
                Tooltip       "A customized item string"
diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp
index f076d917ea..ee3db69ca3 100644
--- a/src/LaTeXFeatures.cpp
+++ b/src/LaTeXFeatures.cpp
@@ -1832,6 +1832,22 @@ TexString LaTeXFeatures::getMacros() const
                       << '\n';
        }
 
+       if (mustProvide("refstyle:enuref")) {
+               // this is not provided by the package, but we use the prefix
+               macros << "\\RS@ifundefined{enuref}{\n"
+                      << "  \\newref{enu}{\n"
+                      << "        name      = \\RSenutxt,\n"
+                      << "        names     = \\RSenustxt,\n"
+                      << "        Name      = \\RSEnutxt,\n"
+                      << "        Names     = \\RSEnustxt,\n"
+                      << "        rngtxt    = \\RSrngtxt,\n"
+                      << "        lsttwotxt = \\RSlsttwotxt,\n"
+                      << "        lsttxt    = \\RSlsttxt\n"
+                      << "  }\n"
+                      << "}{}\n"
+                      << '\n';
+       }
+
        if (mustProvide("cleveref:cpagereffix")) {
                macros << "% Fix for pending cleveref bug: 
https://tex.stackexchange.com/a/620066/105447\n";
                        << 
"\\newcommand*{\\@setcpagerefrange}[3]{\\@@setcpagerefrange{#1}{#2}{cref}{#3}}\n"
@@ -2266,23 +2282,6 @@ docstring const i18npreamble(docstring const & templ, 
Language const * lang,
 
 docstring const LaTeXFeatures::getThmI18nDefs(Layout const & lay) const
 {
-       // For prettyref, we also do the other layout defs here
-       if (params_.xref_package == "prettyref-l7n" && isRequired("prettyref")) 
{
-               odocstringstream ods;
-               if (lay.refprefix == "part")
-                       ods << "\\newrefformat{" << lay.refprefix << 
"}{_(Part)~\\ref{#1}}\n";
-               if (lay.refprefix == "cha")
-                       ods << "\\newrefformat{" << lay.refprefix << 
"}{_(Chapter)~\\ref{#1}}\n";
-               if (lay.refprefix == "sec" || lay.refprefix == "subsec" || 
lay.refprefix == "sub")
-                       ods << "\\newrefformat{" << lay.refprefix << 
"}{_(Section)~\\ref{#1}}\n";
-               if (lay.refprefix == "par")
-                       ods << 
"\\newrefformat{alg}{_(Paragraph[[Sectioning]])~\\ref{#1}}\n";
-               if (lay.refprefix == "fn")
-                       ods << "\\newrefformat{alg}{_(Footnote)~\\ref{#1}}\n";
-               if (!ods.str().empty())
-                       return ods.str();
-       }
-       // Otherwise only handle theorems
        if (lay.thmName().empty())
                return docstring();
        if (params_.xref_package == "zref" && lay.thmZRefName() == "none" && 
!lay.thmXRefName().empty()
@@ -2326,6 +2325,39 @@ docstring const LaTeXFeatures::getThmI18nDefs(Layout 
const & lay) const
 }
 
 
+docstring const LaTeXFeatures::getXRefI18nDefs(Layout const & lay) const
+{
+       if (params_.xref_package == "prettyref-l7n" && isRequired("prettyref")) 
{
+               odocstringstream ods;
+               if (lay.refprefix == "part")
+                       ods << "\\newrefformat{" << lay.refprefix << 
"}{_(Part)~\\ref{#1}}\n";
+               else if (lay.refprefix == "cha")
+                       ods << "\\newrefformat{" << lay.refprefix << 
"}{_(Chapter)~\\ref{#1}}\n";
+               else if (lay.refprefix == "sec" || lay.refprefix == "subsec" || 
lay.refprefix == "sub")
+                       ods << "\\newrefformat{" << lay.refprefix << 
"}{_(Section)~\\ref{#1}}\n";
+               else if (lay.refprefix == "par")
+                       ods << 
"\\newrefformat{alg}{_(Paragraph[[Sectioning]])~\\ref{#1}}\n";
+               else if (lay.refprefix == "fn")
+                       ods << "\\newrefformat{alg}{_(Footnote)~\\ref{#1}}\n";
+               else if (lay.refprefix == "enu")
+                       ods << 
"\\newrefformat{enu}{_(Item[[enumerate]])~\\ref{#1}}\n";
+               if (!ods.str().empty())
+                       return ods.str();
+       } else if (params_.xref_package == "refstyle" && 
isRequired("refstyle:enuref")) {
+               docstring const tn = from_ascii("Item[[enumerate]]");
+               docstring const tnp = from_ascii("Items[[enumerate]]");
+               odocstringstream ods;
+               docstring const prfxname = from_ascii("enu");
+               ods << "\\def\\RS" << prfxname << "txt{_(" << lowercase(tn) << 
")~}\n"
+                   << "\\def\\RS" << prfxname << "stxt{_(" << lowercase(tnp) 
<< ")~}\n"
+                   << "\\def\\RS" << capitalize(prfxname) << "txt{_(" << tn << 
")~}\n"
+                   << "\\def\\RS" << capitalize(prfxname) << "stxt{_(" << tnp 
<< ")~}\n";
+               return ods.str();
+       }
+       return docstring();
+}
+
+
 docstring const LaTeXFeatures::getTClassI18nPreamble(bool use_babel,
                                bool use_polyglossia, bool use_minted) const
 {
@@ -2339,12 +2371,18 @@ docstring const 
LaTeXFeatures::getTClassI18nPreamble(bool use_babel,
        list<docstring>::const_iterator cit = usedLayouts_.begin();
        list<docstring>::const_iterator end = usedLayouts_.end();
        for (; cit != end; ++cit) {
-               docstring const thmxref = getThmI18nDefs(tclass[*cit]);
                // language dependent commands (once per document)
                snippets.insert(i18npreamble(tclass[*cit].langpreamble(),
                                                buffer().language(),
                                                buffer().params().encoding(),
                                                use_polyglossia, false));
+               docstring const xxref = getXRefI18nDefs(tclass[*cit]);
+               if (!xxref.empty())
+                       snippets.insert(i18npreamble(xxref,
+                                                    buffer().language(),
+                                                    
buffer().params().encoding(),
+                                                    use_polyglossia, false));
+               docstring const thmxref = getThmI18nDefs(tclass[*cit]);
                if (!thmxref.empty())
                        snippets.insert(i18npreamble(thmxref,
                                                     buffer().language(),
diff --git a/src/LaTeXFeatures.h b/src/LaTeXFeatures.h
index ba6eb0062c..bb7d510b34 100644
--- a/src/LaTeXFeatures.h
+++ b/src/LaTeXFeatures.h
@@ -91,6 +91,8 @@ public:
        docstring const getTClassPreamble() const;
        /// Localizations for theorem reference defs
        docstring const getThmI18nDefs(Layout const &) const;
+       /// Localizations for extra reference defs
+       docstring const getXRefI18nDefs(Layout const &) const;
        /// The language dependent definitions needed by the document's 
textclass
        docstring const getTClassI18nPreamble(bool use_babel,
                                bool use_polyglossia, bool use_minted) const;
diff --git a/src/insets/InsetRef.cpp b/src/insets/InsetRef.cpp
index 35a90ea791..a39dbed7e5 100644
--- a/src/insets/InsetRef.cpp
+++ b/src/insets/InsetRef.cpp
@@ -985,8 +985,10 @@ void InsetRef::validate(LaTeXFeatures & features) const
                        features.require("refstyle");
                        if (prefix == "cha")
                                
features.addPreambleSnippet(from_ascii("\\let\\charef=\\chapref"));
-                       else if (prefix == "subsec")
+                       else if (prefix == "subsec" || prefix == "Subsec")
                                features.require("refstyle:subsecref");
+                       else if (prefix == "enu" || prefix == "Enu")
+                               features.require("refstyle:enuref");
                        else if (!prefix.empty() && 
!buffer().masterParams().documentClass().hasRefPrefix(prefix)) {
                                // fallback command for unknown prefixes
                                docstring lcmd = 
"\\AtBeginDocument{\\providecommand" +
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to