commit c9f3dc2abd68ed5a27733f38e9f9e30d8074780e
Author: Juergen Spitzmueller <[email protected]>
Date: Sun May 4 09:10:40 2025 +0200
We have the means to provide localization for prettyref, so why not do it?
The only reason is that this might overwrite existing definitions
of users. Hence, we provide this as an opt-in in a separate
cross-ref format.
File format change.
---
development/FORMAT | 4 ++
lib/doc/UserGuide.lyx | 114 ++++++++++++++++++++++++++++++++-------
lib/doc/de/UserGuide.lyx | 41 +++++++++++---
lib/lyx2lyx/lyx_2_5.py | 11 +++-
src/LaTeXFeatures.cpp | 104 ++++++++++++++++++++++++-----------
src/frontends/qt/GuiDocument.cpp | 3 +-
src/frontends/qt/GuiRef.cpp | 2 +-
src/insets/InsetRef.cpp | 13 ++---
src/mathed/InsetMathRef.cpp | 2 +-
src/version.h | 4 +-
10 files changed, 229 insertions(+), 69 deletions(-)
diff --git a/development/FORMAT b/development/FORMAT
index ff9522395e..de2a79330c 100644
--- a/development/FORMAT
+++ b/development/FORMAT
@@ -7,6 +7,10 @@ changes happened in particular if possible. A good example
would be
-----------------------
+2025-05-04 Jürgen Spitzmüller <[email protected]>
+ * Format incremented to 640: Add \crossref_package prettyref-l7n which
adds
+ missing definitions and localization to prettyref.
+
2025-04-27 Jürgen Spitzmüller <[email protected]>
* Format incremented to 639: Adapt local layout for acknowledgement
theorems
to new layout scheme.
diff --git a/lib/doc/UserGuide.lyx b/lib/doc/UserGuide.lyx
index fd49f84f92..006541faa9 100644
--- a/lib/doc/UserGuide.lyx
+++ b/lib/doc/UserGuide.lyx
@@ -1,5 +1,5 @@
#LyX 2.5 created this file. For more info see https://www.lyx.org/
-\lyxformat 638
+\lyxformat 640
\begin_document
\begin_header
\save_transient_properties true
@@ -32167,12 +32167,47 @@ Note that
\series bold
prettyref
\series default
- supports only English documents
-\change_inserted -712698321 1742721720
- (unless you add your own settings)
+
+\change_inserted -712698321 1746342171
+by default (the
+\begin_inset Quotes eld
+\end_inset
+
+unlocalized
+\begin_inset Quotes erd
+\end_inset
+
+ version in \SpecialChar LyX
+)
+\change_unchanged
+supports only English documents
+\change_inserted -712698321 1746341955
+ (unless you add your own settings),
+ but \SpecialChar LyX
+ can generate localized definitions for many languages if you select
+\begin_inset Quotes eld
+\end_inset
+
+prettyref and varioref
+\begin_inset Quotes erd
+\end_inset
+
+.
+ Note that this might override your own definitions in the preamble or a style
file
\change_unchanged
.
- The format is specified by using the command
+
+\change_inserted -712698321 1746341975
+If you want,
+ or need,
+ to generate your own string,
+
+\change_deleted -712698321 1746341975
+T
+\change_inserted -712698321 1746341976
+t
+\change_unchanged
+he format is specified by using the command
\series bold
\backslash
@@ -32247,8 +32282,33 @@ prettyref
\series bold
refstyle
\series default
-predefines reference formats for all available types.
- This is especially true for the wide variety of mathematical
+predefine
+\change_deleted -712698321 1746342318
+s
+\change_unchanged
+ reference formats for all
+\change_deleted -712698321 1746342336
+available
+\change_inserted -712698321 1746342337
+possible
+\change_unchanged
+ types
+\change_inserted -712698321 1746342362
+,
+ although a wide range is defined automatically by \SpecialChar LyX
+ (
+\change_deleted -712698321 1746342365
+.
+ This is especially true
+\change_inserted -712698321 1746342368
+e.
+\begin_inset space \thinspace{}
+\end_inset
+
+g.,
+
+\change_unchanged
+ for the wide variety of mathematical
\change_inserted -712698321 1742722007
\begin_inset Quotes els
@@ -32270,20 +32330,24 @@ theorem
\change_unchanged
environments
\change_inserted -712698321 1742722033
- (cleveref is more
-\begin_inset Quotes els
-\end_inset
-
-clever
-\begin_inset Quotes ers
-\end_inset
-
- here)
+)
\change_unchanged
.
- So if you want to make formatted references to,
+
+\change_deleted -712698321 1746342379
+So i
+\change_inserted -712698321 1746342379
+I
+\change_unchanged
+f you want to make formatted references to,
say,
- Propositions,
+
+\change_deleted -712698321 1746342403
+Propositions
+\change_inserted -712698321 1746342408
+MyType
+\change_unchanged
+,
then you will need to define the relevant format yourself.
For
\series bold
@@ -32299,7 +32363,19 @@ prettyref
\backslash
newref\SpecialChar ligaturebreak
-format{prop}{Proposition
+format{
+\change_deleted -712698321 1746342414
+prop
+\change_inserted -712698321 1746342415
+mythype
+\change_unchanged
+}{
+\change_deleted -712698321 1746342418
+Proposition
+\change_inserted -712698321 1746342420
+My Type
+\change_unchanged
+
\backslash
ref{#1}}
\series default
diff --git a/lib/doc/de/UserGuide.lyx b/lib/doc/de/UserGuide.lyx
index f17b07152d..bee7bcd910 100644
--- a/lib/doc/de/UserGuide.lyx
+++ b/lib/doc/de/UserGuide.lyx
@@ -1,5 +1,5 @@
#LyX 2.5 created this file. For more info see https://www.lyx.org/
-\lyxformat 638
+\lyxformat 640
\begin_document
\begin_header
\save_transient_properties true
@@ -30901,8 +30901,31 @@ refstyle
\series bold
prettyref
\series default
- von Haus aus nur englische Dokumente unterstützt (Sie können aber
Definitionen in Ihrer Sprache in die Präambel eingeben).
- Das Format wird festgelegt,
+ von Haus aus (die
+\begin_inset Quotes gld
+\end_inset
+
+nicht-lokalisierte
+\begin_inset Quotes grd
+\end_inset
+
+ Variante in \SpecialChar LyX
+) nur englische Dokumente unterstützt (Sie können aber Definitionen in Ihrer
Sprache in die Präambel eingeben).
+ \SpecialChar LyX
+ konstruiert aber automatisch Definitionen für viele Sprachen,
+ wenn Sie
+\begin_inset Quotes gld
+\end_inset
+
+Prettyref und Varioref
+\begin_inset Quotes grd
+\end_inset
+
+ auswählen.
+ Beachten Sie aber,
+ dass dies vorhandene Definitionenn im Vorspann oder in Stildateien
überschreiben kann.
+ Falls Sie eigene Definitionen wollen oder brauchen,
+ können Sie das Format festlegen,
indem der Befehl
\series bold
@@ -30972,8 +30995,10 @@ prettyref
\series bold
refstyle
\series default
- Formate für alle verfügbarren Typen von Verweisen vordefiniert.
- Dies trifft insbesondere auf viele der verfügbaren mathematischer
+ Formate für alle möglichen Typen von Verweisen vordefiniert,
+ auch wenn \SpecialChar LyX
+ eine ganze Bandbreite von Typen automatisch definieren kann (bspw.
+ alle verfügbaren mathematischen
\begin_inset Quotes gls
\end_inset
@@ -30981,8 +31006,8 @@ Theorem
\begin_inset Quotes grs
\end_inset
--Umgebungen zu (cleveref ist hier cleverer).
- Sollten Sie also formatierte Querverweise beispielsweise auf (mathematische)
Sätze machen wollen,
+-Umgebungen).
+ Sollten Sie formatierte Querverweise beispielsweise auf nicht unterstützte
Umgebungen machen wollen,
müssen Sie das relevante Format selbst definieren.
Für
\series bold
@@ -31000,7 +31025,7 @@ so aussehen:
\series bold
\backslash
-newrefformat{prop}{Satz
+newrefformat{mytype}{My Type
\backslash
ref{#1}}
\series default
diff --git a/lib/lyx2lyx/lyx_2_5.py b/lib/lyx2lyx/lyx_2_5.py
index 3a738d5db3..1ef0cd8249 100644
--- a/lib/lyx2lyx/lyx_2_5.py
+++ b/lib/lyx2lyx/lyx_2_5.py
@@ -3130,6 +3130,13 @@ def revert_theorem_local_def(document):
if document.del_local_layout(ack_theorem_def_new):
document.append_local_layout(ack_theorem_def_old)
+
+def revert_prettyref_l7n(document):
+ """Revert prettyref-l7n crossref format to prettyref"""
+ i = find_token(document.header, "\\crossref_package prettyref-l7n", 0)
+ if i != -1:
+ document.header[i] = "\\crossref_package prettyref"
+
##
# Conversion hub
#
@@ -3154,11 +3161,13 @@ convert = [
[636, []],
[637, []],
[638, []],
- [639, [convert_theorem_local_def]]
+ [639, [convert_theorem_local_def]],
+ [640, []]
]
revert = [
+ [639, [revert_prettyref_l7n]],
[638, [revert_theorem_local_def]],
[637, [revert_xr]],
[636, [revert_reflists]],
diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp
index ca08dfbbf1..a1c8ac606c 100644
--- a/src/LaTeXFeatures.cpp
+++ b/src/LaTeXFeatures.cpp
@@ -2231,6 +2231,23 @@ 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") {
+ 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()) {
@@ -2260,11 +2277,14 @@ docstring const LaTeXFeatures::getThmI18nDefs(Layout
const & lay) const
docstring const tnp = from_utf8(lay.thmXRefNamePl());
odocstringstream ods;
docstring const thmname = from_utf8(lay.thmName());
- ods << "\\crefname{" << thmname << "}{_(" << lowercase(tn) <<
")}{" << lowercase(tnp) << "}\n"
- << "\\Crefname{" << thmname << "}{_(" << tn << ")}{" << tnp
<< "}\n";
ods << "\\crefname{" << thmname << "}{_(" << lowercase(tn) <<
")}{_(" << lowercase(tnp) << ")}\n"
<< "\\Crefname{" << thmname << "}{_(" << tn << ")}{_(" <<
tnp << ")}\n";
return ods.str();
+ } else if (params_.xref_package == "prettyref-l7n" &&
!lay.thmXRefName().empty()) {
+ odocstringstream ods;
+ docstring const thmname = from_utf8(lay.thmName());
+ ods << "\\newrefformat{" << lay.refprefix << "}{_(" <<
from_utf8(lay.thmXRefName()) << ") \\ref{#1}}\n";
+ return ods.str();
}
return docstring();
}
@@ -2315,40 +2335,64 @@ docstring const
LaTeXFeatures::getTClassI18nPreamble(bool use_babel,
}
}
}
- if ((use_babel || use_polyglossia) && !UsedLanguages_.empty()) {
+ if ((use_babel || use_polyglossia)) {
FloatList const & floats = params_.documentClass().floats();
UsedFloats::const_iterator fit = usedFloats_.begin();
UsedFloats::const_iterator fend = usedFloats_.end();
for (; fit != fend; ++fit) {
Floating const & fl = floats.getType(fit->first);
- // we assume builtin floats are translated
- if (fl.isPredefined())
- continue;
- docstring const type = from_ascii(fl.floattype());
- docstring const flname = from_utf8(fl.name());
- docstring name =
buffer().language()->translateLayout(fl.name());
- // only request translation if we have a real
translation
- // (that differs from the source)
- if (flname != name)
- snippets.insert(getFloatI18nPreamble(
- type, name, buffer().language(),
- buffer().params().encoding(),
- use_polyglossia));
- for (lang_it lit = lbeg; lit != lend; ++lit) {
- string const code = (*lit)->code();
- name = (*lit)->translateLayout(fl.name());
- // we assume we have a suitable translation if
- // either the language is English (we need to
- // translate into English if English is a
secondary
- // language) or if translateIfPossible returns
- // something different to the English source.
- bool const have_translation =
- (flname != name || contains(code,
"en"));
- if (have_translation)
+ // construct prettyref definitions if required
+ docstring prettyreffloatdefs;
+ if (params_.xref_package == "prettyref-l7n") {
+ odocstringstream ods;
+ if (fl.refPrefix() == "alg")
+ ods << "\\newrefformat{" <<
from_ascii(fl.refPrefix()) << "}{_(Algorithm) \\ref{#1}}\n";
+ if (fl.refPrefix() == "fig")
+ ods << "\\newrefformat{" <<
from_ascii(fl.refPrefix()) << "}{_(Figure) \\ref{#1}}\n";
+ if (fl.refPrefix() == "tab")
+ ods << "\\newrefformat{" <<
from_ascii(fl.refPrefix()) << "}{_(Table) \\ref{#1}}\n";
+ prettyreffloatdefs = ods.str();
+ if (!prettyreffloatdefs.empty())
+
snippets.insert(i18npreamble(prettyreffloatdefs,
+
buffer().language(),
+
buffer().params().encoding(),
+
use_polyglossia, false));
+ }
+ if (!UsedLanguages_.empty()) {
+ // we assume builtin floats are translated
+ if (fl.isPredefined())
+ continue;
+ docstring const type =
from_ascii(fl.floattype());
+ docstring const flname = from_utf8(fl.name());
+ docstring name =
buffer().language()->translateLayout(fl.name());
+ // only request translation if we have a real
translation
+ // (that differs from the source)
+ if (flname != name)
snippets.insert(getFloatI18nPreamble(
- type, name, *lit,
- buffer().params().encoding(),
- use_polyglossia));
+ type, name,
buffer().language(),
+
buffer().params().encoding(),
+ use_polyglossia));
+ for (lang_it lit = lbeg; lit != lend; ++lit) {
+ string const code = (*lit)->code();
+ name =
(*lit)->translateLayout(fl.name());
+ // we assume we have a suitable
translation if
+ // either the language is English (we
need to
+ // translate into English if English is
a secondary
+ // language) or if translateIfPossible
returns
+ // something different to the English
source.
+ bool const have_translation =
+ (flname != name ||
contains(code, "en"));
+ if (have_translation)
+
snippets.insert(getFloatI18nPreamble(
+ type, name, *lit,
+
buffer().params().encoding(),
+ use_polyglossia));
+ if (!prettyreffloatdefs.empty())
+
snippets.insert(i18npreamble(prettyreffloatdefs,
+
*lit,
+
buffer().params().encoding(),
+
use_polyglossia, false));
+ }
}
}
}
diff --git a/src/frontends/qt/GuiDocument.cpp b/src/frontends/qt/GuiDocument.cpp
index 018453f2a2..441f8f470b 100644
--- a/src/frontends/qt/GuiDocument.cpp
+++ b/src/frontends/qt/GuiDocument.cpp
@@ -1675,7 +1675,8 @@ GuiDocument::GuiDocument(GuiView & lv)
latexModule->childDocLE));
latexModule->xrefPackageCO->addItem(qt_("Cleveref and varioref"),
toqstr("cleveref"));
- latexModule->xrefPackageCO->addItem(qt_("Prettyref and varioref"),
toqstr("prettyref"));
+ latexModule->xrefPackageCO->addItem(qt_("Prettyref (unlocalized) and
varioref"), toqstr("prettyref"));
+ latexModule->xrefPackageCO->addItem(qt_("Prettyref and varioref"),
toqstr("prettyref-l7n"));
latexModule->xrefPackageCO->addItem(qt_("Refstyle and varioref"),
toqstr("refstyle"));
latexModule->xrefPackageCO->addItem(qt_("Zref-clever and zref-vario"),
toqstr("zref"));
diff --git a/src/frontends/qt/GuiRef.cpp b/src/frontends/qt/GuiRef.cpp
index 06138693e8..1df59b15d0 100644
--- a/src/frontends/qt/GuiRef.cpp
+++ b/src/frontends/qt/GuiRef.cpp
@@ -169,7 +169,7 @@ void GuiRef::enableBoxes()
{
QString const reftype =
typeCO->itemData(typeCO->currentIndex()).toString();
- bool const use_prettyref = buffer().params().xref_package ==
"prettyref";
+ bool const use_prettyref = prefixIs(buffer().params().xref_package,
"prettyref");
bool const use_refstyle = buffer().params().xref_package == "refstyle";
bool const use_cleveref = buffer().params().xref_package == "cleveref";
bool const use_zref = buffer().params().xref_package == "zref";
diff --git a/src/insets/InsetRef.cpp b/src/insets/InsetRef.cpp
index b7b3c8327e..abbcd7681d 100644
--- a/src/insets/InsetRef.cpp
+++ b/src/insets/InsetRef.cpp
@@ -241,7 +241,7 @@ docstring InsetRef::getFormattedCmd(docstring const & ref,
defcmd += "range";
} else if (xref_package == "zref")
defcmd = from_ascii("\\zcref");
- else if (xref_package == "prettyref")
+ else if (prefixIs(xref_package, "prettyref"))
defcmd = from_ascii("\\prettyref");
bool have_cmd = false;
@@ -377,7 +377,7 @@ void InsetRef::latex(otexstream & os, OutputParams const &
rp) const
vector<docstring>::const_iterator en = flabels.end();
for (size_t i = 0; it != en; ++it, ++i) {
if (!first) {
- if (buffer().masterParams().xref_package ==
"prettyref") {
+ if
(prefixIs(buffer().masterParams().xref_package, "prettyref")) {
os << "}";
if (flabels.size() == 2)
os << buffer().B_("[[reference
1]] and [[reference2]]");
@@ -391,12 +391,12 @@ void InsetRef::latex(otexstream & os, OutputParams const
& rp) const
else
os << ",";
}
- if (contains(*it, ' ') &&
buffer().masterParams().xref_package != "prettyref")
+ if (contains(*it, ' ') &&
!prefixIs(buffer().masterParams().xref_package, "prettyref"))
// refstyle bug: labels with blanks need to be
grouped
// otherwise the blanks will be gobbled
os << "{" << *it << "}";
else {
- if (buffer().masterParams().xref_package ==
"prettyref" && !contains(*it, ':'))
+ if
(prefixIs(buffer().masterParams().xref_package, "prettyref") && !contains(*it,
':'))
// warn on invalid label
frontend::Alert::warning(_("Invalid
label!"),
bformat(_("The
label `%1$s' does not have a prefix (e.g., `sec:'), "
@@ -684,7 +684,8 @@ docstring InsetRef::displayString(docstring const & ref,
string const & cmd,
docstring res = (useRange()) ? getStringFromVector(display_string,
from_utf8("–"))
: getStringFromVector(display_string,
from_ascii(", "));
- if (cmd == "formatted" && buffer().params().xref_package != "prettyref"
&& getParam("caps") == "true")
+ if (cmd == "formatted" && !prefixIs(buffer().params().xref_package,
"prettyref")
+ && getParam("caps") == "true")
return capitalize(res);
// it is hard to see what to do about plurals...
@@ -1001,7 +1002,7 @@ bool InsetRef::useRange() const
if (getLabels().size() != 2 || getParam("tuple") == "list")
return false;
return cmd == "vref" || cmd == "vpageref"
- || (cmd == "formatted" && buffer().masterParams().xref_package
!= "prettyref")
+ || (cmd == "formatted" &&
!(buffer().masterParams().xref_package, "prettyref"))
|| (cmd == "cpageref");
}
diff --git a/src/mathed/InsetMathRef.cpp b/src/mathed/InsetMathRef.cpp
index 7e3e166b06..ec57bfa6d0 100644
--- a/src/mathed/InsetMathRef.cpp
+++ b/src/mathed/InsetMathRef.cpp
@@ -360,7 +360,7 @@ void InsetMathRef::write(TeXMathStream & os) const
os << '(' << from_ascii("\\ref{") << cell(0) <<
from_ascii("})");
}
else if (cmd == "formatted") {
- if (buffer_ && buffer().params().xref_package == "prettyref")
+ if (buffer_ &&
support::prefixIs(buffer().params().xref_package, "prettyref"))
os << "\\prettyref{" << cell(0) << "}";
else {
odocstringstream ods;
diff --git a/src/version.h b/src/version.h
index 0e17285463..d3cc200529 100644
--- a/src/version.h
+++ b/src/version.h
@@ -32,8 +32,8 @@ extern char const * const lyx_version_info;
// Do not remove the comment below, so we get merge conflict in
// independent branches. Instead add your own.
-#define LYX_FORMAT_LYX 639 // spitz: new theorem backend
-#define LYX_FORMAT_TEX2LYX 639
+#define LYX_FORMAT_LYX 640 // spitz: prettyref-l7n
+#define LYX_FORMAT_TEX2LYX 640
#if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
#ifndef _MSC_VER
--
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs