commit 5f59637c924578a587eb6ea34077d93116fa29a9
Author: Juergen Spitzmueller <[email protected]>
Date:   Sun Mar 23 11:02:04 2025 +0100

    Add (basic) support for the cleveref package (#11637)
---
 development/FORMAT               |  11 ++
 lib/chkconfig.ltx                |   1 +
 lib/doc/LaTeXConfig.lyx          | 156 +++++++++++++++++++------
 lib/doc/UserGuide.lyx            | 243 +++++++++++++++++++++++++++++++++++++--
 lib/doc/de/UserGuide.lyx         | 147 ++++++++++++++++++++---
 lib/lyx2lyx/lyx_2_5.py           |  67 ++++++++++-
 src/BufferParams.cpp             |   8 ++
 src/frontends/qt/GuiDocument.cpp |   1 +
 src/frontends/qt/GuiRef.cpp      |  18 ++-
 src/insets/InsetRef.cpp          |  57 +++++----
 src/insets/InsetRef.h            |   3 +-
 src/mathed/InsetMathRef.cpp      |   4 +-
 src/tex2lyx/Preamble.cpp         |   6 +-
 src/tex2lyx/text.cpp             |  22 +++-
 src/version.h                    |   4 +-
 15 files changed, 652 insertions(+), 96 deletions(-)

diff --git a/development/FORMAT b/development/FORMAT
index 0bbfc014b0..4ee108bf48 100644
--- a/development/FORMAT
+++ b/development/FORMAT
@@ -7,6 +7,17 @@ changes happened in particular if possible. A good example 
would be
 
 -----------------------
 
+2025-03-23 Jürgen Spitzmüller <[email protected]>
+       * Format incremented to 636: Support for the cleveref package
+         \crossref_package cleveref
+         With CommandInset ref:
+         * LatexCommand formatted: \cref
+           + caps "true": \Cref
+           + nolink "true": \cref*, \Cref*
+         * LatexCommand nameref: \namecref
+           + caps "true": \nameCref
+           + plural "true": \namecrefs, \nameCrefs
+
 2025-03-22 Jürgen Spitzmüller <[email protected]>
        * Format incremented to 635:  Rename buffer param \use_refstyle to 
\crossref_package
          that takes a string ("prettyref" or "refstyle") rather than a boolean 
value.
diff --git a/lib/chkconfig.ltx b/lib/chkconfig.ltx
index 7f46c7b09f..5d9e076d46 100644
--- a/lib/chkconfig.ltx
+++ b/lib/chkconfig.ltx
@@ -333,6 +333,7 @@
 \TestPackage{chessboard}
 \TestPackage{chessfss}
 \TestPackage{chicago}
+\TestPackage{cleveref}
 \TestPackage{color} % this one should be there if graphics.sty is there.
 \TestPackageAddVersion{colortbl}
 \TestPackage{covington}
diff --git a/lib/doc/LaTeXConfig.lyx b/lib/doc/LaTeXConfig.lyx
index c2bf3345a8..3b7a1ce0fe 100644
--- a/lib/doc/LaTeXConfig.lyx
+++ b/lib/doc/LaTeXConfig.lyx
@@ -1,5 +1,5 @@
-#LyX 2.4 created this file. For more info see https://www.lyx.org/
-\lyxformat 620
+#LyX 2.5 created this file. For more info see https://www.lyx.org/
+\lyxformat 636
 \begin_document
 \begin_header
 \save_transient_properties true
@@ -53,10 +53,18 @@
 \paperorientation portrait
 \suppress_date false
 \justification true
-\use_refstyle 0
+\crossref_package prettyref
 \use_formatted_ref 0
 \use_minted 0
 \use_lineno 0
+\backgroundcolor none
+\fontcolor none
+\notefontcolor lightgray
+\boxbgcolor red
+\table_border_color default
+\table_odd_row_color default
+\table_even_row_color default
+\table_alt_row_colors_start 1
 \index Index
 \shortcut idx
 \color #008000
@@ -82,6 +90,7 @@
 \html_be_strict true
 \docbook_table_output 0
 \docbook_mathml_prefix 1
+\docbook_mathml_version 0
 \html_latex_start <span class='latex'>
 \html_latex_end </span>
 \end_header
@@ -2906,7 +2915,6 @@ Publications of the Astronomical Society of the Pacific
 status open
 
 \begin_layout Plain Layout
-
 https://journals.aas.org/authors/aastex/aastex.html
 \end_layout
 
@@ -2972,7 +2980,6 @@ WWW:
 status collapsed
 
 \begin_layout Plain Layout
-
 https://www.aeaweb.org/templates/latex_templates.zip
 \end_layout
 
@@ -3038,7 +3045,6 @@ AEA-\SpecialChar LaTeX
 status collapsed
 
 \begin_layout Plain Layout
-
 https://www.aeaweb.org/journals/aer/submissions/accepted-articles/styleguide
 \end_layout
 
@@ -3285,7 +3291,6 @@ WWW:
 status collapsed
 
 \begin_layout Plain Layout
-
 https://sgmltools-lite.sourceforge.net
 \end_layout
 
@@ -3364,7 +3369,6 @@ WWW:
 status collapsed
 
 \begin_layout Plain Layout
-
 https://www.dante.de
 \end_layout
 
@@ -3445,7 +3449,6 @@ WWW:
 status collapsed
 
 \begin_layout Plain Layout
-
 https://www.elsevier.com/authors/author-schemas/latex-instructions
 \end_layout
 
@@ -3487,7 +3490,6 @@ WWW:
 status collapsed
 
 \begin_layout Plain Layout
-
 https://www.entcs.org/generic.zip
 \end_layout
 
@@ -3910,7 +3912,6 @@ IEEEtran
 status collapsed
 
 \begin_layout Plain Layout
-
 https://www.ieee.org
 \end_layout
 
@@ -3976,7 +3977,6 @@ WWW:
 status collapsed
 
 \begin_layout Plain Layout
-
 https://www.worldscientific.com/page/ijmpc/submission-guidelines
 \end_layout
 
@@ -4022,7 +4022,6 @@ WWW:
 status collapsed
 
 \begin_layout Plain Layout
-
 https://www.worldscientific.com/page/ijmpd/submission-guidelines
 \end_layout
 
@@ -4068,7 +4067,6 @@ WWW:
 status collapsed
 
 \begin_layout Plain Layout
-
 https://publishingsupport.iopscience.iop.org/questions/latex-template/
 \end_layout
 
@@ -4516,7 +4514,6 @@ book
 status collapsed
 
 \begin_layout Plain Layout
-
 https://mirrors.ctan.org/macros/jptex/latex/jlreq/jlreq.pdf
 \end_layout
 
@@ -4552,7 +4549,6 @@ WWW:
 status collapsed
 
 \begin_layout Plain Layout
-
 https://www.jstatsoft.org/public/journals/1/jss-style.zip
 \end_layout
 
@@ -4597,7 +4593,6 @@ WWW:
 status collapsed
 
 \begin_layout Plain Layout
-
 http://www.wkap.nl/kaphtml.htm/STYLEFILES
 \end_layout
 
@@ -4623,7 +4618,6 @@ Astrophysics and Space Science,
 status collapsed
 
 \begin_layout Plain Layout
-
 http://www.wkap.nl/jrnllist.htm/JRNLHOME
 \end_layout
 
@@ -4909,7 +4903,6 @@ Lecture Notes in Computer Science
 status collapsed
 
 \begin_layout Plain Layout
-
 https://www.ctan.org/pkg/llncs
 \end_layout
 
@@ -4952,7 +4945,6 @@ Web:
 status open
 
 \begin_layout Plain Layout
-
 https://maa.org/publication/the-american-mathematical-monthly/
 \end_layout
 
@@ -5216,7 +5208,6 @@ WWW:
 status collapsed
 
 \begin_layout Plain Layout
-
 https://kmh-lanl.hansonhub.com/spie/
 \end_layout
 
@@ -5237,7 +5228,6 @@ spie.cls
 status collapsed
 
 \begin_layout Plain Layout
-
 https://www.ctan.org/tex-archive/macros/latex/contrib/spie
 \end_layout
 
@@ -5335,7 +5325,6 @@ Accelerators and Beams),
 status collapsed
 
 \begin_layout Plain Layout
