On Sunday 27 July 2008 17:09, Steve Litt wrote:
> Hi all,
>
> I'm not calling this a bug because maybe it was never intended to work this
> way, but if I create and use two LyX styles, Code1 and Code2, each of them
> with CopyStyle LyX-Code, then on conversion to PDF I get the following
> error message:
>
> LaXeX Error: Command \lyxcode already defined
>
> I can use all Code1, or all Code2, or all LyX-Code, but if I have any two
> of them in the document, I get an error like described above.
>
> The attached mini document (1.5.3 produced) plus the mini-layout produce
> the symptom.
>
> Is there a simple way I can use CopyStyle with LyX-Code and not get this
> error?
>
> Thanks
>
> SteveT
>
> Steve Litt
> Recession Relief Package
> http://www.recession-relief.US
Hi all,
I found a fix I can use locally, and a fix that could be made with the LyX
distribution. Let me start with the latter...
LyX-Code is defined in lyxdir/layouts/lyxmacros.inc thusly:
Style LyX-Code
Margin Static
LatexType Environment
LatexName lyxcode
NextNoIndent 1
LeftMargin MMM
RightMargin MMM
TopSep 0.5
BottomSep 0.5
Align Left
AlignPossible Block, Left, Right, Center
LabelType No_Label
FreeSpacing 1
Preamble
\newenvironment{lyxcode}
{\begin{list}{}{
\setlength{\rightmargin}{\leftmargin}
\setlength{\listparindent}{0pt}% needed for AMS
classes
\raggedright
\setlength{\itemsep}{0pt}
\setlength{\parsep}{0pt}
\normalfont\ttfamily}%
\item[]}
{\end{list}}
EndPreamble
Font
Family Typewriter
EndFont
End
Notice that the LaTeX environment, lyxcode, is defined within the LyX
environment definition, so if LyX-Code is mentioned twice, \lyxcode is
defined twice, which is an error.
To fix the problem, the developers could remove everything from Preamble to
EndPreamble in the LyX-Code definition, and put it after the "Format 4" and
before any LyX style definitions. While you're at it, you might as well pull
the LaTeX definitions out of LyX environments Address and Right_Address,
because those will have the same problems with CopyStyle. Obviously, there
need be only a single Preamble/EndPreamble pair globally in this file.
It's nice and modular to put the LaTeX definition inside the LyX definition,
but doing so greatly reduces the value of CopyStyle, so I'd recommend against
it.
I didn't want to mess with the distribution, so I did the following locally,
within my layout file...
#############################################
Preamble
\newenvironment{litt_lyxcode}
{\begin{list}{}{
\setlength{\rightmargin}{\leftmargin}
\setlength{\listparindent}{0pt}% needed for AMS classes
\raggedright
\setlength{\itemsep}{0pt}
\setlength{\parsep}{0pt}
\normalfont\ttfamily}%
\item[]}
{\end{list}}
%%%% OTHER LATEX STUFF GOES HERE
EndPreamble
Style litt_LyX-Code
Margin Static
LatexType Environment
LatexName litt_lyxcode
NextNoIndent 1
LeftMargin MMM
RightMargin MMM
TopSep 0.5
BottomSep 0.5
Align Left
AlignPossible Block, Left, Right, Center
LabelType No_Label
FreeSpacing 1
Preamble
EndPreamble
Font
Family Typewriter
EndFont
End
Style Code
CopyStyle litt_LyX-Code
End
Style Codeinbox
CopyStyle litt_LyX-Code
End
Style Codetext
CopyStyle litt_LyX-Code
End
#############################################
In other words, I copied and pasted \lyxcode to \litt_lyxcode within my layout
file, and copied and pasted LyX-Code (minus the Preamble/EndPreamble section)
to litt_LyX-Code within my layout file, and then did CopyStyle on
litt_LyX-Code. It worked perfectly!
Thanks
SteveT
Steve Litt
Recession Relief Package
http://www.recession-relief.US