Uwe Stöhr wrote: > Since more about 10 years it has been a dream for me to have a TeX code > inset for math. > http://www.lyx.org/trac/ticket/2579
This is indeed an important feature and would remove the burden from the math TeX parser to understand 100% of all possible LaTeX formulas. I have been wanting this for a long time as well. > For LyX 2.2 I want implemented such a beast. Its features are simply > these: - it is added to a formula by typing \TeX in math > - its content is not parsed by LyX, so everything is allowed like in the > TeX code inset (ERT) > - its content is output to LaTeX as it is > - its content appears in red like normal TeX code > > This sound simple but every year when I experiment with this but fail. > Attached is a patch idea. Unfortunately I am not able to disable the > parsing of the inset content and when re-opening a file with the new > inset the color of the inset is lost. > Does anybody have an idea how to achieve what I want? I assume that > InsetNest is the wrong type but what kind of inset can/must I use? > How to I manage that LyX recognize the TeX code inset without writing > anything to the LaTeX output that I don't want? The main problem is that currently the native format of math formulas in LyX is LaTeX. Therefore, a true math ERT inset cannot be implemented by definition: Currently LyX needs to parse everything, you cannot introduce any command that starts a special ERT inset, since it could as well be a builtin or user defined macro (and \TeX is indeed a builtin one). Therefore, before thinking about inset implementation, the first question to answer is: How should the native LyX math format be changed to allow for a true ERT inset? In the long term, it does probably make sense to change to MathML or some special LyX math XML format. However, this needs very good preparation, and is IMO not doable for 2.2.0, so we should stick to something very similar to the current format. Changing cat codes as Jean-Marc suggested would only solve a part of the problem: This could be used to parse the contents of the ERT inset itself, but it would not solve the problem of recognizing the start of an ERT inset. One option which is probably easy to implement would be to mark the start and end of the ERT inset with two unicode symbols from the private use area (similar to META_INSET): We could define char_type const MATH_ERT_BEG = 0x200002; char_type const MATH_ERT_END = 0x200003; These symbols can not be part of any LaTeX formula by definition. THey would then be used to swithc the parser from parsing mode to ERT mode (where it would simply read any character until MATH_ERT_END is found) and back. There might be other possibilities, and maybe this solution has drawbacks I did not think of yet. In any case this needs some more thinking. Once the file format question is answered it will be much easier to think about the correct inset. Maybe we can even use the standard text mode ERT inset? Georg