+bool MacroData::hidden() const
+{
+ if (sym_)
+ return sym_->hidden;
+ return false;
+}
+
+
+docstring const MacroData::xmlname() const
+{
+ if (sym_)
+ return sym_->xmlname;
+ return docstring();
+}
+
+
+char const * MacroData::MathMLtype() const
+{
+ return sym_ ? sym_->MathMLtype() : 0;
+}
+
+
+void MacroData::unlock() const
+{
+ --lockCount_;
+ LASSERT(lockCount_ >= 0, lockCount_ = 0);
+}
+
+
+void MacroData::queryData(MathMacroTemplate const & macro) const
+{
+ if (queried_)
+ return;
+
+ queried_ = true;
+ definition_ = macro.definition();
+ numargs_ = macro.numArgs();
+ display_ = macro.displayDefinition();
+ redefinition_ = macro.redefinition();
+ type_ = macro.type();
+ optionals_ = macro.numOptionals();
+
+ macro.getDefaults(defaults_);
+}
+
+
+void MacroData::updateData() const
+{
+ if (queried_)
+ return;
+
+ LBUFERR(buffer_);
+
+ // Try to fix position DocIterator. Should not do anything in theory.
+ pos_.fixIfBroken();
+
+ // find macro template
+ Inset * inset = pos_.nextInset();
+ if (inset == 0 || inset->lyxCode() != MATHMACRO_CODE) {
+ lyxerr << "BUG: No macro template found by MacroData" << endl;
+ return;
+ }
+
+ // query the data from the macro template
+ queryData(static_cast<MathMacroTemplate const &>(*inset));
+}
+
+
+int MacroData::write(odocstream & os, bool overwriteRedefinition) const
+{
+ updateData();
+
+ // find macro template
+ Inset * inset = pos_.nextInset();
+ if (inset == 0 || inset->lyxCode() != MATHMACRO_CODE) {
+ lyxerr << "BUG: No macro template found by MacroData" << endl;
+ return 0;
+ }
+
+ // output template
+ MathMacroTemplate const & tmpl =
+ static_cast<MathMacroTemplate const &>(*inset);
+ otexrowstream ots(os);
+ WriteStream wi(ots, false, true, WriteStream::wsDefault);
+ return tmpl.write(wi, overwriteRedefinition);
+}
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// The global table of macros
+//
+/////////////////////////////////////////////////////////////////////
+
+MacroTable & MacroTable::globalMacros()
+{
+ static MacroTable theGlobalMacros;
+ return theGlobalMacros;
+}
+
+
+MacroData const * MacroTable::get(docstring const & name) const