- if (!os.latex()) {
- os << str_;
- return;
- }
-
- // We need the latex macros defined in the unicodesymbols file.
- // As they do not depend on the encoding, simply use the first
- // available encoding.
- Encodings::const_iterator encit = encodings.begin();
- bool can_encode = encit != encodings.end();
-
- docstring::const_iterator cit = str_.begin();
- docstring::const_iterator end = str_.end();
-
- bool in_lyxmathsym = false;
- while (cit != end) {
- char_type const c = *cit;
- try {
- if (c < 0x80) {
- if (in_lyxmathsym) {
- os << '}';
- in_lyxmathsym = false;
- }
- os << docstring(1, c);
- } else if (can_encode) {
- if (!in_lyxmathsym) {
- os << "\\lyxmathsym{";
- in_lyxmathsym = true;
- }
- os << encit->latexChar(c, true);
- } else {
- throw EncodingException(c);
- }
- } catch (EncodingException & e) {
- if (os.dryrun()) {
- // FIXME: this is OK for View->Source
- // but math preview will likely fail.
- os << "<" << _("LyX Warning: ")
- << _("uncodable character") << " '";
- os << docstring(1, e.failed_char);
- os << "'>";
- } else {
- // throw again
- throw(e);
- }
- }
- ++cit;
- }
- if (in_lyxmathsym)
- os << '}';