void InsetCommandParams::write(ostream & os) const
{
	os << "CommandInset " << insetType() << '\n';
	os << "LatexCommand " << cmdName_ << '\n';
	if (preview_)
		os << "preview true\n";
	ParamInfo::const_iterator it  = info_.begin();
	ParamInfo::const_iterator end = info_.end();
	for (; it != end; ++it) {
		std::string const & name = it->name();
		docstring const & data = (*this)[name];
		if (!data.empty()) {
			// FIXME UNICODE
			os << name << ' '
			   << Lexer::quoteString(to_utf8(data))
			   << '\n';
		}
	}
}
void InsetCommandParams::Write(ostream & os, Buffer const * buffer) const
{
	os << "CommandInset " << insetType() << '\n';
	os << "LatexCommand " << cmdName_ << '\n';
	if (preview_)
		os << "preview true\n";
	ParamInfo::const_iterator it  = info_.begin();
	ParamInfo::const_iterator end = info_.end();
	for (; it != end; ++it) {
		string const & name = it->name();
		string data = to_utf8((*this)[name]);
		if (!data.empty()) {
			// Adjust path of files if document was moved
			if (buffer && name == "filename") {
				data = buffer->includedFilePath(data);
			} else if (buffer && name == "bibfiles") {
				int i = 0;
				string newdata;
				string bib = token(data, ',', i);
				while (!bib.empty()) {
					bib = buffer->includedFilePath(bib, "bib");
					if (!newdata.empty())
						newdata.append(1, ',');
					newdata.append(bib);
					bib = token(data, ',', ++i);
				}
				data = newdata;
			} else if (buffer && name == "options") {
				data = buffer->includedFilePath(data, "bst");
			}
			os << name << ' '
			   << Lexer::quoteString(data)
			   << '\n';
		}
	}
}