mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-08 10:51:03 +00:00
* \newlyxcommand support
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22280 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
32c8479e5a
commit
ec996ed828
@ -552,39 +552,28 @@ void MathMacro::write(WriteStream & os) const
|
||||
|
||||
os << "\\" << name();
|
||||
bool first = true;
|
||||
|
||||
// Optional arguments:
|
||||
// First find last non-empty optional argument
|
||||
idx_type emptyOptFrom = 0;
|
||||
idx_type i = 0;
|
||||
|
||||
// Use macroBackup_ instead of macro_ here, because
|
||||
// this is outside the metrics/draw calls, hence the macro_
|
||||
// variable can point to a MacroData which was freed already.
|
||||
vector<docstring> const & defaults = macroBackup_.defaults();
|
||||
|
||||
// Optional argument
|
||||
if (os.latex()) {
|
||||
// Print first optional in LaTeX semantics
|
||||
if (i < optionals_) {
|
||||
// the first real optional, the others are non-optional in latex
|
||||
if (!cell(i).empty()) {
|
||||
first = false;
|
||||
os << "[" << cell(0) << "]";
|
||||
}
|
||||
|
||||
++i;
|
||||
}
|
||||
} else {
|
||||
// In lyx mode print all in any case
|
||||
for (; i < cells_.size() && i < optionals_; ++i) {
|
||||
if (!cell(i).empty())
|
||||
emptyOptFrom = i + 1;
|
||||
}
|
||||
|
||||
// print out optionals
|
||||
for (i=0; i < cells_.size() && i < emptyOptFrom; ++i) {
|
||||
first = false;
|
||||
os << "[" << cell(i) << "]";
|
||||
}
|
||||
}
|
||||
|
||||
// skip the tailing empty optionals
|
||||
i = optionals_;
|
||||
|
||||
// Print remaining macros
|
||||
// (also the further optional parameters in LaTeX mode!)
|
||||
for (; i < cells_.size(); ++i) {
|
||||
if (cell(i).empty() && i < optionals_)
|
||||
os << "{" << defaults[i] << "}";
|
||||
else if (cell(i).size() == 1
|
||||
if (cell(i).size() == 1
|
||||
&& cell(i)[0].nucleus()->asCharInset()) {
|
||||
if (first)
|
||||
os << " ";
|
||||
|
@ -970,32 +970,20 @@ void MathMacroTemplate::write(WriteStream & os) const
|
||||
|
||||
void MathMacroTemplate::write(WriteStream & os, bool overwriteRedefinition) const
|
||||
{
|
||||
if (type_ == MacroTypeDef) {
|
||||
os << "\\def\\" << name().c_str();
|
||||
for (int i = 1; i <= numargs_; ++i)
|
||||
os << '#' << i;
|
||||
} else {
|
||||
// newcommand or renewcommand
|
||||
if (redefinition_ && !overwriteRedefinition)
|
||||
if (os.latex() && optionals_ > 1)
|
||||
os << "\\newlyxcommand";
|
||||
else {
|
||||
if (redefinition_)
|
||||
os << "\\renewcommand";
|
||||
else
|
||||
os << "\\newcommand";
|
||||
}
|
||||
os << "{\\" << name().c_str() << '}';
|
||||
if (numargs_ > 0)
|
||||
os << '[' << numargs_ << ']';
|
||||
|
||||
// optional values
|
||||
if (os.latex()) {
|
||||
// in latex only one optional possible, simulate the others
|
||||
if (optionals_ >= 1) {
|
||||
docstring optValue = asString(cell(optIdx(0)));
|
||||
if (optValue.find(']') != docstring::npos)
|
||||
os << "[{" << cell(optIdx(0)) << "}]";
|
||||
else
|
||||
os << "[" << cell(optIdx(0)) << "]";
|
||||
}
|
||||
} else {
|
||||
// in lyx we handle all optionals as real optionals
|
||||
for (int i = 0; i < optionals_; ++i) {
|
||||
docstring optValue = asString(cell(optIdx(i)));
|
||||
if (optValue.find(']') != docstring::npos)
|
||||
@ -1003,8 +991,6 @@ void MathMacroTemplate::write(WriteStream & os, bool overwriteRedefinition) cons
|
||||
else
|
||||
os << "[" << cell(optIdx(i)) << "]";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
os << "{" << cell(defIdx()) << "}";
|
||||
|
||||
@ -1016,7 +1002,6 @@ void MathMacroTemplate::write(WriteStream & os, bool overwriteRedefinition) cons
|
||||
if (!cell(displayIdx()).empty())
|
||||
os << "\n{" << cell(displayIdx()) << '}';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int MathMacroTemplate::plaintext(Buffer const & buf, odocstream & os,
|
||||
|
Loading…
Reference in New Issue
Block a user