-
 https://journals.aps.org/revtex
 \end_layout
 
@@ -5449,7 +5438,6 @@ WWW:
 status open
 
 \begin_layout Plain Layout
-
 https://www.springernature.com/gp/authors/campaigns/latex-author-support
 \end_layout
 
@@ -5514,7 +5502,6 @@ WWW:
 status collapsed
 
 \begin_layout Plain Layout
-
 http://www.springeronline.com
 \end_layout
 
@@ -5614,7 +5601,6 @@ WWW:
 status collapsed
 
 \begin_layout Plain Layout
-
 http://www.springeronline.com
 \end_layout
 
@@ -5673,7 +5659,6 @@ WWW:
 status collapsed
 
 \begin_layout Plain Layout
-
 http://www.springeronline.com
 \end_layout
 
@@ -5730,7 +5715,6 @@ WWW:
 status collapsed
 
 \begin_layout Plain Layout
-
 http://www.springeronline.com
 \end_layout
 
@@ -5778,7 +5762,6 @@ WWW:
 status collapsed
 
 \begin_layout Plain Layout
-
 http://www.springeronline.com
 \end_layout
 
@@ -5844,7 +5827,6 @@ WWW:
 status collapsed
 
 \begin_layout Plain Layout
-
 https://www.tug.org
 \end_layout
 
@@ -5888,7 +5870,6 @@ WWW:
 status collapsed
 
 \begin_layout Plain Layout
-
 
https://www.isprs.org/documents/orangebook/LATEX/ISPRSguidelines_authors_fullpaper_latex_2024_01_17.zip
 \end_layout
 
@@ -7220,7 +7201,6 @@ jurabib
 status collapsed
 
 \begin_layout Plain Layout
-
 https://sourceforge.net/projects/jurabib/
 \end_layout
 
@@ -8797,6 +8777,60 @@ cancelto
 .
 \end_layout
 
+\begin_layout Subsection
+cleveref
+\end_layout
+
+\begin_layout Description
+Found:
+ 
+\begin_inset Info
+type  "package"
+arg   "cleveref"
+\end_inset
+
+
+\end_layout
+
+\begin_layout Description
+CTAN:
+ 
+\family typewriter
+macros/latex/contrib/cleveref
+\end_layout
+
+\begin_layout Description
+Notes:
+ The package 
+\family sans
+cleveref
+\family default
+ provides commands to identify reference labels by their context and 
automatically output matching references (e.g.,
+ 
+\begin_inset Quotes eld
+\end_inset
+
+section
+\begin_inset space ~
+\end_inset
+
+3
+\begin_inset Quotes erd
+\end_inset
+
+).
+ It is an alternative approach to 
+\family sans
+prettyref
+\family default
+ and 
+\family sans
+refstyle
+\family default
+,
+ which both need a specific label prefix.
+\end_layout
+
 \begin_layout Subsection
 cprotect
 \end_layout
