// We have a bit of a problem here. MathML wants to know whether the
// character represents an "identifier" or an "operator", and we have
// no general way of telling. So we shall guess: If it's alpha or 
// mathalpha, then we'll treat it as an identifier, otherwise as an 
// operator.
// Worst case: We get bad spacing, or bad italics.
void InsetMathChar::mathmlize(MathStream & ms) const
{
	std::string entity;
	switch (char_) {
		case '<': entity = "&lt;"; break;
		case '>': entity = "&gt;"; break;
		case '&': entity = "&amp;"; break;
		case ' ': {
			ms << from_ascii("&nbsp;");
			return;
		}
		default: break;
	}
	
	if (ms.inText()) {
		if (entity.empty())
			ms.os().put(char_);
		else 
			ms << from_ascii(entity);
		return;
	}

	if (!entity.empty()) {
		ms << "<mo>" << from_ascii(entity) << "</mo>";
		return;
	}		

	char const * type = 
		(isalpha(char_) || Encodings::isMathAlpha(char_))
			? "mi" : "mo";
	// we don't use MTag and ETag because we do not want the spacing
	ms << "<" << type << ">" << char_type(char_) << "</" << type << ">";	
}
Exemple #2
0
void InsetPrintNomencl::latex(otexstream & os, OutputParams const & runparams_in) const
{
	OutputParams runparams = runparams_in;
	if (getParam("set_width") == "auto") {
		docstring widest = nomenclWidest(buffer(), runparams);
		// Set the label width via nomencl's command \nomlabelwidth.
		// This must be output before the command \printnomenclature
		if (!widest.empty()) {
			os << "\\settowidth{\\nomlabelwidth}{"
			   << widest
			   << "}\n";
		}
	} else if (getParam("set_width") == "custom") {
		// custom length as optional arg of \printnomenclature
		string const width =
			Length(to_ascii(getParam("width"))).asLatexString();
		os << '\\'
		   << from_ascii(getCmdName())
		   << '['
		   << from_ascii(width)
		   << "]{}";
		return;
	}
	// output the command \printnomenclature
	os << getCommand(runparams);
}
void InsetMathChar::htmlize(HtmlStream & ms) const
{
	std::string entity;
	switch (char_) {
		case '<': entity = "&lt;"; break;
		case '>': entity = "&gt;"; break;
		case '&': entity = "&amp;"; break;
		case ' ': entity = "&nbsp;"; break;
		default: break;
	}
	
	bool have_entity = !entity.empty();
	
	if (ms.inText()) {
		if (have_entity)
			ms << from_ascii(entity);
		else
			ms.os().put(char_);
		return;
	}
	
	if (have_entity) {
		// an operator, so give some space
		ms << ' ' << from_ascii(entity) << ' ';
		return;
	}		

	if (isalpha(char_) || Encodings::isMathAlpha(char_))
		// we don't use MTag and ETag because we do not want the spacing
		ms << MTag("i") << char_type(char_) << ETag("i");
	else
		// an operator, so give some space
		ms << " " << char_type(char_) << " ";
}
Exemple #4
0
void InsetRef::latex(otexstream & os, OutputParams const & rp) const
{
	string const cmd = getCmdName();
	docstring const data = getEscapedLabel(rp);

	if (rp.inulemcmd)
		os << "\\mbox{";

	if (cmd == "eqref" && buffer().params().use_refstyle) {
		// we advertise this as printing "(n)", so we'll do that, at least
		// for refstyle, since refstlye's own \eqref prints, by default,
		// "equation n". if one wants \eqref, one can get it by using a
		// formatted label in this case.
		os << '(' << from_ascii("\\ref{") << data << from_ascii("})");
	} 
	else if (cmd == "formatted") {
		docstring label;
		docstring prefix;
		docstring const fcmd = getFormattedCmd(data, label, prefix);
		os << fcmd << '{' << label << '}';
	}
	else {
		// We don't want to output p_["name"], since that is only used 
		// in docbook. So we construct new params, without it, and use that.
		InsetCommandParams p(REF_CODE, cmd);
		docstring const ref = getParam("reference");
		p["reference"] = ref;
		os << p.getCommand(rp);
	}

	if (rp.inulemcmd)
		os << "}";
}
Exemple #5
0
void InsetMathXYMatrix::write(WriteStream & os) const
{
    MathEnsurer ensurer(os);
    os << "\\xymatrix";
    if (equal_spacing_) {
        os << "@!";
        switch (spacing_code_) {
        case '0':
        case 'R':
        case 'C':
            os << spacing_code_;
        }
    } else {
        switch (spacing_code_) {
        case 'R':
        case 'C':
        case 'M':
        case 'W':
        case 'H':
        case 'L':
            os << '@' << spacing_code_ << '='
               << from_ascii(spacing_.asLatexString());
            break;
        default:
            if (!spacing_.empty())
                os << "@=" << from_ascii(spacing_.asLatexString());
        }
    }
    os << '{';
    InsetMathGrid::write(os);
    os << "}\n";
}
Exemple #6
0
void InsetMathXYMatrix::infoize(odocstream & os) const
{
    os << "xymatrix ";
    if (equal_spacing_) {
        switch (spacing_code_) {
        case '0':
        case 'R':
        case 'C':
            os << '!' << spacing_code_ << ' ';
        }
    } else {
        switch (spacing_code_) {
        case 'R':
        case 'C':
        case 'M':
        case 'W':
        case 'H':
        case 'L':
            os << spacing_code_ << ' '
               << from_ascii(spacing_.asLatexString()) << ' ';
            break;
        default:
            if (!spacing_.empty())
                os << from_ascii(spacing_.asLatexString()) << ' ';
        }
    }
    InsetMathGrid::infoize(os);
}
Exemple #7
0
int InsetCitation::docbook(odocstream & os, OutputParams const &) const
{
	os << from_ascii("<citation>")
	   << cleanupWhitespace(getParam("key"))
	   << from_ascii("</citation>");
	return 0;
}
bool IndicesList::addDefault(docstring const & n)
{
	if (findShortcut(from_ascii("idx")) != 0)
		// we already have a default
		return false;
	return add(n, from_ascii("idx"));
}
Exemple #9
0
void InsetCaption::updateBuffer(ParIterator const & it, UpdateType utype)
{
	Buffer const & master = *buffer().masterBuffer();
	DocumentClass const & tclass = master.params().documentClass();
	string const & lang = it.paragraph().getParLanguage(master.params())->code();
	Counters & cnts = tclass.counters();
	string const & type = cnts.current_float();
	if (utype == OutputUpdate) {
		// counters are local to the caption
		cnts.saveLastCounter();
	}
	// Memorize type for addToToc().
	floattype_ = type;
	if (type.empty() || type == "senseless")
		full_label_ = master.B_("Senseless!!! ");
	else {
		// FIXME: life would be _much_ simpler if listings was
		// listed in Floating.
		docstring name;
		if (type == "listing")
			name = master.B_("Listing");
		else
			name = master.B_(tclass.floats().getType(type).name());
		docstring counter = from_utf8(type);
		is_subfloat_ = cnts.isSubfloat();
		if (is_subfloat_) {
			// only standard captions allowed in subfloats
			type_ = "Standard";
			counter = "sub-" + from_utf8(type);
			name = bformat(_("Sub-%1$s"),
				       master.B_(tclass.floats().getType(type).name()));
		}
		docstring sec;
		docstring const lstring = getLayout().labelstring();
		docstring const labelstring = isAscii(lstring) ?
				master.B_(to_ascii(lstring)) : lstring;
		if (cnts.hasCounter(counter)) {
			// for longtables, we step the counter upstream
			if (!cnts.isLongtable())
				cnts.step(counter, utype);
			sec = cnts.theCounter(counter, lang);
		}
		if (labelstring != master.B_("standard")) {
			if (!sec.empty())
				sec += from_ascii(" ");
			sec += bformat(from_ascii("(%1$s)"), labelstring);
		}
		if (!sec.empty())
			full_label_ = bformat(from_ascii("%1$s %2$s: "), name, sec);
		else
			full_label_ = bformat(from_ascii("%1$s #: "), name);
	}

	// Do the real work now.
	InsetText::updateBuffer(it, utype);
	if (utype == OutputUpdate)
		cnts.restoreLastCounter();
}
Exemple #10
0
docstring InsetNomencl::toolTip(BufferView const & /*bv*/, int /*x*/, int /*y*/) const
{
	docstring tip = _("Nomenclature Symbol: ") + getParam("symbol") + "\n";
	tip += _("Description: ") + "\t"
		+ subst(getParam("description"), from_ascii("\\\\"), from_ascii("\n\t"));
	if (!getParam("prefix").empty())
		tip += "\n" + _("Sorting: ") + getParam("prefix");
	return tip;
}
Exemple #11
0
docstring LyXVC::vcstatus() const
{
	if (!vcs)
		return docstring();
	if (locking())
		return bformat(_("%1$s lock"), from_ascii(vcs->vcname()));
	else
		return from_ascii(vcs->vcname());
}
int InsetHyperlink::docbook(odocstream & os, OutputParams const &) const
{
	os << "<ulink url=\""
	   << subst(getParam("target"), from_ascii("&"), from_ascii("&amp;"))
	   << "\">"
	   << getParam("name")
	   << "</ulink>";
	return 0;
}
Exemple #13
0
docstring BranchList::getFileNameSuffix() const
{
	docstring result;
	List::const_iterator it = list.begin();
	for (; it != list.end(); ++it) {
		if (it->isSelected() && it->hasFileNameSuffix())
			result += "-" + it->branch();
	}
	return support::subst(result, from_ascii("/"), from_ascii("_"));
}
Exemple #14
0
docstring InsetMathFrac::name() const
{
	switch (kind_) {
	case FRAC:
		return from_ascii("frac");
	case CFRAC:
	case CFRACLEFT:
	case CFRACRIGHT:
		return from_ascii("cfrac");
	case DFRAC:
		return from_ascii("dfrac");
	case TFRAC:
		return from_ascii("tfrac");
	case OVER:
		return from_ascii("over");
	case NICEFRAC:
		return from_ascii("nicefrac");
	case UNITFRAC:
		return from_ascii("unitfrac");
	case UNIT:
		return from_ascii("unit");
	case ATOP:
		return from_ascii("atop");
	}
	// shut up stupid compiler
	return docstring();
}
Exemple #15
0
void InsetMathAMSArray::draw(PainterInfo & pi, int x, int y) const
{
	Changer dummy2 = pi.base.changeEnsureMath();
	Dimension const dim = dimension(*pi.base.bv);
	int const yy = y - dim.ascent();
	// Drawing the deco after changeStyle does not work
	mathed_draw_deco(pi, x + 1, yy, 5, dim.height(), from_ascii(name_left()));
	mathed_draw_deco(pi, x + dim.width() - 8, yy, 5, dim.height(), from_ascii(name_right()));
	Changer dummy = pi.base.changeArray();
	InsetMathGrid::draw(pi, x, y);
}
Exemple #16
0
docstring GuiBibitem::dialogToParams() const
{
	InsetCommandParams params(insetCode());
	QString label = labelED->text();
	if (!yearED->isHidden())
		label += "(" + yearED->text() + ")" + allAuthorsED->text();
	params["key"] = qstring_to_ucs4(keyED->text());
	params["label"] = qstring_to_ucs4(label);
	params["literal"] = literalCB->isChecked()
			? from_ascii("true") : from_ascii("false");
	return from_utf8(InsetCommand::params2string(params));
}
Exemple #17
0
QString const externalLineEnding(docstring const & str)
{
#ifdef Q_WS_MACX
	// The MAC clipboard uses \r for lineendings, and we use \n
	return toqstr(subst(str, '\n', '\r'));
#elif defined(Q_WS_WIN)
	// Windows clipboard uses \r\n for lineendings, and we use \n
	return toqstr(subst(str, from_ascii("\n"), from_ascii("\r\n")));
#else
	return toqstr(str);
#endif
}
Exemple #18
0
void InsetMathBig::draw(PainterInfo & pi, int x, int y) const
{
	Dimension const dim = dimension(*pi.base.bv);
	// mathed_draw_deco does not use the leading backslash, so remove it
	// (but don't use ltrim if this is the backslash delimiter).
	// Replace \| by \Vert (equivalent in LaTeX), since mathed_draw_deco
	// would treat it as |.
	docstring const delim = (delim_ == "\\|") ?  from_ascii("Vert") :
		(delim_ == "\\\\") ? from_ascii("\\") : support::ltrim(delim_, "\\");
	mathed_draw_deco(pi, x + 1, y - dim.ascent(), 4, dim.height(),
			 delim);
	setPosCache(pi, x, y);
}
Exemple #19
0
docstring const LaTeXFeatures::getTClassI18nPreamble(bool use_babel) const
{
	DocumentClass const & tclass = params_.documentClass();
	// collect preamble snippets in a set to prevent multiple identical
	// commands (would happen if e.g. both theorem and theorem* are used)
	set<docstring> snippets;
	typedef LanguageList::const_iterator lang_it;
	lang_it const lbeg = UsedLanguages_.begin();
	lang_it const lend =  UsedLanguages_.end();
	list<docstring>::const_iterator cit = usedLayouts_.begin();
	list<docstring>::const_iterator end = usedLayouts_.end();
	for (; cit != end; ++cit) {
		// language dependent commands (once per document)
		snippets.insert(tclass[*cit].langpreamble(buffer().language()));
		// commands for language changing (for multilanguage documents)
		if (use_babel && !UsedLanguages_.empty()) {
			snippets.insert(tclass[*cit].babelpreamble(buffer().language()));
			for (lang_it lit = lbeg; lit != lend; ++lit)
				snippets.insert(tclass[*cit].babelpreamble(*lit));
		}
	}
	if (use_babel && !UsedLanguages_.empty()) {
		FloatList const & floats = params_.documentClass().floats();
		UsedFloats::const_iterator fit = usedFloats_.begin();
		UsedFloats::const_iterator fend = usedFloats_.end();
		for (; fit != fend; ++fit) {
			Floating const & fl = floats.getType(fit->first);
			docstring const type = from_ascii(fl.floattype());
			docstring const flname = from_utf8(fl.name());
			docstring name = translateIfPossible(flname,
				buffer().language()->code());
			snippets.insert(getFloatI18nPreamble(
				type, name,
				from_ascii(buffer().language()->babel())));
			for (lang_it lit = lbeg; lit != lend; ++lit) {
				name = translateIfPossible(flname,
					(*lit)->code());
				snippets.insert(getFloatI18nPreamble(
					type, name,
					from_ascii((*lit)->babel())));
			}
		}
	}

	odocstringstream tcpreamble;
	set<docstring>::const_iterator const send = snippets.end();
	set<docstring>::const_iterator it = snippets.begin();
	for (; it != send; ++it)
		tcpreamble << *it;
	return tcpreamble.str();
}
Exemple #20
0
	docstring const get(string const & m) const
	{
		if (m.empty())
			return from_ascii(m);

		char * o = setlocale(LC_ALL, 0);
		string old;
		if (o)
			old = o;
		char * n = setlocale(LC_ALL, lang_.c_str());
		if (!n)
			// If we are unable to honour the request we just
			// return what we got in.
			return from_ascii(m);
		errno = 0;
		string const locale_dir = package().locale_dir().toFilesystemEncoding();
		char const * c = bindtextdomain(PACKAGE, locale_dir.c_str());
		int e = errno;
		if (e) {
			LYXERR(Debug::DEBUG, "Messages::get()" << '\n'
				<< "Error code: " << errno << '\n'
				<< "Lang, mess: " << lang_ << " " << m << '\n'
				<< "Directory : " << package().locale_dir().absFileName() << '\n'
				<< "Rtn value : " << c);
		}

		if (!bind_textdomain_codeset(PACKAGE, ucs4_codeset)) {
			LYXERR(Debug::DEBUG, "Messages::get()" << '\n'
				<< "Error code: " << errno << '\n'
				<< "Codeset   : " << ucs4_codeset << '\n');
		}

		textdomain(PACKAGE);

		char const * tmp = m.c_str();
		char const * msg = gettext(tmp);
		docstring translated;
		if (!msg) {
			lyxerr << "Undefined result from gettext" << endl;
			translated = from_ascii(tmp);
		} else if (msg == tmp) {
			//lyxerr << "Same as entered returned" << endl;
			translated = from_ascii(tmp);
		} else {
			LYXERR(Debug::DEBUG, "We got a translation");
			char_type const * ucs4 = reinterpret_cast<char_type const *>(msg);
			translated = ucs4;
		}
		setlocale(LC_ALL, old.c_str());
		return translated;
	}
