Hi again Georg, everyone,
Thank you for your answers, I'd missed this one. Since my requests did
not recruit any GSOC love, I'm looking into it myself. I hope you can
help me get started.
- Math-macros, if turned into \global\long\def, should be turned back so
LyX's beautiful visual editing is restored (can keep the math-macro def
in a comment in the latex version and restore it).
BTW, when does a math-macro become a \newcommand vs \global\long\def?
In old versions, all math formulas in LyX were stored in LaTeX syntax, so
that the LyX and LaTeX formats were 100% identical. This changed some time
ago for math macros, and some pseudo-LaTeX syntax was invented for LyX (see
MathMacroTemplate::write() for details). This was a mistake IMHO, and the
best fix for this problem would be to get rid of the pseudo-syntax and
restore the 100% LaTeX compatibility. There are also comments in tex2lyx
about situations were the conversion to the LyX pseudo-syntax does not work.
I'm trying to understand why some latex files (all of which began as
exports from lyx with similar macros), when converted back to lyx have
math-macros, and some do not.
With a look at tex2lyx I didn't find where this conversion happens.
text.cpp and Preamble.cpp seem to use add_known_command and do relevant
things, but I might be missing some of the context. Pointers to design
documents or hints?
I find it somewhat surprising that math-macros are recovered at all from
the currently output latex. It seems just defining a \math-macro command
and using it would make later identification easier, without being
offensive to latex users at all. While we're at it, if we're using
newcommandx for optional-argument cases, why not use it always for
simplicity?
In short, I would imagine a solution like the following would be
reasonably simple, but really don't know the code well enough. What do
you think?
1. Never use \global\long\def, replacing that with just the \newcommandx
currently used with optional arguments.
2. In MathMacroTemplate::write() convert every math-macro to a call to a
latex command called math-macro that acts like newcommandx, except for
carry the bit of information: "this is only used in math, and should be
converted to a math-macro". Add an approriate definition of math-macro
in every exported latex file.
3. Change tex2lyx to recognize math-macro and convert it accordingly
(now should be trivial)
- Automatically generate styles for environments defined in imported
documents. For example if the imported latex has a keywords environment,
that should not suddenly become ERT in LyX.
This should allow me to start from the conference sample file, import it
into LyX, and obtain a first class lyx environment.
Both your suggestions look useful, although I'm wondering how
achievable is the 2nd one. I'd love to hear what established devels
think of this.
I think the second one is doable as well. Ideally, a local layout (or
module) would be generated for all unknown commands and environments. The
needed infrastructure is all in place: you can define new known commands in
tex2lyx during runtime, and since very recently layouts can be written in
.layout file syntax. Of course such an automatically generated local layout
might not be the optimal and most flexible way to use these commands, but at
least better than ERT.
Glad to know its there, more specifics would be welcome. From a quick
peek I would guess I need to call add_known_environment? That seems to
be called only from Preamble.cpp, so I guess I would need to add a call
to text.cpp, maybe in parse_unknown_environment? does that sound right?
Pointers on how to create the layout file?
Thanks for your time,
Daniel Vainsencher