On 05/30/2010 12:23 PM, Artimess wrote:
I would like to create a LyX module for the environment that I
borrowed from the tex version of memoir book (code e in blue). I
used Steve Litt's tutorial to experiment with it (code in green),
when I run I get two errors in red.
I would appreciate if you explain to me what I am doing wrong.
There are a lot of errors in the LaTeX code. Always try to get the LaTeX
code working in a trivial LaTeX file, outside of LyX. It's too hard to
work on the LaTeX and the module code at the same time.
In any event, this works for me:
%%%%% LaTeX syntax
%%%% control space above/below center environment
\newenvironment{tightcenter}%
{\setlength{\topsep}{0.25in}\begin{list}{}{}\item\relax}
{\end{list}}
\newenvironment{syntax}{%
~\\
\begin{tightcenter}
\begin{tabular}{|p{0.9\linewidth}|}\hline
}%
{%
\\
\hline
\end{tabular}
\end{tightcenter}
~\\
}
That said, I'm not sure \topsep can be controlled that way. See here:
http://dcwww.camd.dtu.dk/~schiotz/comp/LatexTips/LatexTips.html
Also, It is preferable to have this as module rater than layout how
should I go about doing it as a module?
Look at one of the module files that ships with LyX for an example you
can adapt. From your point of view, the difference is only in the
"header" of the file. Instead of \DeclareLaTeXClass you have
\DeclareLyXModule, etc. See also section 5.2.1 of the Customization manual.
#% Do not delete the line below; configure depends on this
# \DeclareLaTeXClass[book]{mybook}
You need a format line, like
Format 11
All LyX layout files must have such a line.
Input stdclass.inc
Preamble
%%%%% LaTeX syntax
%%%% control space above/below center environment
\newcommand*{\tightcenter}{%
\topsep=0.25\onelineskip\trivlist \centering\item\relax}
\def\endtightcenter{\endtrivlist}
\newenvironment{syntax}{%
~\\
\begin{tightcenter}
\begin{tabular}{|p{0.9\linewidth}|} \hline}%
{\hline
\end{tabular}
\end{tightcenter}
~\\
}
EndPreamble
You presumably want to use "AddToPreamble" here. The straight "Preamble"
will overwrite any previous Preamble declaration, which you do not want.
Also, since the syntax part, at least, applies only to the Syntax style,
it would be better to put it in a Preamble block within the Style
declaration. Then the code will go into the preamble only if the Syntax
style is used. Look e.g. at hanging.module for how this is done.
Style Syntax
Style Syntax
One is enough!
CopyStyle Standard
LatexType Environment
LatexName Syntax
LeftMargin "MMMMMM"
RightMargin "MMMMMM"
Font
Shape Italic
EndFont
End