Re: reLyX and minipages revisited

2003-02-10 Thread Andre Poenitz
On Sat, Feb 08, 2003 at 05:54:44PM +, Angus Leeming wrote:
  The problem is the % after \end{minipage}. If you remove it, it works
  with Angus patch, and also with the original reLyX.
  This confuses me: I always thought that a % at the end of a line makes
  latex ignore the line break. But this is not the case here. So reLyX
  agrees with my understanding of the %, but not with the one of latex:-(
 
 I'm sure our resident experts will provide us with some illumination.

TeX-wise  % ignores everything up to the end of line, plus leading spaces
at the beginning of the following line.

Andre'

-- 
Those who desire to give up Freedom in order to gain Security,
will not have, nor do they deserve, either one. (T. Jefferson)



Re: reLyX and minipages revisited

2003-02-10 Thread Andre Poenitz
On Sat, Feb 08, 2003 at 05:54:44PM +, Angus Leeming wrote:
> > The problem is the "%" after \end{minipage}. If you remove it, it works
> > with Angus patch, and also with the original reLyX.
> > This confuses me: I always thought that a "%" at the end of a line makes
> > latex ignore the line break. But this is not the case here. So reLyX
> > agrees with my understanding of the "%", but not with the one of latex:-(
> 
> I'm sure our resident experts will provide us with some illumination.

TeX-wise  % ignores everything up to the end of line, plus leading spaces
at the beginning of the following line.

Andre'

-- 
Those who desire to give up Freedom in order to gain Security,
will not have, nor do they deserve, either one. (T. Jefferson)



Re: reLyX and minipages revisited

2003-02-08 Thread Georg Baum
Am Samstag, 8. Februar 2003 03:40 schrieb Angus Leeming:
 Having said that, reLyX without this patch also merges a paragraph ending
 with a minipage with the next paragraph. Kayvan, I've CCed you in the
 vain hope that you might know the answer!

The problem is the % after \end{minipage}. If you remove it, it works with 
Angus patch, and also with the original reLyX.
This confuses me: I always thought that a % at the end of a line makes 
latex ignore the line break. But this is not the case here. So reLyX agrees 
with my understanding of the %, but not with the one of latex:-(

 One final point. the 'height' and 'inner_position' fields are zeroed
 because although insetminipage has them, they appear never, ever to be
 set. Is this simply a limitation of the frontends?

I have this impression. Maybe reLyX should not print them at all? Or does 
lyx have problems if they are missing?

 I tested this patch very hard and attach a little test case for you to
 try out too. Jean-Marc, I think that this too could go in the 1.3.x.
 branch but, of course, leave that to your discretion.

Please apply to 1.3.x. It does work for me too.


Georg





Re: reLyX and minipages revisited

2003-02-08 Thread Angus Leeming
Georg Baum wrote:

 Am Samstag, 8. Februar 2003 03:40 schrieb Angus Leeming:
 Having said that, reLyX without this patch also merges a paragraph ending
 with a minipage with the next paragraph. Kayvan, I've CCed you in the
 vain hope that you might know the answer!
 
 The problem is the % after \end{minipage}. If you remove it, it works
 with Angus patch, and also with the original reLyX.
 This confuses me: I always thought that a % at the end of a line makes
 latex ignore the line break. But this is not the case here. So reLyX
 agrees with my understanding of the %, but not with the one of latex:-(

I'm sure our resident experts will provide us with some illumination.

 One final point. the 'height' and 'inner_position' fields are zeroed
 because although insetminipage has them, they appear never, ever to be
 set. Is this simply a limitation of the frontends?
 
 I have this impression. Maybe reLyX should not print them at all? Or does
 lyx have problems if they are missing?

Looking at the LyX source, there are even hooks present to manipulate their 
values. Just noone has connected these hooks to the GUI. 

 I tested this patch very hard and attach a little test case for you to
 try out too. Jean-Marc, I think that this too could go in the 1.3.x.
 branch but, of course, leave that to your discretion.
 
 Please apply to 1.3.x. It does work for me too.

Not just yet.

This bit works for 0.45\columnwidth = 45col%, but ain't so smart if you 
specify 4.5cm = 450cm ;-)

+   $tok = $fileobject-eatBalanced;
+   $arg = '';
+   foreach (@{$tok}) {
+   my $tmp = $_-print;
+   if (defined($lengthAsLyXString{$tmp})) {
+   $tmp = $lengthAsLyXString{$tmp};
+   } elsif ($tmp =~ /[0-9.]*/) {
+   $tmp *= 100;
+   }
+   $arg .= $tmp;
+   }

-- 
Angus




Re: reLyX and minipages revisited

2003-02-08 Thread Georg Baum
Am Samstag, 8. Februar 2003 03:40 schrieb Angus Leeming:
> Having said that, reLyX without this patch also merges a paragraph ending
> with a minipage with the next paragraph. Kayvan, I've CCed you in the
> vain hope that you might know the answer!

The problem is the "%" after \end{minipage}. If you remove it, it works with 
Angus patch, and also with the original reLyX.
This confuses me: I always thought that a "%" at the end of a line makes 
latex ignore the line break. But this is not the case here. So reLyX agrees 
with my understanding of the "%", but not with the one of latex:-(

> One final point. the 'height' and 'inner_position' fields are zeroed
> because although insetminipage has them, they appear never, ever to be
> set. Is this simply a limitation of the frontends?

I have this impression. Maybe reLyX should not print them at all? Or does 
lyx have problems if they are missing?

> I tested this patch very hard and attach a little test case for you to
> try out too. Jean-Marc, I think that this too could go in the 1.3.x.
> branch but, of course, leave that to your discretion.

Please apply to 1.3.x. It does work for me too.


Georg





Re: reLyX and minipages revisited

2003-02-08 Thread Angus Leeming
Georg Baum wrote:

> Am Samstag, 8. Februar 2003 03:40 schrieb Angus Leeming:
>> Having said that, reLyX without this patch also merges a paragraph ending
>> with a minipage with the next paragraph. Kayvan, I've CCed you in the
>> vain hope that you might know the answer!
> 
> The problem is the "%" after \end{minipage}. If you remove it, it works
> with Angus patch, and also with the original reLyX.
> This confuses me: I always thought that a "%" at the end of a line makes
> latex ignore the line break. But this is not the case here. So reLyX
> agrees with my understanding of the "%", but not with the one of latex:-(

I'm sure our resident experts will provide us with some illumination.

>> One final point. the 'height' and 'inner_position' fields are zeroed
>> because although insetminipage has them, they appear never, ever to be
>> set. Is this simply a limitation of the frontends?
> 
> I have this impression. Maybe reLyX should not print them at all? Or does
> lyx have problems if they are missing?

Looking at the LyX source, there are even hooks present to manipulate their 
values. Just noone has connected these hooks to the GUI. 

>> I tested this patch very hard and attach a little test case for you to
>> try out too. Jean-Marc, I think that this too could go in the 1.3.x.
>> branch but, of course, leave that to your discretion.
> 
> Please apply to 1.3.x. It does work for me too.

Not just yet.

This bit works for 0.45\columnwidth => 45col%, but ain't so smart if you 
specify 4.5cm => 450cm ;-)

+   $tok = $fileobject->eatBalanced;
+   $arg = '';
+   foreach (@{$tok}) {
+   my $tmp = $_->print;
+   if (defined($lengthAsLyXString{$tmp})) {
+   $tmp = $lengthAsLyXString{$tmp};
+   } elsif ($tmp =~ /[0-9.]*/) {
+   $tmp *= 100;
+   }
+   $arg .= $tmp;
+   }

-- 
Angus




reLyX and minipages revisited

2003-02-07 Thread Angus Leeming
I have gone over Georg's minipage patch with a fine toothed comb. I had to 
make a few changes, but it now works perfectly except for one tiny limitation 
(also present without this patch). 

reLyX does not recognise when it has got to the end of a paragraph unless it 
is told explicitly with $IsNewParagraph = 1; There can be multiple minipages 
in one paragraph, so Georg's solution of inserting this test after each 
minipage is incorrect. Equally, my solution of doing nothing is also 
incorrect.

Having said that, reLyX without this patch also merges a paragraph ending with 
a minipage with the next paragraph. Kayvan, I've CCed you in the vain hope 
that you might know the answer!

One final point. the 'height' and 'inner_position' fields are zeroed because 
although insetminipage has them, they appear never, ever to be set. Is this 
simply a limitation of the frontends?

I tested this patch very hard and attach a little test case for you to try out 
too. Jean-Marc, I think that this too could go in the 1.3.x. branch but, of 
course, leave that to your discretion.

Good night,
Angus


Index: lib/reLyX/BasicLyX.pm
===
RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/reLyX/BasicLyX.pm,v
retrieving revision 1.7
diff -u -p -r1.7 BasicLyX.pm
--- lib/reLyX/BasicLyX.pm	7 Feb 2003 22:11:06 -	1.7
+++ lib/reLyX/BasicLyX.pm	8 Feb 2003 02:18:05 -
@@ -218,6 +218,14 @@ my $MathEnvironments = (math|displaymat
 # 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 {
@@ -1011,6 +1019,44 @@ sub basic_lyx {
 		$tok = $fileobject-eatGroup;
 		new RelyxTable::Table $tok;
 
+	# minipage
+	} elsif ($env eq minipage) {
+		CheckForNewParagraph;
+
+	print OUTFILE \\begin_inset Minipage\n;
+
+		# Read any optional argument.
+		$tok = $fileobject-eatOptionalArgument;
+		my $arg = $tok-print if defined($tok-print);
+
+		my %map = ('t' = '0', 'c' = '1', 'b' = '2');
+		if ($debug_on  $arg ne ''  !defined($map{$arg})) {
+		print \nIgnoring unknown positioning arg '$arg'\n;
+		}
+
+		# The minipage is centred by default.
+		$arg = '1' if (!defined($map{$arg}) ||
+			   ($arg = $map{$arg}) eq '');
+
+		print OUTFILE position $arg\n;
+
+		$tok = $fileobject-eatBalanced;
+		$arg = '';
+		foreach (@{$tok}) {
+		my $tmp = $_-print;
+		if (defined($lengthAsLyXString{$tmp})) {
+			$tmp = $lengthAsLyXString{$tmp};
+		} elsif ($tmp =~ /[0-9.]*/) {
+			$tmp *= 100;
+		}
+		$arg .= $tmp;
+		}
+
+		print OUTFILE inner_position 0\n;
+		print OUTFILE height \0pt\\n;
+		print OUTFILE width \$arg\\n;
+		print OUTFILE collapsed false\n;
+
 	# \begin document
 	} elsif ($env eq document) {
 		# do nothing
@@ -1081,6 +1127,13 @@ sub basic_lyx {
 
 		# Anything after a table will be a new paragraph
 		$IsNewParagraph = 1; $MayBeDeeper = 1;
+
+	# minipage
+	} elsif ($env eq minipage) {
+	print OUTFILE \n\\end_inset \n\n;
+
+		# Next stuff will be new env.
+		# $IsNewParagraph = 1;
 
 	} elsif ($env eq document) {
 	print \nDone with document! if $debug_on;

\documentclass{article}
\begin{document}
text above

\begin{minipage}[c]{0.45\columnwidth}%
foo foo foo foo foo foo foo foo foo foo foo foo foo foo
foo foo foo foo foo foo foo foo foo foo foo foo foo
foo foo foo foo foo foo foo foo foo foo foo foo foo
foo foo foo foo foo foo foo foo foo foo foo foo foo
foo foo foo foo foo foo\end{minipage}%
\hfill\begin{minipage}[t]{0.45\columnwidth}%
bar bar bar bar bar bar bar bar bar bar bar bar bar bar
bar bar bar bar bar bar bar bar bar bar bar bar bar bar
bar bar bar bar bar bar bar bar bar bar bar bar bar bar
bar bar bar bar bar bar bar bar bar bar bar bar bar bar
bar bar bar bar bar bar bar bar\end{minipage}%

text below
\end{document}



reLyX and minipages revisited

2003-02-07 Thread Angus Leeming
I have gone over Georg's minipage patch with a fine toothed comb. I had to 
make a few changes, but it now works perfectly except for one tiny limitation 
(also present without this patch). 

reLyX does not recognise when it has got to the end of a paragraph unless it 
is told explicitly with $IsNewParagraph = 1; There can be multiple minipages 
in one paragraph, so Georg's solution of inserting this test after each 
minipage is incorrect. Equally, my solution of doing nothing is also 
incorrect.

Having said that, reLyX without this patch also merges a paragraph ending with 
a minipage with the next paragraph. Kayvan, I've CCed you in the vain hope 
that you might know the answer!

One final point. the 'height' and 'inner_position' fields are zeroed because 
although insetminipage has them, they appear never, ever to be set. Is this 
simply a limitation of the frontends?

I tested this patch very hard and attach a little test case for you to try out 
too. Jean-Marc, I think that this too could go in the 1.3.x. branch but, of 
course, leave that to your discretion.

Good night,
Angus


Index: lib/reLyX/BasicLyX.pm
===
RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/reLyX/BasicLyX.pm,v
retrieving revision 1.7
diff -u -p -r1.7 BasicLyX.pm
--- lib/reLyX/BasicLyX.pm	7 Feb 2003 22:11:06 -	1.7
+++ lib/reLyX/BasicLyX.pm	8 Feb 2003 02:18:05 -
@@ -218,6 +218,14 @@ my $MathEnvironments = "(math|displaymat
 # 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 {
@@ -1011,6 +1019,44 @@ sub basic_lyx {
 		$tok = $fileobject->eatGroup;
 		new RelyxTable::Table $tok;
 
+	# minipage
+	} elsif ($env eq "minipage") {
+		
+
+	print OUTFILE "\\begin_inset Minipage\n";
+
+		# Read any optional argument.
+		$tok = $fileobject->eatOptionalArgument;
+		my $arg = $tok->print if defined($tok->print);
+
+		my %map = ('t' => '0', 'c' => '1', 'b' => '2');
+		if ($debug_on && $arg ne '' && !defined($map{$arg})) {
+		print "\nIgnoring unknown positioning arg '$arg'\n";
+		}
+
+		# The minipage is centred by default.
+		$arg = '1' if (!defined($map{$arg}) ||
+			   ($arg = $map{$arg}) eq '');
+
+		print OUTFILE "position $arg\n";
+
+		$tok = $fileobject->eatBalanced;
+		$arg = '';
+		foreach (@{$tok}) {
+		my $tmp = $_->print;
+		if (defined($lengthAsLyXString{$tmp})) {
+			$tmp = $lengthAsLyXString{$tmp};
+		} elsif ($tmp =~ /[0-9.]*/) {
+			$tmp *= 100;
+		}
+		$arg .= $tmp;
+		}
+
+		print OUTFILE "inner_position 0\n";
+		print OUTFILE "height \"0pt\"\n";
+		print OUTFILE "width \"$arg\"\n";
+		print OUTFILE "collapsed false\n";
+
 	# \begin document
 	} elsif ($env eq "document") {
 		# do nothing
@@ -1081,6 +1127,13 @@ sub basic_lyx {
 
 		# Anything after a table will be a new paragraph
 		$IsNewParagraph = 1; $MayBeDeeper = 1;
+
+	# minipage
+	} elsif ($env eq "minipage") {
+	print OUTFILE "\n\\end_inset \n\n";
+
+		# Next stuff will be new env.
+		# $IsNewParagraph = 1;
 
 	} elsif ($env eq "document") {
 	print "\nDone with document!" if $debug_on;

\documentclass{article}
\begin{document}
text above

\begin{minipage}[c]{0.45\columnwidth}%
foo foo foo foo foo foo foo foo foo foo foo foo foo foo
foo foo foo foo foo foo foo foo foo foo foo foo foo
foo foo foo foo foo foo foo foo foo foo foo foo foo
foo foo foo foo foo foo foo foo foo foo foo foo foo
foo foo foo foo foo foo\end{minipage}%
\hfill\begin{minipage}[t]{0.45\columnwidth}%
bar bar bar bar bar bar bar bar bar bar bar bar bar bar
bar bar bar bar bar bar bar bar bar bar bar bar bar bar
bar bar bar bar bar bar bar bar bar bar bar bar bar bar
bar bar bar bar bar bar bar bar bar bar bar bar bar bar
bar bar bar bar bar bar bar bar\end{minipage}%

text below
\end{document}