On Fri, Dec 19, 2008 at 12:32:57PM -0500, Richard heck wrote: > Jean-Marc Lasgouttes wrote: > > Richard heck <rgh...@bobjweil.com> writes: > > > >> I could be wrong, but what you report certainly seems like a bug. I > >> think maybe around this part of the function: > >> // The last added char caused a mismatch, because > >> // we didn't exhaust the chars in cmd and didn't > >> // exceed the maximum size of the current unicmd > >> if (k < cmdend && cur_size > tmp.size()) > >> tmp.resize(tmp.size() - 1); > >> we ought to check whether that last added char was alpha and, if so, > >> figure it's a command of some other sort. > >> > > > > Yes, I think it is a bug. But actually I do not understand why this > > macro is written as it is here. The code should read a token and look > > whether it is part of a unicode symbol, or something like that. > > > > > The logic of the thing suggests that the author didn't think about the > case where it was a longer command, just about the case of, say: \O23, > rather than: \OtherCmd. Anyway, it does seem to me that this thing could > be simplified, but I guess Enrico will know.
AFAIR, I wrote fromLaTeXCommand() having in mind the following use case. When exporting to LaTeX a math formula containing a unicode symbol outside of text mode, the symbol is enclosed in the \lyxmathsym macro. If the symbol cannot be represented in the current encoding, it is translated to a LaTeX macro if possible. When importing back from LaTeX and the math parser sees \lyxmathsym, it tries to translate the enclosed macro (if any) back to unicode. So, in my mind, fromLaTeXCommand() was acting on something that LyX wrote and thus there was no need for checking whether the argument of \lyxmathsym was a valid macro or not (it actually had to be either a LaTeX macro representing a unicode symbol, or a unicode symbol, or a sequence of both kinds). For this goal, no error checking was needed. Now I see that I failed to document that :( and you are using the method with another goal in mind. It should be possible to modify fromLaTeXCommand() such that to satisfy your need, or you can simply check whether the remaining untranslated string begins with a letter, meaning that the method failed the translation. I'll try to "fix" fromLaTeXCommand() in order to make it usable for what you have in mind. -- Enrico