[LyX/master] Add IsInherited Argument tag
Juergen Spitzmueller
spitz at lyx.org
Sat Jul 4 06:32:02 UTC 2026
commit d2cbeea0113384ae778537935e0b257668ddc3f3
Author: Juergen Spitzmueller <spitz at lyx.org>
Date: Sat Jul 4 08:27:05 2026 +0200
Add IsInherited Argument tag
This allows to add arguments to InsetLayouts of insets that do fill in
arguments themselves due to their settings.
For instance, the Elsevier CAS classes introduce additional options
for floats, which must be combined with the (placement) options set in
the float dialog
---
lib/doc/Customization.lyx | 72 ++++++++++++++++++++++++++++++++++++++++++++
lib/doc/de/Customization.lyx | 63 ++++++++++++++++++++++++++++++++++++++
lib/scripts/layout2layout.py | 7 +++--
src/Layout.cpp | 3 ++
src/Layout.h | 1 +
src/TextClass.cpp | 2 +-
src/insets/InsetArgument.cpp | 3 +-
src/insets/InsetArgument.h | 4 +++
src/insets/InsetFloat.cpp | 17 +++++++++--
src/insets/InsetLayout.cpp | 3 ++
src/insets/InsetText.cpp | 10 +++---
src/insets/InsetText.h | 3 +-
src/output_latex.cpp | 10 +++---
src/output_latex.h | 3 +-
14 files changed, 184 insertions(+), 17 deletions(-)
diff --git a/lib/doc/Customization.lyx b/lib/doc/Customization.lyx
index 9438538c49..6d66f45aa2 100644
--- a/lib/doc/Customization.lyx
+++ b/lib/doc/Customization.lyx
@@ -10707,6 +10707,8 @@ status collapsed
\change_inserted -712698321 1781961292
MaxLaTeXVersion
+\change_unchanged
+
\end_layout
\end_inset
@@ -10719,6 +10721,8 @@ status collapsed
\change_inserted -712698321 1781961309
yyyy/mm/dd
+\change_unchanged
+
\end_layout
\end_inset
@@ -24337,6 +24341,74 @@ status collapsed
] The font inside the argument is inherited from the surrounding text on screen if this parameter is 1 (which is the default).
Otherwise the document default font is used.
+\change_inserted -712698321 1783145637
+
+\end_layout
+
+\begin_layout Itemize
+
+\change_inserted -712698321 1783145805
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1783145646
+IsInherited
+\end_layout
+
+\end_inset
+
+ [
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1783145638
+
+\emph on
+0
+\end_layout
+
+\end_inset
+
+
+\begin_inset space \thinspace{}
+\end_inset
+
+
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1783145638
+1
+\end_layout
+
+\end_inset
+
+] If this is set to 1,
+ the argument will be inherited and output by the containing inset.
+ This is used if the inset itself might add additional input to the argument via its settings (as in floats).
+ Only supported for
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1783145818
+InsetLayout
+\change_unchanged
+
+\end_layout
+
+\end_inset
+
+ arguments.
+\change_unchanged
+
\end_layout
\begin_layout Itemize
diff --git a/lib/doc/de/Customization.lyx b/lib/doc/de/Customization.lyx
index 77dabe1b7f..748c8b27b2 100644
--- a/lib/doc/de/Customization.lyx
+++ b/lib/doc/de/Customization.lyx
@@ -23282,6 +23282,69 @@ status collapsed
\begin_inset Flex Code
status collapsed
+\begin_layout Plain Layout
+IsInherited
+\end_layout
+
+\end_inset
+
+ [
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\emph on
+0
+\end_layout
+
+\end_inset
+
+
+\begin_inset space \thinspace{}
+\end_inset
+
+
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+1
+\end_layout
+
+\end_inset
+
+] Wenn dies
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+1
+\end_layout
+
+\end_inset
+
+ gesetzt wird,
+ wird dieses Argument von der beinhaltenden Einfügung aufgenommen und ausgegeben.
+ Das wird verwenden,
+ wenn die Einfügung selbst (aufgrund bestimmter Einstellungen) Ergänzungen zum Argument hinzufügt (beispielsweise im Fall von Gleitobjekten).
+ Das wird nur von
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+InsetLayout
+\end_layout
+
+\end_inset
+
+ unterstützt.
+\end_layout
+
+\begin_layout Itemize
+\begin_inset Flex Code
+status collapsed
+
\begin_layout Plain Layout
IsTocCaption
\end_layout
diff --git a/lib/scripts/layout2layout.py b/lib/scripts/layout2layout.py
index ada4483805..1e55ed3e08 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 = 117
+currentFormat = 118
# Incremented to format 4, 6 April 2007, lasgouttes
@@ -397,6 +397,9 @@ currentFormat = 117
# Incremented to format 117, 20 June 2026 by spitz
# New Tag MaxLaTeXVersion for latexrelease rollback
+# Incremented to format 118, 4 July 2026 by spitz
+# New Argument tag IsInherited
+
# Do not forget to document format change in Customization
# Manual (section "Declaring a new text class").
@@ -736,7 +739,7 @@ def convert(lines, end_format):
i += 1
continue
- if 101 <= format <= 117:
+ if 101 <= format <= 118:
# nothing to do.
i += 1
continue
diff --git a/src/Layout.cpp b/src/Layout.cpp
index af04fa218d..f537124f47 100644
--- a/src/Layout.cpp
+++ b/src/Layout.cpp
@@ -1392,6 +1392,9 @@ void Layout::readArgument(Lexer & lex, bool validating)
} else if (tok == "istoccaption") {
lex.next();
arg.is_toc_caption = lex.getBool();
+ } else if (tok == "isinherited") {
+ lex.next();
+ arg.is_inherited = lex.getBool();
} else if (tok == "freespacing") {
lex.next();
arg.free_spacing = lex.getBool();
diff --git a/src/Layout.h b/src/Layout.h
index 3fa421b385..f2dfc7ec47 100644
--- a/src/Layout.h
+++ b/src/Layout.h
@@ -113,6 +113,7 @@ public:
bool is_toc_caption = false;
bool free_spacing = false;
bool inh_font = true;
+ bool is_inherited = false;
std::string newlinecmd;
/// The DocBook tag corresponding to this argument.
docstring docbooktag;
diff --git a/src/TextClass.cpp b/src/TextClass.cpp
index ad7ec69441..87c50d7546 100644
--- a/src/TextClass.cpp
+++ b/src/TextClass.cpp
@@ -60,7 +60,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 = 117; // spitz: MaxLatexVersion
+int const LAYOUT_FORMAT = 118; // spitz: IsInherited
// Layout format for the current lyx file format. Controls which format is
diff --git a/src/insets/InsetArgument.cpp b/src/insets/InsetArgument.cpp
index 7556490251..f12738ce1b 100644
--- a/src/insets/InsetArgument.cpp
+++ b/src/insets/InsetArgument.cpp
@@ -45,7 +45,7 @@ InsetArgument::InsetArgument(Buffer * buf, string const & name)
: InsetCollapsible(buf), name_(name), labelstring_(docstring()),
font_(inherit_font), labelfont_(inherit_font), decoration_(string()),
pass_thru_context_(false), pass_thru_local_(false), pass_thru_(false),
- inherit_font_(true), free_spacing_(false), escape_chars_(docstring()),
+ inherit_font_(true), is_inherited_(false), free_spacing_(false), escape_chars_(docstring()),
pass_thru_chars_(docstring()), is_toc_caption_(false), newline_cmd_(string())
{}
@@ -125,6 +125,7 @@ void InsetArgument::init(Paragraph const & par)
newline_cmd_ = (*lait).second.newlinecmd;
free_spacing_ = (*lait).second.free_spacing;
inherit_font_ = (*lait).second.inh_font;
+ is_inherited_ = (*lait).second.is_inherited;
docbooktag_ = (*lait).second.docbooktag;
docbooktagtype_ = (*lait).second.docbooktagtype;
docbookattr_ = (*lait).second.docbookattr;
diff --git a/src/insets/InsetArgument.h b/src/insets/InsetArgument.h
index 417694b5aa..11dcd663c6 100644
--- a/src/insets/InsetArgument.h
+++ b/src/insets/InsetArgument.h
@@ -77,6 +77,8 @@ public:
///
bool inheritFont() const override { return inherit_font_; }
///
+ bool isInherited() const { return is_inherited_; }
+ ///
bool isFreeSpacing() const override { return free_spacing_; }
///
bool isTocCaption() const { return is_toc_caption_; }
@@ -126,6 +128,8 @@ private:
///
bool inherit_font_;
///
+ bool is_inherited_;
+ ///
bool free_spacing_;
///
docstring escape_chars_;
diff --git a/src/insets/InsetFloat.cpp b/src/insets/InsetFloat.cpp
index 9e91b195a7..015dfd590b 100644
--- a/src/insets/InsetFloat.cpp
+++ b/src/insets/InsetFloat.cpp
@@ -458,9 +458,20 @@ void InsetFloat::latex(otexstream & os, OutputParams const & runparams_in) const
// We only output placement if different from the def_placement.
// sidewaysfloats always use their own page,
// therefore don't output the p option that is always set
- if (!placement.empty()
- && (!params_.sideways || from_ascii(placement) != "p"))
- os << '[' << from_ascii(placement) << ']';
+ InsetLayout const & il = getLayout();
+ bool const have_placement = !placement.empty()
+ && (!params_.sideways || from_ascii(placement) != "p");
+ if (have_placement || !il.latexargs().empty()) {
+ os << '[';
+ if (!il.latexargs().empty()) {
+ getArgs(os, runparams);
+ if (have_placement)
+ os << ", ";
+ }
+ if (have_placement)
+ os << from_ascii(placement);
+ os << ']';
+ }
os << '\n';
if (runparams.inDeletedInset) {
diff --git a/src/insets/InsetLayout.cpp b/src/insets/InsetLayout.cpp
index 7bd75d21b1..3fd06824a5 100644
--- a/src/insets/InsetLayout.cpp
+++ b/src/insets/InsetLayout.cpp
@@ -1016,6 +1016,9 @@ void InsetLayout::readArgument(Lexer & lex)
arg.passthru = PT_FALSE;
else
arg.passthru = PT_INHERITED;
+ } else if (tok == "isinherited") {
+ lex.next();
+ arg.is_inherited = lex.getBool();
} else if (tok == "istoccaption") {
lex.next();
arg.is_toc_caption = lex.getBool();
diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp
index 4e92a1236d..c66a54a287 100644
--- a/src/insets/InsetText.cpp
+++ b/src/insets/InsetText.cpp
@@ -547,7 +547,7 @@ void InsetText::latex(otexstream & os, OutputParams const & runparams) const
}
} else {
if (!il.latexargs().empty())
- getArgs(os, runparams);
+ getArgs(os, runparams, false, true);
if (!il.latexparam().empty())
os << from_utf8(il.latexparam());
}
@@ -952,7 +952,7 @@ void InsetText::insetAsXHTML(XMLStream & xs, OutputParams const & rp,
void InsetText::getArgs(otexstream & os, OutputParams const & runparams_in,
- bool const post) const
+ bool const post, bool const ignore_inherited) const
{
OutputParams runparams = runparams_in;
runparams.local_font =
@@ -961,10 +961,12 @@ void InsetText::getArgs(otexstream & os, OutputParams const & runparams_in,
runparams.pass_thru = true;
if (post)
latexArgInsetsForParent(paragraphs(), os, runparams,
- getLayout().postcommandargs(), "post:");
+ getLayout().postcommandargs(), "post:",
+ ignore_inherited);
else
latexArgInsetsForParent(paragraphs(), os, runparams,
- getLayout().latexargs());
+ getLayout().latexargs(), string(),
+ ignore_inherited);
}
diff --git a/src/insets/InsetText.h b/src/insets/InsetText.h
index 94bbea184d..a817dc6113 100644
--- a/src/insets/InsetText.h
+++ b/src/insets/InsetText.h
@@ -102,7 +102,8 @@ public:
void validate(LaTeXFeatures & features) const override;
/// return the argument(s) only
- void getArgs(otexstream & os, OutputParams const &, bool const post = false) const;
+ void getArgs(otexstream & os, OutputParams const &, bool const post = false,
+ bool const ignore_inherited = false) const;
/// return x,y of given position relative to the inset's baseline
void cursorPos(BufferView const & bv, CursorSlice const & sl,
diff --git a/src/output_latex.cpp b/src/output_latex.cpp
index f16a1c6199..b92bf036df 100644
--- a/src/output_latex.cpp
+++ b/src/output_latex.cpp
@@ -556,7 +556,7 @@ void getArgInsets(otexstream & os, OutputParams const & runparams,
Layout::latexarg const arg = lait->second;
docstring ldelim;
docstring rdelim;
- if (!arg.nodelims) {
+ if (!arg.nodelims && !arg.is_inherited) {
ldelim = arg.mandatory ?
from_ascii("{") : from_ascii("[");
rdelim = arg.mandatory ?
@@ -661,12 +661,14 @@ namespace {
void addArgInsets(Paragraph const & par, string const & prefix,
Layout::LaTeXArgMap const & latexargs,
map<size_t, InsetArgument const *> & ilist,
- vector<string> & required)
+ vector<string> & required, bool const ignore_inherited = false)
{
for (auto const & table : par.insetList()) {
InsetArgument const * arg = table.inset->asInsetArgument();
if (!arg)
continue;
+ if (ignore_inherited && arg->isInherited())
+ continue;
if (arg->name().empty()) {
LYXERR0("Error: Unnamed argument inset!");
continue;
@@ -743,7 +745,7 @@ void latexArgInsets(ParagraphList const & pars,
void latexArgInsetsForParent(ParagraphList const & pars, otexstream & os,
OutputParams const & runparams,
Layout::LaTeXArgMap const & latexargs,
- string const & prefix)
+ string const & prefix, bool const ignore_inherited)
{
map<size_t, InsetArgument const *> ilist;
vector<string> required;
@@ -752,7 +754,7 @@ void latexArgInsetsForParent(ParagraphList const & pars, otexstream & os,
if (par.layout().hasArgs())
// The InsetArguments inside this paragraph refer to this paragraph
continue;
- addArgInsets(par, prefix, latexargs, ilist, required);
+ addArgInsets(par, prefix, latexargs, ilist, required, ignore_inherited);
}
getArgInsets(os, runparams, latexargs, ilist, required, prefix);
}
diff --git a/src/output_latex.h b/src/output_latex.h
index 311b2e61b0..54d499a83f 100644
--- a/src/output_latex.h
+++ b/src/output_latex.h
@@ -64,7 +64,8 @@ void latexArgInsets(ParagraphList const & pars,
void latexArgInsetsForParent(ParagraphList const & pars, otexstream & os,
OutputParams const & runparams,
Layout::LaTeXArgMap const & latexargs,
- std::string const & prefix = std::string());
+ std::string const & prefix = std::string(),
+ bool const ignore_inherited = false);
/** Export \p paragraphs of buffer \p buf to LaTeX.
Don't use a temporary stringstream for \p os if the final output is
supposed to go to a file.
More information about the lyx-cvs
mailing list