lyx 在自定义布局中创建标签

lyx create label in custom layout

我有一个自定义布局,它向 LyX 添加了 "field" 样式。每次创建 "field" 时,我还想在 LyX 中为 "field" 附加一个相应的标签。有没有办法在 LyX 中以编程方式执行此操作?

Counter fieldCnt
LabelString          "Field: \arabic{fieldCnt}."
PrettyFormat         "Field: ##"
End

AddToPreamble

\usepackage{tocloft}
\usepackage{ifthen}
\usepackage{nameref}%
\usepackage{hyperref}%
%\usepackage{refstyle}
\newcommand{\listfieldname}{List of Fields}

\newref{field}{ %
%refcmd = {\ref{#1}, `\nameref{#1}'},
name = {Field~},
names = {Field~},
Name = {Field~},
Names = {Field~},
rngtxt = \RSrngtxt,
lsttxt = \RSlsttxt
}

EndPreamble

Style Field1
Category              Field
RefPrefix field
LatexType Command
LatexName field
LabelType Counter
LabelCounter          fieldCnt
LabelString           "Field \arabic{fieldCnt}: "
OptionalArgs 1

LabelSep              xxx
ParSep                0.7
Margin                Dynamic
Font
Series      Bold
EndFont
Preamble
\newlistof{field}{field}{\listfieldname}
\newcommand{\field}[1]{%
 \refstepcounter{field}
 \par\noindent\textbf{Field \thefield: #1}
 \addcontentsline{field}{field}{\protect\numberline{\thefield}#1}\par}

\setcounter{fielddepth}{1}
EndPreamble
End

无法在布局文件的样式部分添加 LyX 代码。