mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-09-19 22:40:26 +00:00
Make a valid LaTeX length understandable to LyX.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6245 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
1c9c369402
commit
d829ec607e
@ -1,3 +1,7 @@
|
||||
2003-02-25 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* reLyX/BasicLyX.pm (regularizeLatexLength, getAsLyXLength):
|
||||
make a valid LaTeX length understandable to LyX.
|
||||
|
||||
2003-02-21 André Pönitz <poenitz@gmx.net>
|
||||
|
||||
|
@ -353,28 +353,54 @@ sub ending_math {
|
||||
}
|
||||
|
||||
|
||||
# Straight translation of LaTeX lengths to LyX ones.
|
||||
my %lengthAsLyXString = ('\textwidth' => 'text%',
|
||||
'\columnwidth' => 'col%',
|
||||
'\paperwidth' => 'page%',
|
||||
'\linewidth' => 'line%',
|
||||
'\paperheight' => 'pheight%',
|
||||
'\textheight' => 'theight%');
|
||||
|
||||
sub getAsLyXLength {
|
||||
sub regularizeLatexLength {
|
||||
my $LatexLength = shift;
|
||||
|
||||
my $LyXLength = '';
|
||||
# Remove any whitespace
|
||||
$LatexLength =~ s/\s//g;
|
||||
# Remove a leading '+' as unnecessary
|
||||
$LatexLength =~ s/^\+?(\d)/$1/;
|
||||
# Split into value and unit parts
|
||||
my $val;
|
||||
my $unit;
|
||||
if ($LatexLength =~ /(-?\d+[.,]?\d*)(\\?[a-zA-Z]*)$/) {
|
||||
$val = $1;
|
||||
$unit = $2;
|
||||
}
|
||||
# If the input is invalid, return what we have.
|
||||
return $LatexLength if ($val eq '' || $unit eq '');
|
||||
|
||||
# '4,5' is a valid LaTeX number. Change it to '4.5'
|
||||
$val =~ s/,/./;
|
||||
# If the unit is not a LaTeX macro, then ensure it is lower case
|
||||
if (!($unit =~ /^\\/)) {
|
||||
$unit =~ s/([a-z]*)/\L$1/i;
|
||||
}
|
||||
|
||||
$LatexLength = $val . $unit;
|
||||
return $LatexLength;
|
||||
}
|
||||
|
||||
|
||||
sub getAsLyXLength {
|
||||
# Straight translation of LaTeX lengths to LyX ones.
|
||||
my %lengthAsLyXString = ('\textwidth' => 'text%',
|
||||
'\columnwidth' => 'col%',
|
||||
'\paperwidth' => 'page%',
|
||||
'\linewidth' => 'line%',
|
||||
'\paperheight' => 'pheight%',
|
||||
'\textheight' => 'theight%');
|
||||
|
||||
my $LatexLength = shift;
|
||||
$LatexLength = regularizeLatexLength($LatexLength);
|
||||
|
||||
my $LyXLength = $LatexLength;
|
||||
# If $LatexLength is something like '4.5\columnwidth', translate into
|
||||
# LyXese.
|
||||
if ($LatexLength =~ /([0-9]+\.?[0-9]*)\s*(\\[a-z]*)/) {
|
||||
if ($LatexLength =~ /([+-]?\d+\.?\d*)(\\[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;
|
||||
|
Loading…
Reference in New Issue
Block a user