}
-void Buffer::updateEnvironmentMacros(DocIterator & it, pit_type lastpit,
- DocIterator & scope) const
+void Buffer::updateMacros(DocIterator & it, DocIterator & scope) const
{
- Paragraph & par = it.paragraph();
- depth_type depth = par.params().depth();
- Length const & leftIndent = par.params().leftIndent();
+ pit_type lastpit = it.lastpit();
// look for macros in each paragraph
while (it.pit() <= lastpit) {
Paragraph & par = it.paragraph();
- // increased depth?
- if ((par.params().depth() > depth
- || par.params().leftIndent() != leftIndent)
- && par.layout().isEnvironment()) {
- updateBlockMacros(it, scope);
- continue;
- }
-
// iterate over the insets of the current paragraph
InsetList const & insets = par.insetList();
InsetList::const_iterator iit = insets.begin();
// collect macros in inset
it.push_back(CursorSlice(*iit->inset));
- updateInsetMacros(it, newScope ? insetScope : scope);
+ updateMacros(it, newScope ? insetScope : scope);
it.pop_back();
continue;
}
}
-void Buffer::updateBlockMacros(DocIterator & it, DocIterator & scope) const
-{
- Paragraph & par = it.paragraph();
-
- // set scope for macros in this paragraph:
- // * either the "old" outer scope
- // * or the scope ending after the environment
- if (par.layout().isEnvironment()) {
- // find end of environment block,
- DocIterator envEnd = it;
- pit_type n = it.lastpit() + 1;
- depth_type depth = par.params().depth();
- Length const & length = par.params().leftIndent();
- // looping through the paragraph, basically until
- // the layout changes or the depth gets smaller.
- // (the logic of output_latex.cpp's TeXEnvironment)
- do {
- envEnd.pit()++;
- if (envEnd.pit() == n)
- break;
- } while (par.layout() == envEnd.paragraph().layout()
- || depth < envEnd.paragraph().params().depth()
- || length != envEnd.paragraph().params().leftIndent());
-
- // collect macros from environment block
- updateEnvironmentMacros(it, envEnd.pit() - 1, envEnd);
- } else {
- // collect macros from paragraph
- updateEnvironmentMacros(it, it.pit(), scope);
- }
-}
-
-
-void Buffer::updateInsetMacros(DocIterator & it, DocIterator & scope) const
-{
- // look for macros in each paragraph
- pit_type n = it.lastpit() + 1;
- while (it.pit() < n)
- updateBlockMacros(it, scope);
-}
-
-
void Buffer::updateMacros() const
{
if (d->macro_lock)
DocIterator it = par_iterator_begin();
DocIterator outerScope = it;
outerScope.pit() = outerScope.lastpit() + 2;
- updateInsetMacros(it, outerScope);
+ updateMacros(it, outerScope);
}
/// search for macro in local (buffer) table or in children
MacroData const * getBufferMacro(docstring const & name,
DocIterator const & pos) const;
- /** Update macro table in the whole text inset
- \param it at the start of the text inset)
- */
- void updateInsetMacros(DocIterator & it,
- DocIterator & scope) const;
- /** Update macro table for paragraphs until \c lastpit
+ /** Update macro table starting with position of it
\param it in some text inset
- \param lastpit last processed paragraph
*/
- void updateEnvironmentMacros(DocIterator & it,
- pit_type lastpit,
+ void updateMacros(DocIterator & it,
DocIterator & scope) const;
- /** Update macro table for one paragraph block with
- same layout and depth, until \c lastpit
- \param it in some text inset
- \param lastpit last processed paragraph
- */
- void updateBlockMacros(DocIterator & it,
- DocIterator & scope) const;
///
bool readFileHelper(support::FileName const & s);
"ifthen",
"amsthm",
"listings",
- "bm"
+ "bm",
"xargs"
};
}
-bool InsetBox::isMacroScope() const
-{
- BoxType btype = boxtranslator().find(params_.type);
- return btype != Frameless || params_.inner_box;
-}
-
-
int InsetBox::latex(odocstream & os, OutputParams const & runparams) const
{
BoxType btype = boxtranslator().find(params_.type);
///
bool noFontChange() const { return true; }
///
- bool isMacroScope() const;
- ///
int latex(odocstream &, OutputParams const &) const;
///
int plaintext(odocstream &, OutputParams const &) const;
}
-bool InsetCollapsable::isMacroScope() const
-{
- // layout_ == 0 leads to no latex output, so ignore
- // the macros outside
- if (!layout_)
- return true;
-
- // see InsetCollapsable::latex(...) below. In these case
- // an environment is opened there
- if (!layout_->latexname().empty())
- return true;
-
- return false;
-}
-
-
int InsetCollapsable::latex(odocstream & os,
OutputParams const & runparams) const
{
/// can we go further down on mouse click?
bool descendable() const;
///
- bool isMacroScope() const;
- ///
void setLabel(docstring const & l);
///
virtual void setButtonLabel() {}
///
InsetCode lyxCode() const { return FLOAT_CODE; }
///
- bool isMacroScope() const { return true; }
- ///
int latex(odocstream &, OutputParams const &) const;
///
int plaintext(odocstream &, OutputParams const &) const;
///
void write(std::ostream & os) const;
///
- bool isMacroScope() const { return true; }
- ///
bool insetAllowed(InsetCode) const;
/** returns true if, when outputing LaTeX, font changes should
be closed before generating this inset. This is needed for
///
docstring editMessage() const;
///
- bool isMacroScope() const { return true; }
- ///
int latex(odocstream &, OutputParams const &) const;
///
void validate(LaTeXFeatures &) const;
/// should paragraph indendation be ommitted in any case?
bool neverIndent() const;
///
- virtual bool isMacroScope() const { return true; }
+ virtual bool isMacroScope() const { return false; }
///
virtual bool allowMultiPar() const { return true; }
///
InsetCode lyxCode() const { return WRAP_CODE; }
///
- bool isMacroScope() const { return true; }
- ///
int latex(odocstream &, OutputParams const &) const;
///
int plaintext(odocstream &, OutputParams const &) const;
void MathMacroTemplate::write(WriteStream & os, bool overwriteRedefinition) const
{
- bool xargs = false;
- // newcommand or renewcommand
- if (os.latex() && optionals_ > 1) {
- if (redefinition_ && !overwriteRedefinition)
- os << "\\renewcommandx";
- else
- os << "\\newcommandx";
- xargs = true;
- //os << "\\newcommandx";
+ if (os.latex()) {
+ if (optionals_ > 0) {
+ // macros with optionals use the xargs package, e.g.:
+ // \newcommandx{\foo}[2][usedefault, addprefix=\global,1=default]{#1,#2}
+ if (redefinition_ && !overwriteRedefinition)
+ os << "\\renewcommandx";
+ else
+ os << "\\newcommandx";
+
+ os << "\\" << name().c_str()
+ << "[" << numargs_ << "]"
+ << "[usedefault, addprefix=\\global";
+ for (int i = 0; i < optionals_; ++i) {
+ docstring optValue = asString(cell(optIdx(i)));
+ if (optValue.find(']') != docstring::npos
+ || optValue.find('=') != docstring::npos)
+ os << ", " << i + 1 << "="
+ << "{" << cell(optIdx(i)) << "}";
+ else
+ os << ", " << i + 1 << "="
+ << cell(optIdx(i));
+ }
+ os << "]";
+ } else {
+ // macros without optionals use standard _global_ \def macros:
+ // \global\def\foo#1#2{#1,#2}
+ os << "\\global\\def\\" << name().c_str();
+ docstring param = from_ascii("#0");
+ for (int i = 1; i <= numargs_; ++i) {
+ param[1] = '0' + i;
+ os << param;
+ }
+ }
} else {
+ // in LyX output we use some pseudo syntax which is implementation
+ // independent, e.g.
+ // \newcommand{\foo}[2][default}{#1,#2}
if (redefinition_ && !overwriteRedefinition)
os << "\\renewcommand";
else
os << "\\newcommand";
- }
- os << "{\\" << name().c_str() << '}';
- if (numargs_ > 0)
- os << '[' << numargs_ << ']';
+ os << "{\\" << name().c_str() << '}';
+ if (numargs_ > 0)
+ os << '[' << numargs_ << ']';
- // optional values
- if (xargs) {
- os << "[usedefault";
- for (int i = 0; i < optionals_; ++i) {
- docstring optValue = asString(cell(optIdx(i)));
- if (optValue.find(']') != docstring::npos
- || optValue.find('=') != docstring::npos)
- os << ", " << i + 1 << "="
- << "{" << cell(optIdx(i)) << "}";
- else
- os << ", " << i + 1 << "="
- << cell(optIdx(i));
- }
- os << "]";
- } else {
for (int i = 0; i < optionals_; ++i) {
docstring optValue = asString(cell(optIdx(i)));
if (optValue.find(']') != docstring::npos)
}
}
-
os << "{" << cell(defIdx()) << "}";
if (os.latex()) {
void MathMacroTemplate::validate(LaTeXFeatures & features) const
{
- if (optionals_ > 1) {
+ if (optionals_ > 0) {
//features.require("newlyxcommand");
features.require("xargs");
}