* 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
This commit is contained in:
Stefan Schimanski 2007-12-23 16:33:01 +00:00
parent f85fccef65
commit 3f5e1c0e27
3 changed files with 17 additions and 11 deletions

View File

@ -111,7 +111,7 @@ CommandMap known_math_environments;
void add_known_command(string const & command, string const & o1, void add_known_command(string const & command, string const & o1,
bool o2) unsigned optionalsNum)
{ {
// We have to handle the following cases: // We have to handle the following cases:
// definition o1 o2 invocation result // definition o1 o2 invocation result
@ -127,8 +127,7 @@ void add_known_command(string const & command, string const & o1,
if (isStrUnsignedInt(opt1)) { if (isStrUnsignedInt(opt1)) {
// The command has arguments // The command has arguments
nargs = convert<unsigned int>(opt1); nargs = convert<unsigned int>(opt1);
if (nargs > 0 && o2) { for (unsigned int i = 0; i < optionalsNum; ++i) {
// The first argument is optional
arguments.push_back(optional); arguments.push_back(optional);
--nargs; --nargs;
} }

View 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. * Adds the command \p command to the list of known commands.
* \param o1 first optional parameter to the latex command \newcommand * \param o1 first optional parameter to the latex command \newcommand
* (with brackets), or the empty string if there were no optional arguments. * (with brackets), or the empty string if there were no optional argument.
* \param o2 wether \newcommand had a second optional parameter * \param optionalsNum is the number of optional parameters
*/ */
void add_known_command(std::string const & command, std::string const & o1, void add_known_command(std::string const & command, std::string const & o1,
bool o2); unsigned optionalsNum);
// Access to environment stack // Access to environment stack
extern std::vector<std::string> active_environments; extern std::vector<std::string> active_environments;

View File

@ -2393,11 +2393,18 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
} }
string const command = p.verbatim_item(); string const command = p.verbatim_item();
string const opt1 = p.getOpt(); string const opt1 = p.getOpt();
string const opt2 = p.getFullOpt(); string optionals;
add_known_command(command, opt1, !opt2.empty()); unsigned optionalsNum = 0;
string const ert = name + '{' + command + '}' + while (true) {
opt1 + opt2 + string const opt = p.getFullOpt();
'{' + p.verbatim_item() + '}'; 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); context.check_layout(os);
begin_inset(os, "FormulaMacro"); begin_inset(os, "FormulaMacro");