@@ -9611,6 +9645,64 @@ preview
  especially for math formulas when you use the option ``Instant Preview'' in 
Tools->Preferences->Look and feel->Graphics.
 \end_layout
 
+\begin_layout Subsection
+refstyle
+\end_layout
+
+\begin_layout Description
+Found:
+ 
+\begin_inset Info
+type  "package"
+arg   "refstyle"
+\end_inset
+
+
+\end_layout
+
+\begin_layout Description
+CTAN:
+ 
+\family typewriter
+macros/latex/contrib/refstyle
+\end_layout
+
+\begin_layout Description
+Notes:
+ The package 
+\family sans
+refstyle
+\family default
+ provides commands to identify reference labels by their prefixes and 
automatically output matching references (e.g.,
+ 
+\begin_inset Quotes eld
+\end_inset
+
+section
+\begin_inset space ~
+\end_inset
+
+3
+\begin_inset Quotes erd
+\end_inset
+
+).
+ \SpecialChar LyX
+ uses labels in the form 
+\begin_inset Quotes eld
+\end_inset
+
+sec:mysection
+\begin_inset Quotes erd
+\end_inset
+
+ and 
+\family sans
+refstyle
+\family default
+ interprets the "sec:" part.
+\end_layout
+
 \begin_layout Subsection
 rotating
 \end_layout
diff --git a/lib/doc/UserGuide.lyx b/lib/doc/UserGuide.lyx
index 0656266e6c..35f0a0e5d1 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 635
+\lyxformat 636
 \begin_document
 \begin_header
 \save_transient_properties true
@@ -31835,7 +31835,7 @@ reference:
 
 
 \begin_inset Note Greyedout
-status open
+status collapsed
 
 \begin_layout Plain Layout
 
@@ -31844,13 +31844,24 @@ Note:
 
 \series default
  This feature is only available when you have the \SpecialChar LaTeX
--package 
+-package
+\change_inserted -712698321 1742721528
+ 
+\series bold
+cleveref
+\series default
+,
+
+\change_unchanged
+ 
 \series bold
 prettyref
 \series default
  or 
 \series bold
 refstyle
+\change_inserted -712698321 1742721546
+
 \series default
 
 \begin_inset Index idx
@@ -31859,12 +31870,16 @@ pageformat default
 status collapsed
 
 \begin_layout Plain Layout
+
+\change_inserted -712698321 1742721546
 \SpecialChar LaTeX
  packages
 \begin_inset IndexMacro subentry
 status open
 
 \begin_layout Plain Layout
+
+\change_inserted -712698321 1742721546
 prettyref
 \end_layout
 
@@ -31876,6 +31891,8 @@ prettyref
 \end_inset
 
 
+\change_unchanged
+
 \begin_inset Index idx
 range none
 pageformat default
@@ -31888,7 +31905,36 @@ status collapsed
 status open
 
 \begin_layout Plain Layout
+prettyref
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\end_inset
+
+
+\begin_inset Index idx
+range none
+pageformat default
+status open
+
+\begin_layout Plain Layout
+\SpecialChar LaTeX
+ packages
+\begin_inset IndexMacro subentry
+status open
+
+\begin_layout Plain Layout
+
+\change_deleted -712698321 1742721549
 refstyle
+\change_inserted -712698321 1742721550
+cleveref
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -31909,8 +31955,16 @@ refstyle
 
 You can select which \SpecialChar LaTeX
 -package should be used for this feature by setting the option 
+\change_deleted -712698321 1742721596
+
 \family sans
-Use refstyle (not prettyref) for cross-references
+U
+\change_inserted -712698321 1742721595
+Format packages
+\change_deleted -712698321 1742721600
+se refstyle (not prettyref) for cross-references
+\change_unchanged
+
 \family default
  in the menu 
 \family sans
@@ -31923,11 +31977,26 @@ Document Class
 \series bold
 refstyle
 \series default
- is the default and preferred because 
+ is the default
+\change_inserted -712698321 1742721692
+.
+
+\change_unchanged
+ 
+\change_deleted -712698321 1742721696
+and preferred because
+\change_inserted -712698321 1742721697
+Note that
+\change_unchanged
+ 
 \series bold
 prettyref
 \series default
- supports only English documents.
+ supports only English documents
+\change_inserted -712698321 1742721720
+ (unless you add your own settings)
+\change_unchanged
+.
  The format is specified by using the command 
 \series bold
 
@@ -31935,7 +32004,20 @@ prettyref
 newref\SpecialChar ligaturebreak
 format
 \series default
- (prettyref) or 
+ (prettyref)
+\change_inserted -712698321 1742721923
+,
+
+\series bold
+ 
+\backslash
+crefname|
+\backslash
+crefname
+\series default
+ (cleveref)
+\change_unchanged
+ or 
 \series bold
 
 \backslash
@@ -31984,7 +32066,39 @@ prettyref
 refstyle 
 \series default
 predefines reference formats for all available types.
- This is especially true for the wide variety of mathematical `theorem' 
environments.
+ This is especially true for the wide variety of mathematical 
+\change_inserted -712698321 1742722007
+
+\begin_inset Quotes els
+\end_inset
+
+
+\change_deleted -712698321 1742722008
+`
+\change_unchanged
+theorem
+\change_deleted -712698321 1742722011
+'
+\change_inserted -712698321 1742722012
+
+\begin_inset Quotes ers
+\end_inset
+
+
+\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,
  say,
  Propositions,
@@ -32015,7 +32129,7 @@ For more information about defining formatted 
references,
  have a look at the package documentation 
 \begin_inset CommandInset citation
 LatexCommand cite
