From 3f5e1c0e27468b72a9098e1ff451fc445398bb5f Mon Sep 17 00:00:00 2001 From: Stefan Schimanski Date: Sun, 23 Dec 2007 16:33:01 +0000 Subject: [PATCH] * tex2lyx support for multiple optional argument using \newlyxcommand git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22282 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/tex2lyx/tex2lyx.cpp | 5 ++--- src/tex2lyx/tex2lyx.h | 6 +++--- src/tex2lyx/text.cpp | 17 ++++++++++++----- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/tex2lyx/tex2lyx.cpp b/src/tex2lyx/tex2lyx.cpp index 790cf4a3a7..c107cea8c0 100644 --- a/src/tex2lyx/tex2lyx.cpp +++ b/src/tex2lyx/tex2lyx.cpp @@ -111,7 +111,7 @@ CommandMap known_math_environments; void add_known_command(string const & command, string const & o1, - bool o2) + unsigned optionalsNum) { // We have to handle the following cases: // definition o1 o2 invocation result @@ -127,8 +127,7 @@ void add_known_command(string const & command, string const & o1, if (isStrUnsignedInt(opt1)) { // The command has arguments nargs = convert(opt1); - if (nargs > 0 && o2) { - // The first argument is optional + for (unsigned int i = 0; i < optionalsNum; ++i) { arguments.push_back(optional); --nargs; } diff --git a/src/tex2lyx/tex2lyx.h b/src/tex2lyx/tex2lyx.h index 913060977c..c3ffe97d50 100644 --- a/src/tex2lyx/tex2lyx.h +++ b/src/tex2lyx/tex2lyx.h @@ -75,11 +75,11 @@ char const * const * is_known(std::string const &, char const * const *); /*! * Adds the command \p command to the list of known commands. * \param o1 first optional parameter to the latex command \newcommand - * (with brackets), or the empty string if there were no optional arguments. - * \param o2 wether \newcommand had a second optional parameter + * (with brackets), or the empty string if there were no optional argument. + * \param optionalsNum is the number of optional parameters */ void add_known_command(std::string const & command, std::string const & o1, - bool o2); + unsigned optionalsNum); // Access to environment stack extern std::vector active_environments; diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp index 8cadc5f841..390e445179 100644 --- a/src/tex2lyx/text.cpp +++ b/src/tex2lyx/text.cpp @@ -2393,11 +2393,18 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, } string const command = p.verbatim_item(); string const opt1 = p.getOpt(); - string const opt2 = p.getFullOpt(); - add_known_command(command, opt1, !opt2.empty()); - string const ert = name + '{' + command + '}' + - opt1 + opt2 + - '{' + p.verbatim_item() + '}'; + string optionals; + unsigned optionalsNum = 0; + while (true) { + string const opt = p.getFullOpt(); + if (opt.empty()) + break; + optionalsNum++; + optionals += opt; + } + add_known_command(command, opt1, optionalsNum); + string const ert = name + '{' + command + '}' + opt1 + + optionals + '{' + p.verbatim_item() + '}'; context.check_layout(os); begin_inset(os, "FormulaMacro"); -- 2.39.2