4

I would like to create a style for a command that takes multiple arguments:

\classify{A}{B}{C}

I started creating a style

Style Classify
    Category   FrontMatter

    LatexType  Command
    LatexName  classify
End

but this kind of style works only for commands that take a single argument. How can I modify the style definition so that it accepts multiple arguments and optional arguments?

gioele
  • 795

2 Answers2

4

This is not possible in LyX 2.0.x. LyX 2.1 provides a very flexible argument framework. LyX 2.1 will be released in a couple of months. You can use the development version (pretty stable) now alongside your current version on Ubuntu very easily with the LyX PPA.

To accomplish what you want to do in LyX 2.1, use the following:

Style Classify
    Category   FrontMatter
    LatexType  Command
    LatexName  refine
 Argument 1
    Mandatory 1
    LabelString "FirstMandatoryArg"
  EndArgument
 Argument 2
    Mandatory 1
    LabelString "SecondMandatoryArg"
  EndArgument
End

Attached is a screenshot that shows you how to use it. Note that the items are greyed out in the Insert menu because I've already inserted them. Note also that the order doesn't matter (thus A C B will still be {A}{B}{C}). You can see this in the LaTeX preview at the bottom of the screenshot.

enter image description here

scottkosty
  • 13,164
3

It is possible in LyX 2.0 using insets as named parameters inside of a frame inset. The downside is that there is less checking, so you might get side effects if you put other stuff like spaces or parskips in there.

My layout defines a Synopsis inset for 1 to 4 columns using tabulary (and ugly colors). Table heads and caption are optional. The Head and Text insets are supposed to be used multiple times.

Here are two examples, one with table heads and caption, and one without:

Synopsis inset in Lyx

The result:

Result in PDF viewer

The key is to first collect all necessary parameters and store them locally. Here's the layout code:

#\DeclareLyXModule{Synopsis} 
#DescriptionBegin 
#     Synopsis Inset Example for LyX 2.0
#     A frame inset with multiple, mostly optional named parameter insets.
#
#     Usage:
#         Synopsis[ SynopsisHead... SynopsisText... SynopsisCaption ]
#         Synopsis[ SynopsisHead+SynopsisText... SynopsisCaption ]
#
#     There must be 1..4 Texts, everything else is optional.
#     If you use Heads you must define one Head for each Text.
#     The 1st Head must be before the 1st Text.
#DescriptionEnd 

Format 21

Preamble

\usepackage{etoolbox}
\usepackage{tabulary}

\def\setSysnopsisColumnType#1{\newcolumntype{Q}{#1}}%

\long\def\synopsisFrame#1{%
    \begin{table}[h]%
        \small%
        %
        %%% execute parameter insets
        %%% (there should be nothing else, not even parskips!)
        #1%
        %
        %%% set table format
        \expandafter\setSysnopsisColumnType\expandafter{\theSynopsisFormat}%
        \begin{tabulary}{\textwidth}{Q}%
            %
            %%% table head (depends on body)
            \ifdef{\theSynopsisHeadi}{%
                \theSynopsisHeadi%
                \ifdef{\theSynopsisTextii}{ & \theSynopsisHeadii}{}%
                \ifdef{\theSynopsisTextiii}{ & \theSynopsisHeadiii}{}%
                \ifdef{\theSynopsisTextiv}{ & \theSynopsisHeadiv}{}%
                \\[1em]
            }{}%
            %
            %%% table body
            \theSynopsisTexti
            \ifdef{\theSynopsisTextii}{ & \theSynopsisTextii}{}%
            \ifdef{\theSynopsisTextiii}{ & \theSynopsisTextiii}{}%
            \ifdef{\theSynopsisTextiv}{ & \theSynopsisTextiv}{}%
            %
        \end{tabulary}%
        \ifdef{\theSynopsisCaption}{\caption{\theSynopsisCaption}}{}%
    \end{table}%
}

\long\def\synopsisHead#1{%
    %%% set next Head
    \ifdef{\theSynopsisHeadiv}{%
        \PackageError{SynopsisInset}{Too many Heads.}%
            {Only 4 Head insets are supported.}%
    }{%
        \ifdef{\theSynopsisHeadiii}{%
            \def\theSynopsisHeadiv{#1}%
        }{%
            \ifdef{\theSynopsisHeadii}{%
                \def\theSynopsisHeadiii{#1}%
            }{%
                \ifdef{\theSynopsisHeadi}{%
                    \def\theSynopsisHeadii{#1}%
                }{%
                    \def\theSynopsisHeadi{#1}%
                }%
            }%
        }%
    }%
}

\long\def\synopsisText#1{%
    %%% set next Text
    \ifdef{\theSynopsisTextiv}{%
        \PackageError{SynopsisInset}{Too many Texts.}%
            {Only 4 Text insets are supported.}%
    }{%
        \ifdef{\theSynopsisTextiii}{%
            \def\theSynopsisTextiv{#1}% set Text
            \def\theSynopsisFormat{|J|J|J|J|}% set format
        }{%
            \ifdef{\theSynopsisTextii}{%
                \def\theSynopsisTextiii{#1}%
                \def\theSynopsisFormat{|J|J|J|}%
            }{%
                \ifdef{\theSynopsisTexti}{%
                    \def\theSynopsisTextii{#1}%
                    \def\theSynopsisFormat{|J|J|}%
                }{%
                    \def\theSynopsisTexti{#1}%
                    \def\theSynopsisFormat{|J|}%
                }%
            }%
        }%
    }%
}

\long\def\synopsisCaption#1{%
    \def\theSynopsisCaption{#1}%
}

EndPreamble


InsetLayout Flex:Synopsis
    LyXType Custom
    LabelString Synopsis
    LatexType Command
    LatexName synopsisFrame
    BgColor blue
    ContentAsLabel 0
    CustomPars 1
    Decoration Classic
    LabelFont        
        Color        blue
        Size         Small
    EndFont
End

InsetLayout Flex:SynopsisHead
    LyXType Custom
    LabelString Head
    LatexType Command
    LatexName synopsisHead
    BgColor white
    ContentAsLabel 0
    CustomPars 1
    Decoration Classic
    LabelFont        
        Color        blue
        Size         Small
    EndFont
End

InsetLayout Flex:SynopsisText
    LyXType Custom
    LabelString Text
    LatexType Command
    LatexName synopsisText
    BgColor white
    ContentAsLabel 0
    CustomPars 1
    Decoration Classic
    LabelFont        
        Color        blue
        Size         Small
    EndFont
End

InsetLayout Flex:SynopsisCaption
    LyXType Custom
    LabelString Caption
    LatexType Command
    LatexName synopsisCaption
    BgColor white
    ContentAsLabel 0
    CustomPars 1
    Decoration Classic
    LabelFont        
        Color        blue
        Size         Small
    EndFont
End
user24582
  • 191