Math macros crash LyX currently. This happens in metrics(). The following patch compiles, and it is the best I came up with (I could not run it, because of qt3 moc breakage).
I'd be interested to know how I could have made it shorter, and whether it is right. I have to say I do not like it much :) A few things I would propose to make vectors easier: - define types utf8vector, ucs2vector and ucs4vector (less typing). - use convert<ucs4vector>(utf8vector) specializations instead of utf8_to_ucs4 and friends. Of course, having _() return a ucs4vector would have helped a lot here. We could maybe define a _ucs4() gettext helper and change it back to _() when all the uses of gettext have been fixed to use the right return value. Also, there is bformat. What can we do with it. My point is that we need some syntaxic sugar to help the transition. JMarc
Index: src/mathed/math_macrotemplate.C =================================================================== --- src/mathed/math_macrotemplate.C (revision 14714) +++ src/mathed/math_macrotemplate.C (working copy) @@ -20,6 +20,7 @@ #include "gettext.h" #include "lyxlex.h" #include "LColor.h" +#include "support/unicode.h" #include "frontends/Painter.h" #include "frontends/font_metrics.h" @@ -33,7 +34,7 @@ using std::string; using std::auto_ptr; using std::ostream; using std::endl; - +using std::vector; MathMacroTemplate::MathMacroTemplate() : MathNestInset(2), numargs_(0), name_(), type_("newcommand") @@ -112,7 +113,12 @@ void MathMacroTemplate::metrics(MetricsI { cell(0).metrics(mi); cell(1).metrics(mi); - docstring dp(prefix().begin(), prefix().end()); + string pref = prefix(); + vector<char> utf8pref(pref.begin(), pref.end()); + vector<uint32_t> ucs4pref = + utf8_to_ucs4(vector<char>(utf8pref.begin(), + utf8pref.end())); + docstring dp(ucs4pref.begin(), ucs4pref.end()); dim.wid = cell(0).width() + cell(1).width() + 20 + font_metrics::width(dp, mi.base.font); dim.asc = std::max(cell(0).ascent(), cell(1).ascent()) + 7;