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();
|
os << "\\" << name();
|
||||||
bool first = true;
|
bool first = true;
|
||||||
|
|
||||||
|
// Optional arguments:
|
||||||
|
// First find last non-empty optional argument
|
||||||
|
idx_type emptyOptFrom = 0;
|
||||||
idx_type i = 0;
|
idx_type i = 0;
|
||||||
|
for (; i < cells_.size() && i < optionals_; ++i) {
|
||||||
// Use macroBackup_ instead of macro_ here, because
|
if (!cell(i).empty())
|
||||||
// this is outside the metrics/draw calls, hence the macro_
|
emptyOptFrom = i + 1;
|
||||||
// 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) {
|
|
||||||
first = false;
|
|
||||||
os << "[" << cell(i) << "]";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
// Print remaining macros
|
||||||
// (also the further optional parameters in LaTeX mode!)
|
|
||||||
for (; i < cells_.size(); ++i) {
|
for (; i < cells_.size(); ++i) {
|
||||||
if (cell(i).empty() && i < optionals_)
|
if (cell(i).size() == 1
|
||||||
os << "{" << defaults[i] << "}";
|
|
||||||
else if (cell(i).size() == 1
|
|
||||||
&& cell(i)[0].nucleus()->asCharInset()) {
|
&& cell(i)[0].nucleus()->asCharInset()) {
|
||||||
if (first)
|
if (first)
|
||||||
os << " ";
|
os << " ";
|
||||||
|
@ -970,40 +970,26 @@ void MathMacroTemplate::write(WriteStream & os) const
|
|||||||
|
|
||||||
void MathMacroTemplate::write(WriteStream & os, bool overwriteRedefinition) const
|
void MathMacroTemplate::write(WriteStream & os, bool overwriteRedefinition) const
|
||||||
{
|
{
|
||||||
if (type_ == MacroTypeDef) {
|
// newcommand or renewcommand
|
||||||
os << "\\def\\" << name().c_str();
|
if (os.latex() && optionals_ > 1)
|
||||||
for (int i = 1; i <= numargs_; ++i)
|
os << "\\newlyxcommand";
|
||||||
os << '#' << i;
|
else {
|
||||||
} else {
|
if (redefinition_)
|
||||||
// newcommand or renewcommand
|
|
||||||
if (redefinition_ && !overwriteRedefinition)
|
|
||||||
os << "\\renewcommand";
|
os << "\\renewcommand";
|
||||||
else
|
else
|
||||||
os << "\\newcommand";
|
os << "\\newcommand";
|
||||||
os << "{\\" << name().c_str() << '}';
|
}
|
||||||
if (numargs_ > 0)
|
os << "{\\" << name().c_str() << '}';
|
||||||
os << '[' << numargs_ << ']';
|
if (numargs_ > 0)
|
||||||
|
os << '[' << numargs_ << ']';
|
||||||
|
|
||||||
// optional values
|
// optional values
|
||||||
if (os.latex()) {
|
for (int i = 0; i < optionals_; ++i) {
|
||||||
// in latex only one optional possible, simulate the others
|
docstring optValue = asString(cell(optIdx(i)));
|
||||||
if (optionals_ >= 1) {
|
if (optValue.find(']') != docstring::npos)
|
||||||
docstring optValue = asString(cell(optIdx(0)));
|
os << "[{" << cell(optIdx(i)) << "}]";
|
||||||
if (optValue.find(']') != docstring::npos)
|
else
|
||||||
os << "[{" << cell(optIdx(0)) << "}]";
|
os << "[" << cell(optIdx(i)) << "]";
|
||||||
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)
|
|
||||||
os << "[{" << cell(optIdx(i)) << "}]";
|
|
||||||
else
|
|
||||||
os << "[" << cell(optIdx(i)) << "]";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
os << "{" << cell(defIdx()) << "}";
|
os << "{" << cell(defIdx()) << "}";
|
||||||
@ -1016,7 +1002,6 @@ void MathMacroTemplate::write(WriteStream & os, bool overwriteRedefinition) cons
|
|||||||
if (!cell(displayIdx()).empty())
|
if (!cell(displayIdx()).empty())
|
||||||
os << "\n{" << cell(displayIdx()) << '}';
|
os << "\n{" << cell(displayIdx()) << '}';
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int MathMacroTemplate::plaintext(Buffer const & buf, odocstream & os,
|
int MathMacroTemplate::plaintext(Buffer const & buf, odocstream & os,
|
||||||
|
Loading…
Reference in New Issue
Block a user