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 -0000	1.7
+++ lib/reLyX/BasicLyX.pm	8 Feb 2003 02:18:05 -0000
@@ -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}

Reply via email to