]> git.lyx.org Git - features.git/commitdiff
When in doubt, do as LyX does
authorAngus Leeming <leeming@lyx.org>
Tue, 11 Feb 2003 11:24:31 +0000 (11:24 +0000)
committerAngus Leeming <leeming@lyx.org>
Tue, 11 Feb 2003 11:24:31 +0000 (11:24 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6089 a592a061-630c-0410-9148-cb99ea01b6c8

lib/ChangeLog
lib/reLyX/BasicLyX.pm

index 66fe6de5666aedd4db086dab8a0f09d24a36bcfa..924f152a4cbde3313ce5468af17cb474f8954432 100644 (file)
@@ -1,3 +1,9 @@
+2003-02-11  Angus Leeming  <leeming@lyx.org>
+
+       * 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  <leeming@lyx.org>
 
        * reLyX/BasicLyX.pm: add support for minipages. The inner-pos optional
index e2d730b7e506cf6bc44b9a80b1261aff2ab41d05..1b14bf4583c1b7751037b901dc61ae4f0e573052 100644 (file)
@@ -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