On 05/31/2011 06:12 PM, Peter Flynn wrote:
> I am having some trouble understanding how to implement a new
> environment in an existing .layout file. The documentation covers the
> principle, but not the detail, especially about how to enable other
> environments (like lists) *inside* the one I am implementing, and how
> to get LyX to prompt for any arguments required in my environment.
>
> I have defined and tested the environment in LaTeX, and I then add to
> the .layout file:
>
>> Style Foo
>>   LatexType     Environment
>>   LatexName     foo
>>   ParSep        0.5
>>
>>   Font
>>     Size        Small
> >     Series      Normal
>>   EndFont
>>
>>   Preamble
>>     \newenvironment{foo}
>>       {\begin{quotation}\small\raggedright\noindent\ignorespaces}
> >       {\par\end{quotation}}
>>   EndPreamble
>> End
>
> When I open a .lyx file, the entry for a Foo is there in the menu, and
> I can add a few words and paragraphs and it correctly exports:
>
>> \begin{foo}
>> a few words
>>
>> and paragraphs\end{foo}
>
> All well so far.
>
> But an environment should be able to contain all kinds of other
> environment, like lists. If I try to add an itemized list between the
> two paragraphs above, the exported LaTeX shows that LyX has terminated
> the foo environment prematurely, inserted the list *outside* the
> environment, and then created a new instance of the foo environment to
> hold the second paragraph:
>
> > \begin{foo}
> > a few words\end{panel}
> > \begin{itemize}
> > \item blort\end{itemize}
> > \begin{panel}
> > and paragraphs\end{foo}
>
> How do I tell LyX that lists (for example; and much other stuff) is
> permitted inside a Foo environment? Is there a setting or switch that
> tells LyX to allow nested environments globally, or does it have to be
> done on an environment by environment basis?
>
This is normal LyX behavior. If you want the list inside, then you need
to do Edit>Increase List Depth on the list items. You can do this when
you insert the list, and the rest will be correct. Think of this as a
nesting system.

> Bonus question: I will eventually want to extend the environment to
> add a box and shaded background, allowing the user to specify width
> and color in mandatory arguments to the Foo environment. Writing the
> LaTeX definition for the Preamble is easy; but how do I tell LyX that
> the environment has two arguments?
>
RequiredArgs 2

> I can see that an Inset affords the option to add tokens or values,
> but I can't see how to make one compulsory, so that it pops up the
> moment you add a Foo from the menu.
>
There's no system for automatic popup, etc. You add the arguments via
the poorly named Insert>Short Title, just as for optional arguments. The
UI here definitely could be better.

> Final plea: I have been unable to find a formal list of all the
> keywords for a .layout file, with their syntax and application. Does
> such a list exist yet?
>
As Bennett mentioned, all of these are documented in Chapter 5 of the
Customization manual.

Richard

Reply via email to