-key "prettyref,refstyle"
+key "cleveref,prettyref,refstyle"
 literal "true"
 
 \end_inset
@@ -32028,15 +32142,42 @@ The options
 \family sans
 Plural
 \family default
- and 
+ 
+\change_deleted -712698321 1742722076
+and 
 \family sans
 Capitalized
 \family default
- will be available with formatted references only if you are using the 
+ 
+\change_unchanged
+will be available with formatted references only if you are using the 
 \series bold
 refstyle
 \series default
- package.
+ package
+\change_inserted -712698321 1742722093
+,
+ and with textual references using cleveref
+\change_unchanged
+.
+
+\change_inserted -712698321 1742722131
+ 
+\family sans
+Capitalized
+\family default
+ is available with formatted references using 
+\series bold
+refstyle
+\series default
+,
+ and with formatted and textual references using 
+\series bold
+cleveref
+\series default
+.
+\change_unchanged
+
 \begin_inset Newline newline
 \end_inset
 
@@ -51167,11 +51308,15 @@ status open
 
 \change_inserted -712698321 1742640894
 prettyref
+\change_unchanged
+
 \end_layout
 
 \end_inset
 
 
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -51194,11 +51339,15 @@ status open
 
 \change_inserted -712698321 1742640894
 refstyle
+\change_unchanged
+
 \end_layout
 
 \end_inset
 
 
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -59398,6 +59547,76 @@ 
https://mirrors.ctan.org/macros/latex/contrib/caption/caption.pdf
 \end_inset
 
 
+\change_inserted -712698321 1742722173
+
+\end_layout
+
+\begin_layout Bibliography
+
+\change_inserted -712698321 1742722235
+\begin_inset CommandInset bibitem
+LatexCommand bibitem
+key "cleveref"
+literal "false"
+
+\end_inset
+
+cleveref
+\begin_inset CommandInset href
+LatexCommand href
+name "Documentation"
+target "https://mirrors.ctan.org/macros/latex/contrib/cleveref/cleveref.pdf";
+literal "false"
+
+\end_inset
+
+ of the \SpecialChar LaTeX
+ package cleveref
+\begin_inset Index idx
+range none
+pageformat default
+status open
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1742722175
+\SpecialChar LaTeX
+ packages
+\begin_inset IndexMacro subentry
+status open
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1742722254
+cleveref
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\end_inset
+
+:
+\begin_inset Newline newline
+\end_inset
+
+
+\begin_inset Flex URL
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1742722259
+https://mirrors.ctan.org/macros/latex/contrib/cleveref/cleveref.pdf
+\end_layout
+
+\end_inset
+
+
+\change_unchanged
+
 \end_layout
 
 \begin_layout Bibliography
diff --git a/lib/doc/de/UserGuide.lyx b/lib/doc/de/UserGuide.lyx
index fb95319d28..db98488a7f 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 635
+\lyxformat 636
 \begin_document
 \begin_header
 \save_transient_properties true
@@ -30684,7 +30684,7 @@ Querverweis:
 
 
 \begin_inset Note Greyedout
-status open
+status collapsed
 
 \begin_layout Plain Layout
 
@@ -30695,6 +30695,11 @@ Bemerkung:
  Dies ist nur möglich,
  wenn das \SpecialChar LaTeX
 -Paket 
+\series bold
+cleveref
+\series default
+,
+ 
 \series bold
 prettyref
 \series default
@@ -30703,6 +30708,29 @@ prettyref
 refstyle
 \series default
 
+\begin_inset Index idx
+range none
+pageformat default
+status open
+
+\begin_layout Plain Layout
+\SpecialChar LaTeX
+-Paket
+\begin_inset IndexMacro subentry
+status open
+
+\begin_layout Plain Layout
+cleveref
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\end_inset
+
+
 \begin_inset Index idx
 range none
 pageformat default
@@ -30759,9 +30787,9 @@ refstyle
 
 Man kann mit der Option 
 \family sans
-Verwende refstyle (statt prettyref) für Querverweise
+Formatpakete 
 \family default
- im Menü 
+im Menü 
 \family sans
 Dokument\SpecialChar menuseparator
 Einstellungen\SpecialChar menuseparator
@@ -30774,12 +30802,13 @@ Dokumentklasse
 \series bold
 refstyle
 \series default
- ist die Voreinstellung und bevorzugt,
- da 
+ ist die Voreinstellung und bevorzugt.
+ Beachten Sie,
+ dass 
 \series bold
 prettyref
 \series default
- nur englische Dokumente unterstützt.
+ 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,
  indem der Befehl 
 \series bold
@@ -30787,7 +30816,16 @@ prettyref
 \backslash
 newrefformat
 \series default
- (prettyref) oder 
+ (prettyref),
+ 
+\series bold
+
+\backslash
+crefname|
+\backslash
+crefname
+\series default
+ (cleveref) oder 
 \series bold
 
 \backslash
@@ -30843,7 +30881,7 @@ Theorem
 \begin_inset Quotes grs
 \end_inset
 
--Umgebungen zu.
+-Umgebungen zu (cleveref ist hier cleverer).
  Sollten Sie also formatierte Querverweise beispielsweise auf (mathematische) 
Sätze machen wollen,
  müssen Sie das relevante Format selbst definieren.
  Für 
@@ -30874,7 +30912,7 @@ Für weitere Informationen zur Definition formatierter 
Querverweise konsultieren
  
 \begin_inset CommandInset citation
 LatexCommand cite
-key "prettyref,refstyle"
+key "cleveref,prettyref,refstyle"
 literal "true"
 
 \end_inset
@@ -30883,19 +30921,38 @@ literal "true"
 \begin_inset Newline newline
 \end_inset
 
