From e23f96ef2e40f0ab5d483a76dec21c4e8423762d Mon Sep 17 00:00:00 2001 From: Stefan Schimanski Date: Thu, 24 May 2007 06:52:08 +0000 Subject: [PATCH] * Import newcommand/providecommand/renewcommand/def macros as MathMacros if they are compatible (i.e. no optional arguments, no patterns) * Recursive macros are also imported, but they only work correctly in the limits of the current macro implementation in LyX * Fixes http://bugzilla.lyx.org/show_bug.cgi?id=21 git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18483 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/tex2lyx/text.cpp | 51 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp index f1a9998ae0..1efb58ba74 100644 --- a/src/tex2lyx/text.cpp +++ b/src/tex2lyx/text.cpp @@ -1424,9 +1424,44 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, context.check_layout(os); eat_whitespace(p, os, context, false); string name = p.get_token().cs(); - while (p.next_token().cat() != catBegin) - name += p.get_token().asString(); - handle_ert(os, "\\def\\" + name + '{' + p.verbatim_item() + '}', context); + eat_whitespace(p, os, context, false); + + // parameter text + bool simple = true; + string paramtext; + int arity = 0; + while (p.next_token().cat() != catBegin) { + if (p.next_token().cat() == catParameter) { + // # found + p.get_token(); + paramtext += "#"; + + // followed by number? + if (p.next_token().cat() == catOther) { + char c = p.getChar(); + paramtext += c; + // number = current arity + 1? + if (c == arity + '0' + 1) + ++arity; + else + simple = false; + } else + paramtext += p.get_token().asString(); + } else { + paramtext += p.get_token().asString(); + simple = false; + } + } + + // only output simple (i.e. compatible) macro as FormulaMacros + string ert = "\\def\\" + name + ' ' + paramtext + '{' + p.verbatim_item() + '}'; + if (simple) { + context.check_layout(os); + begin_inset(os, "FormulaMacro"); + os << "\n" << ert; + end_inset(os); + } else + handle_ert(os, ert, context); } else if (t.cs() == "noindent") { @@ -2269,7 +2304,15 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, string const ert = name + '{' + command + '}' + opt1 + opt2 + '{' + p.verbatim_item() + '}'; - handle_ert(os, ert, context); + + if (opt2.empty()) { + context.check_layout(os); + begin_inset(os, "FormulaMacro"); + os << "\n" << ert; + end_inset(os); + } else + // we cannot handle optional argument, so only output ERT + handle_ert(os, ert, context); } else if (t.cs() == "vspace") { -- 2.39.5