On Mon, Feb 05, 2001 at 10:31:40PM +0200, Dekel Tsur wrote:
> On Mon, Feb 05, 2001 at 09:22:07PM +0100, Lars Gullik BjRnnes wrote:
> > Why not switch to an xml like format?
> > 
> > This could also perhaps help the xml-format project a bit.
> > 
> > <language>
> >         <language-name>afrikaans</language-name>
> >         <babel-name>afrikaans</babel-name>
> >         <gui-name>Afrikaans</gui-name>
> >         <language-encoding>iso8859-1</language-encoding>
> > </language>
> 
> So the layouts files should also be stored in xml format.
> I will let others do these changes.

OK.

Attached you'll find layout2xml.pl. The other attachment is the converted
stdlists.inc

I don't actually know xml, so I've done a very rudimentary job. I'm hoping
someone will give me a bit more detail on exactly what you want. Right now:

- <Layout name="filename with the .layout removed">...</Layout> is placed
  around the whole document (Since I only remove .layout, .inc remains, by
the way. Of course that could be changed.)

- each comment line turns into <!--...-->

- Style & other blocks that nest turn into <Style value="itemize">...</Style>

- Attributes become something like <AlignPossible value="Block, Left">

- Preamble is copied verbatim until EndPreamble and put inside
  a <Preamble>...</Preamble> block.

- Some rudimentary formatting is done to make the xml human-readable

I've tried it so far on the files stdlists.inc and revtex4.layout, and it
seems to handle everything. I didn't do anything special with Input, and
an attribute like Columns, which applies to the whole textclass, is treated
the same way as a style sub-attribute like AlignPossible. So let me know
what needs to be changed.

You probably want to be more sophisticated than using 'value="whatever"' for
everything. For example, you may want to have some text not actually in the
<> blocks. But I've never written xml, so I wouldn't know. Try running it on
a couple files, and see what you get, and tell me what changes I should make.

-Amir
#!/usr/bin/perl -w

use strict;

my $Verbatim = 0;
my %BlockEnd = (
    "Font" => "EndFont",
    "LabelFont" => "EndFont",
    "TextFont" => "EndFont",
    "Style" => "End",
    "ClassOptions" => "End",
);
my @ExpectedEnd = ();
my @Block = ();

my $name = $ARGV[0];
$name =~ s/\.layout$//;
print qq(<Layout name="$name">\n\n);

while (<>) {
    if ($Verbatim) {
        if (/^\s*EndPreamble/) {
            $Verbatim = 0;
            print "  " x @Block;
            print "</Preamble>\n";
        } else {
            print;
        }

    # Empty line
    } elsif (/^\s*$/) {
        print;

    # Comment
    } elsif (/^\s*#/) {
        s/#(.*)/<!--$1-->/;
        print;

    # End of current block
    } elsif (@ExpectedEnd && /^\s*$ExpectedEnd[-1]\s*$/) {
        pop @ExpectedEnd;
        my $str = pop @Block;
        print "  " x @Block;
        print qq(</$str>\n);

    # Beginning of other block
    } elsif (/^\s*(\w+)(\s+(\w+))?/i && exists $BlockEnd{$1}) {
        my $blockname = $1;
        my $val = $3;
        my $valstr = $val ? qq( value="$val") : "";
        # Indent before pushing onto @Block
        print "  " x @Block;
        print qq(<$blockname$valstr>\n);
        push @Block, $blockname;
        push @ExpectedEnd, $BlockEnd{$blockname};

    # Attribute
    } elsif (/\s*(\w+)\s+(\S.*)/) {
        my ($name, $val) = ($1, $2);
        print "  " x @Block;
        print qq(<$name value="$val">\n);

    } elsif (/\s*Preamble/) {
        $Verbatim = 1;
        print "  " x @Block;
        print "<Preamble>\n";

    } else {
        warn "unhandled line: $_, expect is @ExpectedEnd";
        print;
    }
}

print "</Layout>\n";
<Layout name="stdlists.inc">

<!-- Standard textclass definition file. Taken from initial LyX source code-->
<!-- Author : Matthias Ettrich <[EMAIL PROTECTED]>-->
<!-- Transposed by Pascal André <[EMAIL PROTECTED]>-->
<!-- Heavily modifed and enhanced by several developers.-->

<!-- This include files contains various standard environments for lists.-->

<!-- Itemize style definition-->
<Style value="Itemize">
  <Margin value="Static">
  <LatexType value="Item_Environment">
  <LatexName value="itemize">
  <NextNoIndent value="1">
  <LeftMargin value="MMN">
  <LabelSep value="xx">
  <ItemSep value="0.2">
  <TopSep value="0.7">
  <BottomSep value="0.7">
  <ParSep value="0.3">
  <Align value="Block">
  <AlignPossible value="Block, Left">
  <LabelType value="Static">
  <LabelString value="*">
</Style>

<!-- Enumerate style definition-->
<Style value="Enumerate">
  <Margin value="Static">
  <LatexType value="Item_Environment">
  <LatexName value="enumerate">
  <NextNoIndent value="1">
  <LeftMargin value="MMN">
  <LabelSep value="xx">
  <ParSkip value="0.0">
  <ItemSep value="0.2">
  <TopSep value="0.7">
  <BottomSep value="0.7">
  <ParSep value="0.3">
  <Align value="Block">
  <AlignPossible value="Block, Left">
  <LabelType value="Counter_EnumI">
</Style>

<!-- Description style definition-->
<Style value="Description">
  <Margin value="First_Dynamic">
  <LatexType value="Item_environment">
  <LatexName value="description">
  <NextNoIndent value="1">
  <LeftMargin value="MM">
  <LabelSep value="xxx">
  <ParSkip value="0.4">
  <ItemSep value="0.2">
  <TopSep value="0.7">
  <BottomSep value="0.7">
  <ParSep value="0.3">
  <Align value="Block">
  <AlignPossible value="Block, Left">
  <LabelType value="Manual">
  <LabelString value="MM">

  <!-- label font definition-->
  <LabelFont>
    <Series value="Bold">
  </LabelFont>
</Style>

<!-- List style definition-->
<Style value="List">
  <Margin value="Manual">
  <LatexType value="List_Environment">
  <LatexName value="lyxlist">
  <NextNoindent value="1">
  <LabelSep value="xxx">
  <ParSkip value="0.4">
  <TopSep value="0.7">
  <BottomSep value="0.7">
  <ParSep value="0.5">
  <Align value="Block">
  <AlignPossible value="Block, Left">
  <LabelType value="Manual">
  <LabelString value="00.00.0000">

  <!--define the environment lyxlist-->
  <Preamble>
  \newenvironment{lyxlist}[1]
    {\begin{list}{}
      {\settowidth{\labelwidth}{#1}
       \setlength{\leftmargin}{\labelwidth}
       \addtolength{\leftmargin}{\labelsep}
       \renewcommand{\makelabel}[1]{##1\hfil}}}
    {\end{list}}
  </Preamble>

</Style>
</Layout>

Reply via email to