From c8c5fc65d087e78436a1e6e08a82f9c46732aaa9 Mon Sep 17 00:00:00 2001 From: Stefan Schimanski Date: Mon, 10 Mar 2008 12:48:46 +0000 Subject: [PATCH] * xargs export support. No parser support yet. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23615 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/LaTeXFeatures.cpp | 1 + src/mathed/MathMacroTemplate.cpp | 43 ++++++++++++++++++++++++-------- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp index 8e0b42e63b..0540c937b3 100644 --- a/src/LaTeXFeatures.cpp +++ b/src/LaTeXFeatures.cpp @@ -549,6 +549,7 @@ char const * simplefeatures[] = { "amsthm", "listings", "bm" + "xargs" }; int const nb_simplefeatures = sizeof(simplefeatures) / sizeof(char const *); diff --git a/src/mathed/MathMacroTemplate.cpp b/src/mathed/MathMacroTemplate.cpp index ff296e80b5..46612210e2 100644 --- a/src/mathed/MathMacroTemplate.cpp +++ b/src/mathed/MathMacroTemplate.cpp @@ -1133,10 +1133,16 @@ void MathMacroTemplate::write(WriteStream & os) const void MathMacroTemplate::write(WriteStream & os, bool overwriteRedefinition) const { + bool xargs = false; // newcommand or renewcommand - if (os.latex() && optionals_ > 1) - os << "\\newlyxcommand"; - else { + if (os.latex() && optionals_ > 1) { + if (redefinition_ && !overwriteRedefinition) + os << "\\renewcommandx"; + else + os << "\\newcommandx"; + xargs = true; + //os << "\\newcommandx"; + } else { if (redefinition_ && !overwriteRedefinition) os << "\\renewcommand"; else @@ -1147,14 +1153,30 @@ void MathMacroTemplate::write(WriteStream & os, bool overwriteRedefinition) cons os << '[' << numargs_ << ']'; // optional values - for (int i = 0; i < optionals_; ++i) { - docstring optValue = asString(cell(optIdx(i))); - if (optValue.find(']') != docstring::npos) - os << "[{" << cell(optIdx(i)) << "}]"; - else - os << "[" << cell(optIdx(i)) << "]"; + if (xargs) { + os << "[usedefault"; + for (int i = 0; i < optionals_; ++i) { + docstring optValue = asString(cell(optIdx(i))); + if (optValue.find(']') != docstring::npos + || optValue.find('=') != docstring::npos) + os << ", " << i + 1 << "=" + << "{" << cell(optIdx(i)) << "}"; + else + os << ", " << i + 1 << "=" + << cell(optIdx(i)); + } + os << "]"; + } else { + for (int i = 0; i < optionals_; ++i) { + docstring optValue = asString(cell(optIdx(i))); + if (optValue.find(']') != docstring::npos) + os << "[{" << cell(optIdx(i)) << "}]"; + else + os << "[" << cell(optIdx(i)) << "]"; + } } + os << "{" << cell(defIdx()) << "}"; if (os.latex()) { @@ -1239,7 +1261,8 @@ bool MathMacroTemplate::fixNameAndCheckIfValid() void MathMacroTemplate::validate(LaTeXFeatures & features) const { if (optionals_ > 1) { - features.require("newlyxcommand"); + //features.require("newlyxcommand"); + features.require("xargs"); } }