2014-11-12 19:18 GMT+01:00 Ernesto Posse:
> Hi. I'm trying to define my own layout file and I ran into this situation:
> I need a style whose latex command must go into the preamble (as required
> by the underlying latex class), but I need to define my own command for the
> style because the one provided by the base class doesn't work well with the
> way styles work in the LyX UI.
>
> The problem is that styles which have been declared as "InPreamble 1" get
> their code generated before the user preamble which defines the required
> latex command, and therefore, when compiling, LaTeX will stop with an error
> saying that the control sequence is not defined (because it is defined
> later). The style in question is the following:
>
> Style Category
> InPreamble 1
> LabelType Static
> LabelString "Category"
> LatexType Command
> LatexName ACMCCScategory
> RequiredArgs 3
> Margin Dynamic
> Labelsep xx
> LabelFont
> Family Sans
> Series Bold
> Shape Slanted
> Size Normal
> Color Blue
> EndFont
> Preamble
> \newcommand{\ACMCCScategory}[4]{\category{#1}{#2}{#3}[4]}
> EndPreamble
> End
>
> So as you see, the style uses the custom-defined command \ACMCCScategory,
> but the generated code is this:
>
> \makeatletter
>
>
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
>
>
> \ACMCCScategory{D.2.4}{Software Engineering}{Software/Program
> Verification}{Formal methods}
>
>
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Textclass specific LaTeX commands.
>
> \newcommand{\ACMCCScategory}[4]{\category{#1}{#2}{#3}[4]}
>
>
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
>
> \usepackage{aadl}
>
>
> \makeatother
>
>
> So the problem is evident: the command is defined after it is being used.
>
>
> Is there a way to tell LyX to produce the preamble commands before the "in
> preamble" styles?
>
No, this is not yet possible.
However, if you use LyX 2.1, you do not need an own command, since the
command in question is possible with the help of the new argument syntax:
Style Category
InPreamble 1
LabelType Static
LabelString "Category"
LatexType Command
LatexName category
Argument 1
Mandatory 1
LabelString "CR number"
EndArgument
Argument 2
Mandatory 1
LabelString "Category"
EndArgument
Argument 3
Mandatory 1
LabelString "Sub-Category"
EndArgument
Argument 4
LabelString "Subject Descriptor"
EndArgument
Margin Dynamic
Labelsep xx
LabelFont
Family Sans
Series Bold
Shape Slanted
Size Normal
Color Blue
EndFont
End
This also gives a much better UI, since both the Insert menu and the
argument insets tell you which argument you are actually dealing with. And
the order of insertion does not matter (in contrast to the pre 2.1 argument
insets)
HTH,
Jürgen