我想为接受多个参数的命令创建一个样式:
\classify{A}{B}{C}
我开始创造一种风格
Style Classify
Category FrontMatter
LatexType Command
LatexName classify
End
但这种样式仅适用于采用单个参数的命令。如何修改样式定义以使其接受多个参数和可选参数?
答案1
这在 中是不可能的LyX 2.0.x
。LyX 2.1
提供了一个非常灵活的参数框架。LyX 2.1
将在几个月后发布。您现在可以在 Ubuntu 上非常轻松地使用开发版本(相当稳定)以及您当前的版本利克斯PPA。
为了完成您想要做的事情LyX 2.1
,请使用以下命令:
Style Classify
Category FrontMatter
LatexType Command
LatexName refine
Argument 1
Mandatory 1
LabelString "FirstMandatoryArg"
EndArgument
Argument 2
Mandatory 1
LabelString "SecondMandatoryArg"
EndArgument
End
附件是一张向您展示如何使用它的屏幕截图。请注意,插入菜单中的项目呈灰色,因为我已经插入了它们。还请注意,顺序无关紧要(因此 ACB 仍为 {A}{B}{C})。您可以在屏幕截图底部的 LaTeX 预览中看到这一点。
答案2
可以将LyX 2.0
insets 用作框架 inset 内的命名参数。缺点是检查较少,因此如果您在其中放入其他内容(如空格或 parskips),可能会产生副作用。
我的布局使用tabulary
(和丑陋的颜色)为 1 到 4 列定义了一个概要插入。表头和标题是可选的。表头和文本插入应该多次使用。
这里有两个示例,一个带有表头和标题,一个没有:
结果:
关键是首先收集所有必要的参数并将它们存储在本地。以下是布局代码:
#\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