From: Angus Leeming Date: Tue, 11 Feb 2003 11:24:31 +0000 (+0000) Subject: When in doubt, do as LyX does X-Git-Tag: 1.6.10~17569 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=9a2c09c1ef9ca7ae4b3fcbbf44df1cef852dd070;p=features.git When in doubt, do as LyX does git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6089 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/lib/ChangeLog b/lib/ChangeLog index 66fe6de566..924f152a4c 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,9 @@ +2003-02-11 Angus Leeming + + * reLyX/BasicLyX.pm: Do as LyX does: wrap the minipage width and + height output in inverted commas and strip the space from "4.5 cm". + Factorise the code by defining sub getAsLyXLength. + 2003-02-11 Angus Leeming * reLyX/BasicLyX.pm: add support for minipages. The inner-pos optional diff --git a/lib/reLyX/BasicLyX.pm b/lib/reLyX/BasicLyX.pm index e2d730b7e5..1b14bf4583 100644 --- a/lib/reLyX/BasicLyX.pm +++ b/lib/reLyX/BasicLyX.pm @@ -218,14 +218,6 @@ my $MathEnvironments = "(math|displaymath|xxalignat|(equation|eqnarray|align|ali # ListLayouts may have standard paragraphs nested inside them. my $ListLayouts = "Itemize|Enumerate|Description"; -# Striaght translation of LaTeX lengths to LyX ones. -my %lengthAsLyXString = ('\textwidth' => 'text%', - '\columnwidth' => 'col%', - '\paperwidth' => 'page%', - '\linewidth' => 'line%', - '\paperheight' => 'pheight%', - '\textheight' => 'theight%'); - # passed a string and an array # returns true if the string is an element of the array. sub foundIn { @@ -360,6 +352,34 @@ sub ending_math { return 0; } + +# Straight translation of LaTeX lengths to LyX ones. +my %lengthAsLyXString = ('\textwidth' => 'text%', + '\columnwidth' => 'col%', + '\paperwidth' => 'page%', + '\linewidth' => 'line%', + '\paperheight' => 'pheight%', + '\textheight' => 'theight%'); + +sub getAsLyXLength { + my $LatexLength = shift; + + my $LyXLength = ''; + # If $LatexLength is something like '4.5\columnwidth', translate into + # LyXese. + if ($LatexLength =~ /([0-9]+\.?[0-9]*)\s*(\\[a-z]*)/) { + if (defined($lengthAsLyXString{$2})) { + $LyXLength = ($1 * 100) . $lengthAsLyXString{$2}; + } + } else { + $LyXLength = $LatexLength; + # Remove any spaces from '4.5 cm' + $LyXLength =~ s/\s*//g; + } + + return $LyXLength; +} + ########################## MAIN TRANSLATOR SUBROUTINE ##################### sub basic_lyx { # This subroutine is called by Text::TeX::process each time subroutine @@ -1046,14 +1066,7 @@ sub basic_lyx { my $height = '0pt'; $tok = $fileobject->eatOptionalArgument; if (defined($tok->print)) { - $height = $tok->print; - # if something like '4.5\columnwidth', translate into - # LyXese. - if ($height =~ /([0-9.]*)\s*(\\[a-z]*)/) { - if (defined($lengthAsLyXString{$2})) { - $height = ($1 * 100) . $lengthAsLyXString{$2}; - } - } + $height = getAsLyXLength($tok->print); } # Read the inner-pos optional argument, if it exists @@ -1067,21 +1080,12 @@ sub basic_lyx { # Read the width as (a reference to) an array of tokens. $tok = $fileobject->eatBalanced; - # $width is Something like either '4.5cm' or '\columnwidth'. - my $width = pop(@{$tok})->print; - # If $width is something like '\columnwidth', then manipulate - # it into LyX format and also extract the length itself. - if (defined($lengthAsLyXString{$width})) { - $width = $lengthAsLyXString{$width}; - my $val = pop(@{$tok}); - $val = (defined($val)) ? $val->print : '0'; - $width = ($val * 100) . $width; - } + my $width = getAsLyXLength($tok->exact_print); print OUTFILE "position $pos\n"; print OUTFILE "inner_position $innerpos\n"; - print OUTFILE "height $height\n"; - print OUTFILE "width $width\n"; + print OUTFILE "height \"$height\"\n"; + print OUTFILE "width \"$width\"\n"; print OUTFILE "collapsed false\n"; # \begin document