Exemple #21
0
Buffer & Inset::buffer()
{
	if (!buffer_) {
		odocstringstream s;
		string const iname = insetName(lyxCode());
		LYXERR0("Inset: " << this << " LyX Code: " << lyxCode()
					<< " name: " << iname);
		s << "LyX Code: " << lyxCode() << " name: " << from_ascii(iname);
		LATTEST(false);
		throw ExceptionMessage(BufferException,
			from_ascii("Inset::buffer_ member not initialized!"), s.str());
	}
	return *buffer_;
}
Exemple #22
0
void InsetMathEnsureMath::metrics(MetricsInfo & mi, Dimension & dim) const
{
	bool really_change_font = isTextFont(from_ascii(mi.base.fontname));
	FontSetChanger dummy(mi.base, "mathnormal", really_change_font);
	cell(0).metrics(mi, dim);
	metricsMarkers(dim);
}
Exemple #23
0
void InsetMathEnsureMath::draw(PainterInfo & pi, int x, int y) const
{
	bool really_change_font = isTextFont(from_ascii(pi.base.fontname));
	FontSetChanger dummy(pi.base, "mathnormal", really_change_font);
	cell(0).draw(pi, x, y);
	drawMarkers(pi, x, y);
}
Exemple #24
0
void InsetRef::updateBuffer(ParIterator const & it, UpdateType)
{
	docstring const & ref = getParam("reference");
	// register this inset into the buffer reference cache.
	buffer().addReference(ref, this, it);

	docstring label;
	for (int i = 0; !types[i].latex_name.empty(); ++i) {
		if (getCmdName() == types[i].latex_name) {
			label = _(types[i].short_gui_name);
			break;
		}
	}
	label += ref;
	
	if (!buffer().params().isLatex() && !getParam("name").empty()) {
		label += "||";
		label += getParam("name");
	}
	
	screen_label_ = label;
	bool shortened = false;
	unsigned int const maxLabelChars = 24;
	if (screen_label_.size() > maxLabelChars) {
		screen_label_.erase(maxLabelChars - 3);
		screen_label_ += "...";
		shortened = true;
	}
	if (shortened)
		tooltip_ = label;
	else 
		tooltip_ = from_ascii("");
}
Exemple #25
0
static bool verify_chksum(char *buf, unsigned int *size)
{
	int i;
	uint16_t chksum = 0;
	int len = *size;

	if (len < 3)
		return false;
	while (buf[len - 1] == '\r' || (buf[len - 1] == '\n'))
			len--;
	chksum = from_ascii(&buf[len - 2], 2, LG_16);
	len -= 2;
	for (i = 1; i < len; i++)
		chksum += buf[i];

	chksum &= 0xff;

	if (chksum)
		ERROR("Wrong checksum received: %x", chksum);

	/*
	 * Drop checksum after verification
	 */
	buf[len] = '\0';

	*size = len;

	return (chksum == 0);
}
Exemple #26
0
void InsetMathSqrt::htmlize(HtmlStream & os) const
{
	os << MTag("span", "class='sqrt'")
	   << from_ascii("&radic;") 
	   << MTag("span", "class='sqrtof'")	<< cell(0) << ETag("span") 
		 << ETag("span");
}
Exemple #27
0
QStringList texFileList(QString const & filename)
{
	QStringList list;
	FileName const file = libFileSearch(QString(), filename);
	if (file.empty())
		return list;

	// FIXME Unicode.
	vector<docstring> doclist = 
		getVectorFromString(file.fileContents("UTF-8"), from_ascii("\n"));

	// Normalise paths like /foo//bar ==> /foo/bar
	QSet<QString> set;
	for (size_t i = 0; i != doclist.size(); ++i) {
		QString file = toqstr(doclist[i]);
		file.replace("\r", "");
		while (file.contains("//"))
			file.replace("//", "/");
		if (!file.isEmpty())
			set.insert(file);
	}

	// remove duplicates
	return QList<QString>::fromSet(set);
}
Exemple #28
0
bool InsetCaption::getStatus(Cursor & cur, FuncRequest const & cmd,
	FuncStatus & status) const
{
	switch (cmd.action()) {

	case LFUN_INSET_MODIFY: {
		string const first_arg = cmd.getArg(0);
		if (first_arg == "changetype") {
			string const type = cmd.getArg(1);
			status.setOnOff(type == type_);
			bool varia = type != "Unnumbered";
			// check if the immediate parent inset allows caption variation
			if (cur.depth() > 1) {
				varia = cur[cur.depth() - 2].inset().allowsCaptionVariation(type);
			}
			status.setEnabled(varia
					  && buffer().params().documentClass().hasInsetLayout(
						from_ascii("Caption:" + type)));
			return true;
		}
		return InsetText::getStatus(cur, cmd, status);
	}

	case LFUN_INSET_TOGGLE:
		// pass back to owner
		cur.undispatched();
		return false;

	default:
		return InsetText::getStatus(cur, cmd, status);
	}
}
Exemple #29
0
QValidator::State PathValidator::validate(QString & qtext, int &) const
{
	if (!latex_doc_)
		return QValidator::Acceptable;

	docstring const text = support::trim(qstring_to_ucs4(qtext));
	if (text.empty())
		return acceptable_if_empty_ ?
			QValidator::Acceptable : QValidator::Intermediate;

	docstring invalid_chars = from_ascii("#$%{}()[]\"^");
	if (!tex_allows_spaces_)
		invalid_chars += ' ';

	if (text.find_first_of(invalid_chars) != docstring::npos) {

		static int counter = 0;
		if (counter == 0) {
			Alert::error(_("Invalid filename"),
				     _("LyX does not provide LaTeX support for file names containing any of these characters:\n") +
					 printable_list(invalid_chars));
		}
		++counter;
		return QValidator::Intermediate;
	}

	return QValidator::Acceptable;
}
Exemple #30
0
docstring const class_to_string(MathClass const mc)
{
	string s;
	switch (mc) {
	case MC_ORD:
		s = "mathord";
		break;
	case MC_OP:
		s = "mathop";
		break;
	case MC_BIN:
		s = "mathbin";
		break;
	case MC_REL:
		s = "mathrel";
		break;
	case MC_OPEN:
		s = "mathopen";
		break;
	case MC_CLOSE:
		s = "mathclose";
		break;
	case MC_PUNCT:
		s = "mathpunct";
		break;
	case MC_INNER:
		s = "mathinner";
		break;
	case MC_UNKNOWN:
		LATTEST(false);
		s = "mathord";
	}
	return from_ascii(s);
}