-Die Optionen 
+Die Option 
 \family sans
 Plural
 \family default
- und 
+ ist nur bei formatierten Querverweisen mit 
+\series bold
+refstyle
+\series default
+ aktiviert,
+ außerdem bei Textverweisen mit 
+\series bold
+cleveref
+\series default
+.
+ 
 \family sans
 Großschreibung
 \family default
- sind nur bei formatierten Querverweisen mit 
+ ist bei formatierten Querverweisen mit 
 \series bold
 refstyle
 \series default
- aktiviert.
+ und 
+\series bold
+cleveref
+\series default
+ aktiviert,
+ bei 
+\series bold
+cleveref
+\series default
+ außerdem auch bei Textverweisen.
 \begin_inset Newline newline
 \end_inset
 
@@ -56369,6 +56426,68 @@ 
https://mirrors.ctan.org/macros/latex/contrib/caption/caption.pdf
 \end_inset
 
 
+\end_layout
+
+\begin_layout Bibliography
+\begin_inset CommandInset bibitem
+LatexCommand bibitem
+key "cleveref"
+literal "false"
+
+\end_inset
+
+
+\begin_inset CommandInset href
+LatexCommand href
+name "Documentation"
+target "https://mirrors.ctan.org/macros/latex/contrib/cleveref/cleveref.pdf";
+literal "false"
+
+\end_inset
+
+ des \SpecialChar LaTeX
+-Pakets 
+\series bold
+cleveref
+\series default
+
+\begin_inset Index idx
+range none
+pageformat default
+status collapsed
+
+\begin_layout Plain Layout
+\SpecialChar LaTeX
+-Paket
+\begin_inset IndexMacro subentry
+status open
+
+\begin_layout Plain Layout
+cleveref
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\end_inset
+
+:
+\begin_inset Newline newline
+\end_inset
+
+
+\begin_inset Flex URL
+status collapsed
+
+\begin_layout Plain Layout
+https://mirrors.ctan.org/macros/latex/contrib/cleveref/cleveref.pdf
+\end_layout
+
+\end_inset
+
+
 \end_layout
 
 \begin_layout Bibliography
diff --git a/lib/lyx2lyx/lyx_2_5.py b/lib/lyx2lyx/lyx_2_5.py
index f0d3f6801d..d1b4a17287 100644
--- a/lib/lyx2lyx/lyx_2_5.py
+++ b/lib/lyx2lyx/lyx_2_5.py
@@ -2524,6 +2524,69 @@ def revert_crossref_package(document):
             document.header[i] = "\\use_refstyle 1"
 
 
+def revert_cleveref(document):
+    "Reverts cleveref commands to ERT"
+
+    i = find_token(document.header, "\\crossref_package cleveref", 0)
+    if i == -1:
+        return
+
+    # Reset header
+    document.header[i] = "\\crossref_package prettyref"
+
+    # Check and revert insets
+    i = 0
+    need_cleveref = False
+    while True:
+        i = find_token(document.body, "\\begin_inset CommandInset ref", i)
+        if i == -1:
+            break
+        j = find_end_of_inset(document.body, i)
+        if j == -1:
+            document.warning("Can't find end of reference inset at line %d!!" 
% (i))
+            i += 1
+            continue
+
+        nameref = False
+        k = find_token(document.body, "LatexCommand formatted", i, j)
+        if k == -1:
+            k = find_token(document.body, "LatexCommand nameref", i, j)
+            if k == -1:
+                i += 1
+                continue
+            nolink = get_bool_value(document.body, "nolink", i, j, False)
+            if not nolink:
+                i += 1
+                continue
+            nameref = True
+        
+        plural = get_bool_value(document.body, "plural", i, j, False)
+        caps = get_bool_value(document.body, "caps", i, j, False)
+        label = get_quoted_value(document.body, "reference", i, j)
+
+        cmd = "\\"
+        if nameref:
+            cmd += "name"
+        if caps:
+            cmd += "C"
+        else:
+            cmd += "c"
+        cmd += "ref"
+        if plural:
+            cmd += "s"
+        cmd += "{" + label + "}"
+        document.body[i : j + 1] = put_cmd_in_ert([cmd])
+        need_cleveref = True
+        i += 1
+
+    # preamble
+    if need_cleveref:
+        add_to_preamble(
+            document,
+            ["\\usepackage{cleveref}"]
+        )
+    
+
 ##
 # Conversion hub
 #
@@ -2544,11 +2607,13 @@ convert = [
     [632, []],
     [633, [convert_doc_colors]],
     [634, []],
-    [635, [convert_crossref_package]]
+    [635, [convert_crossref_package]],
+    [636, []]
 ]
 
 
 revert = [
+    [635, [revert_cleveref]],
     [634, [revert_crossref_package]],
     [633, [revert_colortbl]],
     [632, [revert_doc_colors, revert_colorbox]],
diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp
index d083a31dbb..7869325fdc 100644
--- a/src/BufferParams.cpp
+++ b/src/BufferParams.cpp
@@ -3026,6 +3026,14 @@ bool BufferParams::writeLaTeX(otexstream & os, 
LaTeXFeatures & features,
                os << '\n';
        }
 
+       // cleveref needs to be loaded very late as well
+       if (features.mustProvide("cleveref")) {
+               os << "\\usepackage";
+               if (!lyxrc.language_global_options && 
!language_options.str().empty())
+                       os << "[" << language_options.str() << "]";
+               os << "{cleveref}\n";
+       }
+
        // Since menukeys uses catoptions, which does some heavy changes on 
key-value options,
        // it is recommended to load menukeys as the last package (even after 
hyperref)
        if (features.isRequired("menukeys"))
