Re: \over vs \frac, and large tables

2001-11-13 Thread Lee Killough

>> Well, you can write recursive descent parsers, LR(1) parsers (yacc, bison,
>> etc.).
>
>You can't. You can't parse TeX cleanly without context. There might
>be macro, active characters, "unusual" catcodes and thing like that.

Oh, so it's context-sensitive. That's nice :(

>Ideally, you would have to run through everything TeX would have seen
>until it comes to the expression itself. Of course one could made
>"normalizing assumptions" (like "no catcode changes"), but even than the
>scope of \over is not exactly trivial.

Ugly.

>Short of re-implementing TeX itself I see no clean solution.

That's too bad.

>> perl -e 'while(<>){s/(\d+)\s*\\over\s+(\d+)/\\frac{$1}{$2}/g;print;}'
>
>This one fails already on '1\over2' or '1 + 2\over 3'.

Well, as I said, my document's use of it was trivial, mostly limited to simple
fractions, so it fit simple pattern matching. Something like 1 + 2\over 3 never
appeared. 1 + {2 \over 3} and \frac{1+2}{3} might have appeared, but not 1 +
2\over 3.

Writing a general script to convert \over to \frac under all cases sounds tough
-- it sounds like you must almost parse the whole document in order to infer
the context of \over.

All I had to do was convert some simple fractions.

Lee




Re: \over vs \frac, and large tables

2001-11-13 Thread Lee Killough

>> Is there a way to make LyX display \over the same way \frac is displayed?
>
>No way unless you want to use 1.2.0cvs. It's working there.

I may give it a try.

>There is another point: parsing  \over is _much_ harder than parsing \frac.

I think I see what you mean, since \frac always has its arguments enclosed in
braces after the \frac, so you can do trivial counting of {'s and }' to find
where \frac's arguments begin and end. And \frac is prefix, while \over is
infix.

>How do you recognize the begin of the numerator and the end of the
>denominator?

Well, you can write recursive descent parsers, LR(1) parsers (yacc, bison,
etc.). It's not _that_ hard to parse.

It's true that simple regexp matching like Perl's s/abc/xyz/ would not be
sufficient.

But I did not have anything that complicated. \over was used for numerical
fractions like 1/2 or 3/4, so they were trivial to parse. I did not have
\over with complicated expressions in them -- that was always \frac.

perl -e 'while(<>){s/(\d+)\s*\\over\s+(\d+)/\\frac{$1}{$2}/g;print;}'

Lee



\over vs \frac, and large tables

2001-11-12 Thread Lee Killough

Is there a way to make LyX display \over the same way \frac is displayed?

\over displays as red source text, making formulas somewhat unreadable:

1 over 2

instead of:

1
-
2

I can see the point of displaying it differently to let you know it's \over
instead of \frac, but since LyX is not supposed to be 100% WYSIWYG, I think it
should be allowed to display \over and \frac the same, just so they are both
readable.

To fix it, I wrote a Perl script to change all of my \over's to \frac's.

Also, how do I handle large tables with LyX?

I have a large full-page table with many math forumlas in it, and if the zoom
is set to anything larger than about 80%, the table is too wide to fit in the
window. LyX doesn't handle it well if I try to resize the window so that the
table fits entirely inside it. And when the number of rows is large, LyX
sometimes jumps back to the beginning of the document when I try to move the
cursor up and down the table. This is true even if I put a page break before
the table.

Trying to change things like justification and alignment inside table cells
does not usually show the changes immediately, and sometimes it crashes LyX
(the emergency file works, though). I'm not expecting 100% WYSIWYG or anything
close (in fact, I prefer LyX's structural orientation to WYSIWYG editors which
remember every space you type), but if LyX can display things like indentation
and alignment in table cells correctly at all, it should display them as soon
as changes are made, which it doesn't seem to do.

I gave up editing the tables under LyX, and hand-edited the source code
directly, with much better results.

(I am using 1.1.6fix3 on RH 7.0 Linux.)

Thanks,

Lee