commit 8e12d03b438e1c87626bd4fcb3418ba9559e6254
Author: Juergen Spitzmueller <[email protected]>
Date:   Sat Jul 5 10:04:40 2025 +0200

    Preamble tag for floats (#13110)
---
 lib/doc/Customization.lyx    | 53 ++++++++++++++++++++++++++++++++++++++++++++
 lib/doc/de/Customization.lyx | 41 ++++++++++++++++++++++++++++++++++
 lib/scripts/layout2layout.py |  7 ++++--
 src/Floating.cpp             | 14 ++++++------
 src/Floating.h               |  8 +++++--
 src/LaTeXFeatures.cpp        |  8 +++++++
 src/TextClass.cpp            | 12 +++++++---
 7 files changed, 129 insertions(+), 14 deletions(-)

diff --git a/lib/doc/Customization.lyx b/lib/doc/Customization.lyx
index 839940938e..95420a07c5 100644
--- a/lib/doc/Customization.lyx
+++ b/lib/doc/Customization.lyx
@@ -18702,6 +18702,53 @@ tbp
 \end_inset
 
 .
+\change_inserted -712698321 1751702464
+
+\end_layout
+
+\begin_layout Description
+
+\change_inserted -712698321 1751702481
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1751702464
+Preamble
+\end_layout
+
+\end_inset
+
+ Information to be included in the \SpecialChar LaTeX
+ preamble when this float is used.
+ Used to define macros,
+ load packages,
+ etc.,
+ required by this particular float.
+ Must end with 
+\begin_inset Quotes eld
+\end_inset
+
+
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1751702464
+EndPreamble
+\end_layout
+
+\end_inset
+
+
+\begin_inset Quotes erd
+\end_inset
+
+.
+\change_unchanged
+
 \end_layout
 
 \begin_layout Description
@@ -23842,6 +23889,8 @@ status collapsed
 
 \change_inserted -712698321 1748075210
 InheritFont
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -23854,6 +23903,8 @@ status collapsed
 
 \change_inserted -712698321 1748075210
 0
+\change_unchanged
+
 \end_layout
 
 \end_inset
@@ -23872,6 +23923,8 @@ status collapsed
 
 \emph on
 1
+\change_unchanged
+
 \end_layout
 
 \end_inset
diff --git a/lib/doc/de/Customization.lyx b/lib/doc/de/Customization.lyx
index dfbdfba07a..1cd8813ce9 100644
--- a/lib/doc/de/Customization.lyx
+++ b/lib/doc/de/Customization.lyx
@@ -17176,6 +17176,47 @@ tbp
 \begin_inset Flex Code
 status collapsed
 
+\begin_layout Plain Layout
+Preamble
+\end_layout
+
+\end_inset
+
+ Befehle und Definitionen,
+ die in die Präambel (vor 
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\backslash
+begin{docu\SpecialChar softhyphen
+ment}
+\end_layout
+
+\end_inset
+
+) eingefügt werden,
+ wenn dieses Gleitobjekt benutzt wird.
+ Kann verwendet werden um Pakete zu laden,
+ Makros zu definieren usw.
+ Muss mit 
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+EndPreamble
+\end_layout
+
+\end_inset
+
+ beendet werden.
+\end_layout
+
+\begin_layout Description
+\begin_inset Flex Code
+status collapsed
+
 \begin_layout Plain Layout
 PrettyFormat
 \end_layout
diff --git a/lib/scripts/layout2layout.py b/lib/scripts/layout2layout.py
index 81bf2789b7..938587db72 100644
--- a/lib/scripts/layout2layout.py
+++ b/lib/scripts/layout2layout.py
@@ -9,7 +9,7 @@
 # This script will update a .layout file to current format
 
 # The latest layout format is also defined in src/TextClass.cpp
-currentFormat = 109
+currentFormat = 110
 
 
 # Incremented to format 4, 6 April 2007, lasgouttes
@@ -368,6 +368,9 @@ currentFormat = 109
 # Incremented to format 109, 15 May 2025 by spitz
 # New Layout tag "MultiPar"
 
+# Incremented to format 110, 5 July 2025 by spitz
+# New Float tag "Preamble"
+
 # Do not forget to document format change in Customization
 # Manual (section "Declaring a new text class").
 
@@ -707,7 +710,7 @@ def convert(lines, end_format):
                 i += 1
             continue
 
-        if 101 <= format <= 109:
+        if 101 <= format <= 110:
             # nothing to do.
             i += 1
             continue
diff --git a/src/Floating.cpp b/src/Floating.cpp
index 9dc0c46526..e174571366 100644
--- a/src/Floating.cpp
+++ b/src/Floating.cpp
@@ -34,16 +34,16 @@ Floating::Floating(string const & type, string const & 
placement,
                   docstring const & htmlStyle, std::string const & docbookTag,
                   string const & docbookAttr, string const & docbookTagType,
                   std::string const & docbookFloatType, std::string const & 
docbookCaption,
-                  string const & required, bool usesfloat, bool ispredefined,
-                  bool allowswide, bool allowssideways)
+                  string const & required, docstring const & preamble,
+                  bool usesfloat, bool ispredefined, bool allowswide, bool 
allowssideways)
        : floattype_(type), placement_(placement), ext_(ext), within_(within),
          style_(style), name_(name), listname_(listName), 
listcommand_(listCmd),
          refprefix_(refPrefix), allowedplacement_(allowedplacement), 