diff --git a/src/frontends/qt/GuiDocument.cpp b/src/frontends/qt/GuiDocument.cpp
index b5d9bac16d..b39482f7a9 100644
--- a/src/frontends/qt/GuiDocument.cpp
+++ b/src/frontends/qt/GuiDocument.cpp
@@ -1672,6 +1672,7 @@ GuiDocument::GuiDocument(GuiView & lv)
        latexModule->childDocLE->setValidator(new NoNewLineValidator(
                latexModule->childDocLE));
 
+       latexModule->xrefPackageCO->addItem(qt_("Cleveref and varioref"), 
toqstr("cleveref"));
        latexModule->xrefPackageCO->addItem(qt_("Prettyref and varioref"), 
toqstr("prettyref"));
        latexModule->xrefPackageCO->addItem(qt_("Refstyle and varioref"), 
toqstr("refstyle"));
 
diff --git a/src/frontends/qt/GuiRef.cpp b/src/frontends/qt/GuiRef.cpp
index 9b52733224..c4c5f486e0 100644
--- a/src/frontends/qt/GuiRef.cpp
+++ b/src/frontends/qt/GuiRef.cpp
@@ -137,17 +137,23 @@ void GuiRef::enableView(bool enable)
 void GuiRef::enableBoxes()
 {
        QString const reftype =
-           typeCO->itemData(typeCO->currentIndex()).toString();
+               typeCO->itemData(typeCO->currentIndex()).toString();
+       bool const use_refstyle = buffer().params().xref_package == "refstyle";
+       bool const use_cleveref = buffer().params().xref_package == "cleveref";
        bool const isFormatted = (reftype == "formatted");
        bool const isLabelOnly = (reftype == "labelonly");
-       bool const usingRefStyle = buffer().params().xref_package == "refstyle";
-       bool const intext = bufferview()->cursor().inTexted();
        bool const hyper_on = buffer().params().pdfoptions().use_hyperref;
-       pluralCB->setEnabled(intext && isFormatted && usingRefStyle);
-       capsCB->setEnabled(intext && isFormatted && usingRefStyle);
+       bool const cleveref_nameref = use_cleveref && reftype == "nameref"
+                       && (!hyper_on || nolinkCB->isChecked());
+       bool const allow_plural = use_refstyle || cleveref_nameref;
+       bool const allow_caps = use_refstyle || use_cleveref;
+       bool const allow_nohyper = !isLabelOnly && (!isFormatted || 
use_cleveref);
+       bool const intext = bufferview()->cursor().inTexted();
+       pluralCB->setEnabled(intext && (isFormatted || cleveref_nameref) && 
allow_plural);
+       capsCB->setEnabled(intext && (isFormatted || cleveref_nameref) && 
allow_caps);
        noprefixCB->setEnabled(intext && isLabelOnly);
        // disabling of hyperlinks not supported by formatted references
-       nolinkCB->setEnabled(hyper_on && intext && !isFormatted && 
!isLabelOnly);
+       nolinkCB->setEnabled(hyper_on && intext && allow_nohyper);
 }
 
 
