]> git.lyx.org Git - features.git/commitdiff
* tex2lyx support for multiple optional argument using \newlyxcommand
authorStefan Schimanski <sts@lyx.org>
Sun, 23 Dec 2007 16:33:01 +0000 (16:33 +0000)
committerStefan Schimanski <sts@lyx.org>
Sun, 23 Dec 2007 16:33:01 +0000 (16:33 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22282 a592a061-630c-0410-9148-cb99ea01b6c8

src/tex2lyx/tex2lyx.cpp
src/tex2lyx/tex2lyx.h
src/tex2lyx/text.cpp

index 790cf4a3a71ac19336eb46fab879a22a8adb42ba..c107cea8c070f85d2e7da3a9b723d5a04afa79ce 100644 (file)
@@ -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<unsigned int>(opt1);
-               if (nargs > 0 && o2) {
-                       // The first argument is optional
+               for (unsigned int i = 0; i < optionalsNum; ++i) {
                        arguments.push_back(optional);
                        --nargs;
                }
index 913060977c578e73d0f05112538921b889352fbe..c3ffe97d5064940a9c3ed4af1e95be5b32fa62d6 100644 (file)
@@ -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<std::string> active_environments;
index 8cadc5f8418fa3af18b4dd779a7057f0e2dc12e9..390e445179e70fcc7b3fe94d6ad9bb9e92f5dd19 100644 (file)
@@ -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");