# LyX style for command with multiple arguments

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?

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.

• What are the suggested workarounds for 2.0. I think that many other classes suffer the same problem, don't they? – gioele May 16 '13 at 20:43
• @gioele As far as I know, ERT (that is, not using a layout) is the only workaround. – scottkosty May 16 '13 at 20:45
• It is possible (see my answer), but this is the canonical way. – user24582 Sep 13 '15 at 11:57
• @scottkosty: Is there an option in LyX to have a macro that doesn't take an argument? Reference: How to do \hrulefill in LyX without a TeX inset – Werner Jul 25 '16 at 15:46
• @Werner unfortunately I think not (but I'm not completely sure). – scottkosty Jul 25 '16 at 16:06

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:

The result:

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 ]
#
#     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)
\\[1em]
}{}%
%
%%% table body
\theSynopsisTexti
\ifdef{\theSynopsisTextii}{ & \theSynopsisTextii}{}%
\ifdef{\theSynopsisTextiii}{ & \theSynopsisTextiii}{}%
\ifdef{\theSynopsisTextiv}{ & \theSynopsisTextiv}{}%
%
\end{tabulary}%
\ifdef{\theSynopsisCaption}{\caption{\theSynopsisCaption}}{}%
\end{table}%
}

{Only 4 Head insets are supported.}%
}{%
}{%
}{%
}{%
}%
}%
}%
}%
}

\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

LyXType Custom
LatexType Command
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