diff --git a/src/insets/InsetRef.cpp b/src/insets/InsetRef.cpp
index 8588c1e051..9cd0ddabf6 100644
--- a/src/insets/InsetRef.cpp
+++ b/src/insets/InsetRef.cpp
@@ -202,11 +202,14 @@ bool InsetRef::getStatus(Cursor & cur, FuncRequest const 
& cmd,
 // label, thus: \prettyref{pfx:suffix}.
 //
 docstring InsetRef::getFormattedCmd(docstring const & ref,
-       docstring & label, docstring & prefix, bool use_refstyle,
+       docstring & label, docstring & prefix, string const xref_package,
        bool use_caps)
 {
-       static docstring const defcmd = from_ascii("\\ref");
-       static docstring const prtcmd = from_ascii("\\prettyref");
+       bool const use_cleveref = xref_package == "cleveref";
+       docstring const crefcmd = use_caps ? from_ascii("\\Cref") : 
from_ascii("\\cref");
+       static docstring const defcmd = use_cleveref ? crefcmd : 
from_ascii("\\ref");
+       static docstring const prtcmd = use_cleveref ? crefcmd : 
from_ascii("\\prettyref");
+
 
        label = split(ref, prefix, ':');
 
@@ -220,12 +223,12 @@ docstring InsetRef::getFormattedCmd(docstring const & ref,
 
        if (prefix.empty()) {
                // we have ":xxxx"
-               LYXERR0("Label `" << ref << "' contains nothign before `:'.");
+               LYXERR0("Label `" << ref << "' contains nothing before `:'.");
                label = ref;
                return defcmd;
        }
 
-       if (!use_refstyle) {
+       if (xref_package != "refstyle") {
                // \prettyref uses the whole label
                label = ref;
                return prtcmd;
@@ -263,6 +266,8 @@ void InsetRef::latex(otexstream & os, OutputParams const & 
rp) const
        string const & cmd = getCmdName();
        docstring const & data = getEscapedLabel(rp);
        bool const hyper_on = buffer().masterParams().pdfoptions().use_hyperref;
+       bool const use_nolink = hyper_on && getParam("nolink") == "true";
+       bool const use_cleveref = buffer().masterParams().xref_package == 
"cleveref";
 
        if (rp.inulemcmd > 0)
                os << "\\mbox{";
@@ -272,22 +277,21 @@ void InsetRef::latex(otexstream & os, OutputParams const 
& rp) const
                // for refstyle, since refstlye's own \eqref prints, by default,
                // "equation n". if one wants \eqref, one can get it by using a
                // formatted label in this case.
-               bool const use_nolink = hyper_on && getParam("nolink") == 
"true";
                os << '(' << from_ascii("\\ref")   +
                        // no hyperlink version?
                        (use_nolink ? from_utf8("*") : from_utf8("")) +
                        from_ascii("{") << data << from_ascii("})");
-       }
-       else if (cmd == "formatted") {
+       } else if (cmd == "formatted") {
                docstring label;
                docstring prefix;
                bool const use_caps     = getParam("caps") == "true";
                bool const use_plural   = getParam("plural") == "true";
-               bool const use_refstyle = buffer().masterParams().xref_package 
== "refstyle";
                docstring const fcmd =
-                       getFormattedCmd(data, label, prefix, use_refstyle, 
use_caps);
+                       getFormattedCmd(data, label, prefix, 
buffer().masterParams().xref_package, use_caps);
                os << fcmd;
-               if (use_refstyle && use_plural)
+               if (use_cleveref && use_nolink)
+                       os << "*";
+               if (buffer().masterParams().xref_package == "refstyle" && 
use_plural)
                        os << "[s]";
                if (contains(label, ' '))
                        // refstyle bug: labels with blanks need to be grouped
@@ -295,8 +299,15 @@ void InsetRef::latex(otexstream & os, OutputParams const & 
rp) const
                        os << "{{" << label << "}}";
                else
                        os << '{' << label << '}';
-       }
-       else if (cmd == "labelonly") {
+       } else if (cmd == "nameref" && use_cleveref && (use_nolink || 
!hyper_on)) {
+               bool const use_caps     = getParam("caps") == "true";
+               bool const use_plural   = getParam("plural") == "true";
+               docstring const crefcmd = use_caps ? from_ascii("Cref") : 
from_ascii("cref");
+               os << "\\name" << crefcmd;
+               if (use_plural)
+                       os << "s";
+               os << '{' << data << '}';
+       } else if (cmd == "labelonly") {
                docstring const & ref = getParam("reference");
                if (getParam("noprefix") != "true")
                        os << ref;
@@ -310,8 +321,7 @@ void InsetRef::latex(otexstream & os, OutputParams const & 
rp) const
                                os << suffix;
                        }
                }
-       }
-       else {
+       } else {
                InsetCommandParams p(REF_CODE, cmd);
                bool const use_nolink = hyper_on && getParam("nolink") == 
"true";
                p["reference"] = getParam("reference");
@@ -605,11 +615,10 @@ void InsetRef::validate(LaTeXFeatures & features) const
                docstring const data = getEscapedLabel(features.runparams());
                docstring label;
                docstring prefix;
-               bool const use_refstyle = buffer().masterParams().xref_package 
== "refstyle";
                bool const use_caps   = getParam("caps") == "true";
                docstring const fcmd =
-                       getFormattedCmd(data, label, prefix, use_refstyle, 
use_caps);
-               if (use_refstyle) {
+                       getFormattedCmd(data, label, prefix, 
buffer().masterParams().xref_package, use_caps);
+               if (buffer().masterParams().xref_package == "refstyle") {
                        features.require("refstyle");
                        if (prefix == "cha")
                                
features.addPreambleSnippet(from_ascii("\\let\\charef=\\chapref"));
@@ -618,6 +627,8 @@ void InsetRef::validate(LaTeXFeatures & features) const
                                                fcmd + "[1]{\\ref{" + prefix + 
":#1}}}";
                                features.addPreambleSnippet(lcmd);
                        }
+               } else if (buffer().masterParams().xref_package == "cleveref") {
+                       features.require("cleveref");
                } else {
                        features.require("prettyref");
                        // prettyref uses "cha" for chapters, so we provide a 
kind of
@@ -628,8 +639,14 @@ void InsetRef::validate(LaTeXFeatures & features) const
        } else if (cmd == "eqref" && buffer().params().xref_package != 
"refstyle")
                // with refstyle, we simply output "(\ref{label})"
                features.require("amsmath");
-       else if (cmd == "nameref")
-               features.require("nameref");
+       else if (cmd == "nameref") {
+               bool const nr_clever = 
!buffer().masterParams().pdfoptions().use_hyperref
+                       || getParam("nolink") == "true";
+               if (buffer().masterParams().xref_package == "cleveref" && 
nr_clever)
+                       features.require("cleveref");
+               else
+                       features.require("nameref");
+       }
 }
 
 bool InsetRef::forceLTR(OutputParams const & rp) const
diff --git a/src/insets/InsetRef.h b/src/insets/InsetRef.h
index 423e53adde..e976006aa1 100644
--- a/src/insets/InsetRef.h
+++ b/src/insets/InsetRef.h
@@ -100,7 +100,8 @@ public:
        /// \param prefix of the label (before :)
        /// Also used by InsetMathRef
        static docstring getFormattedCmd(docstring const & ref, docstring & 
label,
-                       docstring & prefix, bool use_refstyle, bool use_caps = 
false);
+                       docstring & prefix, std::string const xref_package,
+                       bool use_caps = false);
 
 protected:
        ///
diff --git a/src/mathed/InsetMathRef.cpp b/src/mathed/InsetMathRef.cpp
index 078d0b23e8..2c1f6fe176 100644
--- a/src/mathed/InsetMathRef.cpp
+++ b/src/mathed/InsetMathRef.cpp
@@ -216,6 +216,8 @@ void InsetMathRef::validate(LaTeXFeatures & features) const
        else if (commandname() == "formatted") {
                if (use_refstyle)
                        features.require("refstyle");
+               else if (buffer().masterParams().xref_package == "cleveref")
+                       features.require("cleveref");
                else
                        features.require("prettyref");
        }
@@ -359,7 +361,7 @@ void InsetMathRef::write(TeXMathStream & os) const
                        docstring label;
                        docstring prefix;
                        docstring const fcmd =
-                               InsetRef::getFormattedCmd(ref, label, prefix, 
true);
+                               InsetRef::getFormattedCmd(ref, label, prefix, 
buffer().params().xref_package);
                        os << fcmd;
                        //if (plural)
                        //      os << "[s]";
diff --git a/src/tex2lyx/Preamble.cpp b/src/tex2lyx/Preamble.cpp
index 24e106d9af..f8a6b50a25 100644
--- a/src/tex2lyx/Preamble.cpp
+++ b/src/tex2lyx/Preamble.cpp
@@ -352,7 +352,7 @@ const char * const known_xetex_packages[] = {"arabxetex", 
"fixlatvian",
 
 /// packages that are automatically skipped if loaded by LyX
 const char * const known_lyx_packages[] = {"amsbsy", "amsmath", "amssymb",
-"amstext", "amsthm", "array", "babel", "booktabs", "calc", "CJK", "color", 
"colortbl",
+"amstext", "amsthm", "array", "babel", "booktabs", "calc", "CJK", "cleveref", 
"color", "colortbl",
 "float", "fontspec", "framed", "graphicx", "hhline", "ifthen", "longtable",
 "makeidx", "minted", "multirow", "nomencl", "parskip", "pdfpages", 
"prettyref", "refstyle",
 "rotating", "rotfloat", "splitidx", "setspace", "subscript", 
"tabularx","textcomp", "tipa",
@@ -2163,7 +2163,9 @@ void Preamble::handle_package(Parser &p, string const & 
name,
                        h_use_indices = "true";
                else if (name == "minted")
                        h_use_minted = true;
-               else if (name == "refstyle" || name == "prettyref")
+               else if (name == "refstyle"
+                        || name == "prettyref"
+                        || name == "cleveref")
                        h_crossref_package = name;
 
                if (!in_lyx_preamble) {
diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp
index e614c24fe6..ec3a566b59 100644
--- a/src/tex2lyx/text.cpp
+++ b/src/tex2lyx/text.cpp
@@ -150,13 +150,15 @@ char const * const known_babel_shorthands[] = { "\"", 
"|", "-", "~", "=", "/",
  "~", "*", ":", "_", "x", "'", "`", "<", ">", 0 };
 
 char const * const known_ref_commands[] = { "ref", "pageref", "vref",
- "vpageref", "prettyref", "nameref", "eqref", 0 };
+ "vpageref", "prettyref", "nameref", "eqref", "cref", "Cref", "namecref",
+ "nameCref", "namecrefs", "nameCrefs", 0 };
 
 char const * const known_coded_ref_commands[] = { "ref", "pageref", "vref",
- "vpageref", "formatted", "nameref", "eqref", 0 };
+ "vpageref", "formatted", "nameref", "eqref", "formatted", "formatted", 
"nameref",
+ "nameref", "nameref", "nameref", 0 };
 
 char const * const known_starref_commands[] = { "ref", "pageref", "vref",
- "vpageref", "nameref", "eqref", 0 };
+ "vpageref", "nameref", "eqref", "cref", "Cref", 0 };
 
 char const * const known_refstyle_commands[] = { "algref", "chapref", "corref",
  "eqref", "enuref", "figref", "fnref", "lemref", "parref", "partref", 
"propref",
@@ -4586,6 +4588,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, 
bool outer,
                     && (t.cs() != "prettyref" || preamble.crossrefPackage() == 
"prettyref")
                     && (p.next_token().asInput() != "*" || is_known(t.cs(), 
known_starref_commands))) {
                        bool starred = false;
+                       bool const caps = contains(t.cs(), 'C');
+                       bool const plural = suffixIs(t.cs(), "refs");
                        if (p.next_token().asInput() == "*") {
                                starred = true;
                                p.get_token();
@@ -4598,8 +4602,14 @@ void parse_text(Parser & p, ostream & os, unsigned 
flags, bool outer,
                                os << "reference \""
                                   << 
convert_literate_command_inset_arg(p.verbatim_item())
                                   << "\"\n";
-                               os << "plural \"false\"\n";
-                               os << "caps \"false\"\n";
+                               if (plural)
+                                       os << "plural \"true\"\n";
+                               else
+                                       os << "plural \"false\"\n";
+                               if (caps)
+                                       os << "caps \"true\"\n";
+                               else
+                                       os << "caps \"false\"\n";
                                os << "noprefix \"false\"\n";
                                if (starred)
                                        os << "nolink \"true\"\n";
@@ -4610,6 +4620,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, 
bool outer,
                                        
preamble.registerAutomaticallyLoadedPackage("varioref");
                                else if (t.cs() == "prettyref")
                                        
preamble.registerAutomaticallyLoadedPackage("prettyref");
+                               else if (contains(t.cs(), "cref") || 
contains(t.cs(), "Cref"))
+                                       
preamble.registerAutomaticallyLoadedPackage("cleveref");
                        } else {
                                // LyX does not yet support optional arguments 
of ref commands
                                output_ert_inset(os, t.asInput() + opt + "{" +
diff --git a/src/version.h b/src/version.h
index d32f196b6d..f11881f421 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 635 // spitz: \\crossref_package
-#define LYX_FORMAT_TEX2LYX 635
+#define LYX_FORMAT_LYX 636 // spitz: cleveref support
+#define LYX_FORMAT_TEX2LYX 636
 
 #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
 #ifndef _MSC_VER
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to