\begin_layout Description
-\change_inserted -712698321 1690292676
+\change_inserted -712698321 1690357747
\begin_inset Flex Code
status collapsed
\change_inserted -712698321 1690292501
AllowedOccurrences
+\change_unchanged
+
\end_layout
\end_inset
\change_inserted -712698321 1690292507
int
+\change_unchanged
+
\end_layout
\end_inset
\change_inserted -712698321 1690292530
AllowedInInsets
+\change_unchanged
+
\end_layout
\end_inset
\change_inserted -712698321 1690292536
AllowedInLayouts
+\change_unchanged
+
\end_layout
\end_inset
has been defined,
- this can be used to determine how many times the inset can be inserted to a given paragraph.
+ this can be used to determine how many times the inset can be inserted to a given inset or the paragraph (group).
+\end_layout
+
+\begin_layout Description
+
+\change_inserted -712698321 1690357828
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1690357753
+AllowedOccurrencesPerItem
+\end_layout
+
+\end_inset
+
+ [
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1690357747
+
+\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 1690357747
+1
+\end_layout
+
+\end_inset
+
+] If this is set to true,
+
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1690357774
+AllowedOccurrences
+\end_layout
+
+\end_inset
+
+ applies to single paragraphs if we are in a list-type environment (with
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1690357825
+
+\backslash
+item
+\change_unchanged
+
+\end_layout
+
+\end_inset
+
+s).
\change_unchanged
\end_layout
\begin_inset Flex Code
status collapsed
+\begin_layout Plain Layout
+AllowedOccurrencesPerItem
+\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 auf
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+true
+\end_layout
+
+\end_inset
+
+ gesetzt wird,
+ zählen die
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+AllowedOccurrences
+\end_layout
+
+\end_inset
+
+ je Absatz,
+ sofern wir uns in einer listenartigen Umgebung (mit
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\backslash
+item
+\end_layout
+
+\end_inset
+
+s) befinden.
+\end_layout
+
+\begin_layout Description
+\begin_inset Flex Code
+status collapsed
+
\begin_layout Plain Layout
Argument
\end_layout
Numbered_Example_(multiline), Numbered_Examples_(consecutive)
EndAllowedInLayouts
AllowedOccurrences 1
+ AllowedOccurrencesPerItem true
End
InsetLayout Flex:Subexample_Preamble
# Incremented to format 102, 25 July 2023 by spitz
# add InsetLayout tags AllowedInInsets, EndAllowedInInsets,
-# AllowedInLayouts, EndAllowedInLayouts, AllowedOccurrences
+# AllowedInLayouts, EndAllowedInLayouts, AllowedOccurrences,
+# AllowedOccurrencesPerItem
# Do not forget to document format change in Customization
# Manual (section "Declaring a new text class").
set<docstring> const & allowed_insets = il.allowedInInsets();
set<docstring> const & allowed_layouts = il.allowedInLayouts();
- bool result = false;
- if (allowed_insets.find(inInset().getLayout().name()) != allowed_insets.end())
- result = true;
+ bool in_allowed_inset =
+ allowed_insets.find(inInset().getLayout().name()) != allowed_insets.end();
- else if (allowed_layouts.find(d->layout_->name()) != allowed_layouts.end())
- result = true;
+ bool in_allowed_layout =
+ allowed_layouts.find(d->layout_->name()) != allowed_layouts.end();
- else if (inInset().asInsetArgument()) {
+ if (!in_allowed_inset && inInset().asInsetArgument()) {
// check if the argument allows the inset in question
if (cur.depth() > 1) {
docstring parlayout = cur[cur.depth() - 2].inset().getLayout().name()
+ from_ascii("@") + from_ascii(inInset().asInsetArgument()->name());
if (allowed_insets.find(parlayout) != allowed_insets.end())
- result = true;
+ in_allowed_inset = true;
}
}
- if (result && il.allowedOccurrences() != -1) {
- int have_ins = 0;
- for (auto const & table : insetList())
- if (table.inset->getLayout().name() == il.name())
- ++have_ins;
+ int have_ins = 0;
+ // check if we exceed the number of allowed insets in this inset
+ if (in_allowed_inset && inInset().asInsetText() && il.allowedOccurrences() != -1) {
+ ParagraphList & pars = cur.text()->paragraphs();
+ for (Paragraph const & par : pars) {
+ for (auto const & table : par.insetList())
+ if (table.inset->getLayout().name() == il.name())
+ ++have_ins;
+ }
+ if (have_ins >= il.allowedOccurrences())
+ return false;
+ }
+
+ have_ins = 0;
+ // check if we exceed the number of allowed insets in the layout group
+ if (in_allowed_layout && il.allowedOccurrences() != -1) {
+ pit_type pit = cur.pit();
+ pit_type lastpit = cur.pit();
+ ParagraphList & pars = cur.text()->paragraphs();
+ // If we are not on a list-type environment or AllowedOccurrencesPerItem
+ // is false, we check the whole paragraph group
+ if (d->layout_->isEnvironment()
+ && !(il.allowedOccurrencesPerItem()
+ && (d->layout_->latextype == LATEX_LIST_ENVIRONMENT
+ || d->layout_->latextype == LATEX_ITEM_ENVIRONMENT))) {
+ lastpit = cur.lastpit();
+ // get the first paragraph in sequence with this layout
+ depth_type const current_depth = params().depth();
+ while (true) {
+ if (pit == 0)
+ break;
+ Paragraph cpar = pars[pit - 1];
+ if (&cpar.layout() == d->layout_
+ && cpar.params().depth() == current_depth)
+ --pit;
+ else
+ break;
+ }
+ }
+ for (; pit <= lastpit; ++pit) {
+ if (&pars[pit].layout() != d->layout_)
+ break;
+ for (auto const & table : pars[pit].insetList())
+ if (table.inset->getLayout().name() == il.name())
+ ++have_ins;
+ }
if (have_ins >= il.allowedOccurrences())
return false;
}
- if (result)
+ if (in_allowed_layout || in_allowed_inset)
return true;
return (allowed_insets.empty() && allowed_layouts.empty());
IL_ALLOWED_IN_INSET,
IL_ALLOWED_IN_LAYOUT,
IL_ALLOWED_OCCURRENCES,
+ IL_ALLOWED_OCCURRENCES_PER_ITEM,
IL_ARGUMENT,
IL_BABELPREAMBLE,
IL_BGCOLOR,
{ "allowedininsets", IL_ALLOWED_IN_INSET },
{ "allowedinlayouts", IL_ALLOWED_IN_LAYOUT },
{ "allowedoccurrences", IL_ALLOWED_OCCURRENCES },
+ { "allowedoccurrencesperitem", IL_ALLOWED_OCCURRENCES_PER_ITEM },
{ "argument", IL_ARGUMENT },
{ "babelpreamble", IL_BABELPREAMBLE },
{ "bgcolor", IL_BGCOLOR },
case IL_ALLOWED_OCCURRENCES:
lex >> allowed_occurrences_;
break;
+ case IL_ALLOWED_OCCURRENCES_PER_ITEM:
+ lex >> allowed_occurrences_per_item_;
+ break;
case IL_END:
getout = true;
break;
std::set<docstring> const & allowedInLayouts() const { return allowed_in_layouts_; }
///
int allowedOccurrences() const { return allowed_occurrences_; }
+ ///
+ bool allowedOccurrencesPerItem() const { return allowed_occurrences_per_item_; }
private:
///
void makeDefaultCSS() const;
std::set<docstring> allowed_in_layouts_;
///
int allowed_occurrences_ = -1;
+ ///
+ bool allowed_occurrences_per_item_ = false;
};
///