required_(required),
-         usesfloatpkg_(usesfloat), ispredefined_(ispredefined),
-         allowswide_(allowswide), allowssideways_(allowssideways),
-         html_tag_(htmlTag), html_attrib_(htmlAttrib), html_style_(htmlStyle),
-         docbook_caption_(docbookCaption), docbook_tag_(docbookTag),
-         docbook_tag_type_(docbookTagType)
+         preamble_(preamble), usesfloatpkg_(usesfloat),
+         ispredefined_(ispredefined), allowswide_(allowswide),
+         allowssideways_(allowssideways), html_tag_(htmlTag), 
html_attrib_(htmlAttrib),
+         html_style_(htmlStyle), docbook_caption_(docbookCaption),
+         docbook_tag_(docbookTag), docbook_tag_type_(docbookTagType)
 {
        // Implement some edge cases for DocBook. Both docbook_float_type_ and 
docbook_attr_ must be computed
        // based on the given value of docbookFloatType; docbook_tag_ can still 
be guessed without correlation.
diff --git a/src/Floating.h b/src/Floating.h
index 7bc82b7dfb..d56590d7d5 100644
--- a/src/Floating.h
+++ b/src/Floating.h
@@ -37,8 +37,8 @@ public:
                 docstring const & htmlStyle, std::string const & docbookTag,
                 std::string const & docbookAttr, std::string const & 
docbookTagType,
                 std::string const & docbookFloatType, std::string const & 
docbookCaption,
-                std::string const & required, bool usesfloat, bool 
ispredefined,
-                bool allowswide, bool allowssideways);
+                std::string const & required, docstring const & preamble,
+                bool usesfloat, bool ispredefined, bool allowswide, bool 
allowssideways);
        ///
        std::string const & floattype() const { return floattype_; }
        ///
@@ -69,6 +69,8 @@ public:
        /// allowed placement options
        std::string const & required() const { return required_; }
        ///
+       docstring const & preamble() const { return preamble_; }
+       ///
        bool isPredefined() const { return ispredefined_; }
        ///
        bool allowsWide() const { return allowswide_; }
@@ -114,6 +116,8 @@ private:
        std::string allowedplacement_;
        ///
        std::string required_;
+       /// Macro definitions needed for this layout
+       docstring preamble_;
        ///
        bool usesfloatpkg_;
        ///
diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp
index 4aca4ab6cb..6212d562a4 100644
--- a/src/LaTeXFeatures.cpp
+++ b/src/LaTeXFeatures.cpp
@@ -2081,6 +2081,14 @@ docstring const LaTeXFeatures::getTClassPreamble() const
                        continue;
                tcpreamble << it->second.preamble();
        }
+       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);
+               if (!fl.preamble().empty())
+                       tcpreamble << fl.preamble();
+       }
 
        return tcpreamble.str();
 }
diff --git a/src/TextClass.cpp b/src/TextClass.cpp
index 235972f277..b68bfb0ea1 100644
--- a/src/TextClass.cpp
+++ b/src/TextClass.cpp
@@ -59,7 +59,7 @@ namespace lyx {
 // You should also run the development/tools/updatelayouts.py script,
 // to update the format of all of our layout files.
 //
-int const LAYOUT_FORMAT = 109; // spitz: MultiPar (styles)
+int const LAYOUT_FORMAT = 110; // spitz: Preamble tag for floats
 
 
 // Layout format for the current lyx file format. Controls which format is
@@ -1465,6 +1465,7 @@ bool TextClass::readFloat(Lexer & lexrc)
                FT_ALLOWS_WIDE,
                FT_REQUIRES,
                FT_PRETTYFORMAT,
+               FT_PREAMBLE,
                FT_END
        };
 
@@ -1488,6 +1489,7 @@ bool TextClass::readFloat(Lexer & lexrc)
                { "listname", FT_LISTNAME },
                { "numberwithin", FT_WITHIN },
                { "placement", FT_PLACEMENT },
+               { "preamble", FT_PREAMBLE },
                { "prettyformat", FT_PRETTYFORMAT },
                { "refprefix", FT_REFPREFIX },
                { "requires", FT_REQUIRES },
@@ -1518,6 +1520,7 @@ bool TextClass::readFloat(Lexer & lexrc)
        string within;
        string required;
        docstring prettyformat;
+       docstring preamble;
        bool usesfloat = true;
        bool ispredefined = false;
        bool allowswide = true;
@@ -1555,6 +1558,9 @@ bool TextClass::readFloat(Lexer & lexrc)
                        lexrc.next();
                        name = lexrc.getString();
                        break;
+               case FT_PREAMBLE:
+                       preamble = 
lexrc.getLongString(from_ascii("EndPreamble"));
+                       break;
                case FT_PLACEMENT:
                        lexrc.next();
                        placement = lexrc.getString();
@@ -1677,8 +1683,8 @@ bool TextClass::readFloat(Lexer & lexrc)
                        listname, listcommand, refprefix, allowed_placement,
                        htmltag, htmlattr, htmlstyle, docbooktag, docbookattr,
                        docbooktagtype, docbookfloattype, docbookcaption,
-                       required, usesfloat, ispredefined,
-               allowswide, allowssideways);
+                       required, preamble, usesfloat, ispredefined,
+                       allowswide, allowssideways);
                floatlist_.newFloat(fl);
                // each float has its own counter
                counters_.newCounter(from_ascii(type), from_ascii(within),
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to