The bug:
It turns out that reLyX thinks \)* is a starred version of the \) command, 
rather than realizing that it's supposed to be \) followed by an asterisk 
in plain text. (In case you're wondering, the $'s in the .tex file get 
turned into \)'s. So it doesn't finish the math environment, and gets all 
confused.

John nailed down the part of reLyX doing the matching: reLyX/Text/TeX.pm:104

$macro = '\\\\(?:[^a-zA-Z]\*?|([a-zA-Z]+\*?)\s*)';

I dunno about you, but I have to try and turn it into English to try and 
make sense of such junk. I do so below so that you can follow the logic and 
confirm that I've got it right. I'm not used to Perlish REs and would value 
someone else checking it over. Here goes:

\\\\(?:RE)

Noting that '\\' matches a single '\', this matches either '\\' or '\RE' 
where
RE = [^a-zA-Z]\*?|([a-zA-Z]+\*?)\s*

In turn, RE can be split into either
        RE1 = [^a-zA-Z]\*?
or
        RE2 = [a-zA-Z]+\*?
and either can be followed by an arbitrary amount of whitespace '\s*'

RE1 is 'a single non-alphabetic char followed by zero or 1 asterisks'
RE2 is 'one or more alphabetic chars followed by zero or 1 asterisks'

Clearly, therefore, we need to specialise RE1 so that it matches ')' but 
does not match ')*'

This RE does the trick:

\)|([^a-zA-Z)]\*?)

in which case we need
$macro = '\\\\(?:\)|([^a-zA-Z)]\*?)|([a-zA-Z]+\*?)\s*)';

Making the change to reLyX/Text/TeX.pm, I go from a TeX document

\documentclass{article}
\begin{document}
$4x+2$*, la la
\end{document}

to a LyX document

#LyX 1.2 created this file. For more info see http://www.lyx.org/
\lyxformat 2.15
\textclass article

\layout Standard


\begin_inset Formula \( 4x+2\)
\end_inset

*, la la
\the_end


Aren't I clever! Lars, may I apply this fix please?
Angus


Incidentally, the unmodified reLyX gives

#LyX 1.2 created this file. For more info see http://www.lyx.org/
\lyxformat 2.15
\textclass article

\layout Standard


\begin_inset Formula \( 4x+2
\latex latex

\backslash )*
\latex default
, la la
\the_end


Reply via email to