If LyX reads in a table with columns specified so: <column alignment="center" valignment="top" leftline="true" width="0pt"> <column alignment="block" valignment="top" leftline="true" rightline="true" width="4cm" special="||p{4cm}||">
The table appears on the screen as | foo | bar | Export to LaTeX, which stores this info as {|c||p{4cm}||} Run it through a modified reLyX, creating a LyX file <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt"> <column alignment="block" valignment="top" leftline="true" rightline="true" width="4cm" special="|p{4cm}||"> Which appears on screen as | foo || bar | This being the best that LyX can do with the visual rendering of this data. Proof therefore that reLyX is smart ;-) Actually, this proves too things: 1. That LyX's table format is crap. The LaTeX format is unambiguous and clear because it has separated the concept of the column from the concept of the lines bounding it. LyX articially splits these lines into beloning to either the column to the left or the column to the right. Result: multiple ways of providing the same information. 2. The reLyX has to jump through a huge number of hoops to go from LaTeX's simple data format to LyX's complex and ambiguous one if we want also to maximise the visual effect. Note that there is no unique way of generating the LyX format, so we may as well try and make it pretty; we're not being 'smart' for the sake of it. I append the perl that got us there for José's benefit, since his python algorithm is incorrect at the moment and there's no need for us both to suffer. José, this subroutine is called for each column in the table, being also passed its RH neighbour. Best wishes, Angus my %TableAlignments_221 = ('l' => 'left', 'r' => 'right', 'c' => 'center'); sub print_info_221 { # print out header information for this column my $current = shift; my $right = shift; # lyxformat 221 can only accomodate 'true' and 'false' values for # the lines bounding the column. Thus we must manipulate the # number of lines data available to us if we are to maximise the # WYSIWYG effect. # The number of lines on the LHS of column $current has # been manipulated already by the column to its left. # We need concern ourselves only with the RHS of $current my $nlines = $current->{"right_line"}; $nlines += $right->{"left_line"} if (defined($right)); # Given the total number of lines separating the two columns, # we can now split them between the columns to maximise the # WYSIWYG effect. if ($nlines == 1) { $current->{"right_line"} = 1; $right->{"left_line"} = 0 if (defined($right)); } elsif ($nlines == 2) { if (defined($right)) { $current->{"right_line"} = 1; $right->{"left_line"} = 1; } } elsif ($nlines > 2) { if (defined($right)) { $current->{"right_line"} = $nlines - 1; $right->{"left_line"} = 1; } } # In order to ensure the LaTeX remains unchanged, we use the # $special field. my $special = $current->{"special"}; if ($special eq '' && $current->{"right_line"} > 1) { if ($current->{"pwidth"} eq '') { $special = $current->{"alignment"}; } else { $special = 'p{' . $current->{"pwidth"} . '}'; } } if ($special ne '') { $special = '|' x $current->{"left_line"} . $special . '|' x $current->{"right_line"}; } # Special case $alignment if using 'p' columns. my $alignment = $TableAlignments_221{$current->{"alignment"}}; $alignment = 'block' if ($current->{"pwidth"} ne ''); # width is always output my $width = $current->{"pwidth"}; $width = '0pt' if ($width eq ''); # Finally, generate the output. my $to_print = "<column" . RelyxTable::write_string("alignment", $alignment) . RelyxTable::write_string("valignment", "top") . RelyxTable::write_bool("leftline", $current->{"left_line"}) . RelyxTable::write_bool("rightline", $current->{"right_line"}) . RelyxTable::write_string("width", $width) . RelyxTable::write_string("special", $special) . ">\n"; return $to_print; } --