2003-08-19 13:00:56 +00:00
|
|
|
|
/**
|
2007-04-25 03:01:35 +00:00
|
|
|
|
* \file InsetMathString.cpp
|
2003-08-19 13:00:56 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
2001-12-05 08:04:20 +00:00
|
|
|
|
|
2003-08-19 13:00:56 +00:00
|
|
|
|
#include <config.h>
|
2001-11-05 17:08:45 +00:00
|
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "InsetMathString.h"
|
2006-10-22 10:15:23 +00:00
|
|
|
|
#include "MathStream.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "MathSupport.h"
|
2001-11-05 17:08:45 +00:00
|
|
|
|
|
2008-05-31 20:54:50 +00:00
|
|
|
|
#include "Encoding.h"
|
|
|
|
|
|
|
|
|
|
#include "support/gettext.h"
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
namespace lyx {
|
2003-10-06 15:43:21 +00:00
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
InsetMathString::InsetMathString(docstring const & s)
|
2002-05-30 07:09:54 +00:00
|
|
|
|
: str_(s)
|
2001-11-05 17:08:45 +00:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2007-08-30 18:03:17 +00:00
|
|
|
|
Inset * InsetMathString::clone() const
|
2002-03-21 17:42:56 +00:00
|
|
|
|
{
|
2007-08-30 18:03:17 +00:00
|
|
|
|
return new InsetMathString(*this);
|
2001-11-05 17:08:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-21 20:39:47 +00:00
|
|
|
|
void InsetMathString::metrics(MetricsInfo & mi, Dimension & dim) const
|
2001-11-05 17:08:45 +00:00
|
|
|
|
{
|
2006-10-22 10:15:23 +00:00
|
|
|
|
mathed_string_dim(mi.base.font, str_, dim);
|
2001-11-05 17:08:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathString::draw(PainterInfo & pi, int x, int y) const
|
2002-03-21 17:42:56 +00:00
|
|
|
|
{
|
2006-10-22 10:15:23 +00:00
|
|
|
|
pi.draw(x, y, str_);
|
2001-11-05 17:08:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathString::normalize(NormalStream & os) const
|
2001-11-05 17:08:45 +00:00
|
|
|
|
{
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << "[string " << str_ << ' ' << "mathalpha" << ']';
|
2001-11-05 17:08:45 +00:00
|
|
|
|
}
|
2001-11-07 08:51:35 +00:00
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathString::maple(MapleStream & os) const
|
2001-11-07 08:51:35 +00:00
|
|
|
|
{
|
2002-07-01 11:17:14 +00:00
|
|
|
|
if (/*code_ != LM_TC_VAR ||*/ str_.size() <= 1) {
|
2001-12-05 08:04:20 +00:00
|
|
|
|
os << ' ' << str_ << ' ';
|
2001-11-07 17:30:26 +00:00
|
|
|
|
return;
|
2002-03-21 17:42:56 +00:00
|
|
|
|
}
|
2001-11-07 17:30:26 +00:00
|
|
|
|
|
|
|
|
|
// insert '*' between adjacent chars if type is LM_TC_VAR
|
|
|
|
|
os << str_[0];
|
2006-10-22 10:15:23 +00:00
|
|
|
|
for (size_t i = 1; i < str_.size(); ++i)
|
2002-06-25 13:19:50 +00:00
|
|
|
|
os << str_[i];
|
2001-11-07 08:51:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathString::mathematica(MathematicaStream & os) const
|
2002-07-01 11:17:14 +00:00
|
|
|
|
{
|
|
|
|
|
os << ' ' << str_ << ' ';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathString::octave(OctaveStream & os) const
|
2001-11-07 08:51:35 +00:00
|
|
|
|
{
|
2002-05-30 07:09:54 +00:00
|
|
|
|
if (/*code_ != LM_TC_VAR ||*/ str_.size() <= 1) {
|
2001-12-05 08:04:20 +00:00
|
|
|
|
os << ' ' << str_ << ' ';
|
2001-11-07 17:30:26 +00:00
|
|
|
|
return;
|
2002-03-21 17:42:56 +00:00
|
|
|
|
}
|
2001-11-07 08:51:35 +00:00
|
|
|
|
|
|
|
|
|
// insert '*' between adjacent chars if type is LM_TC_VAR
|
2001-11-07 17:30:26 +00:00
|
|
|
|
os << str_[0];
|
2006-10-22 10:15:23 +00:00
|
|
|
|
for (size_t i = 1; i < str_.size(); ++i)
|
2002-06-25 13:19:50 +00:00
|
|
|
|
os << str_[i];
|
2001-11-07 17:30:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
void InsetMathString::mathmlize(MathStream & os) const
|
2001-11-07 17:30:26 +00:00
|
|
|
|
{
|
2002-05-30 07:09:54 +00:00
|
|
|
|
/*
|
2001-11-07 17:30:26 +00:00
|
|
|
|
if (code_ == LM_TC_VAR)
|
2001-12-05 08:04:20 +00:00
|
|
|
|
os << "<mi> " << str_ << " </mi>";
|
2001-11-07 17:30:26 +00:00
|
|
|
|
else if (code_ == LM_TC_CONST)
|
2001-12-05 08:04:20 +00:00
|
|
|
|
os << "<mn> " << str_ << " </mn>";
|
2001-11-07 17:30:26 +00:00
|
|
|
|
else if (code_ == LM_TC_RM || code_ == LM_TC_TEXTRM)
|
2001-12-05 08:04:20 +00:00
|
|
|
|
os << "<mtext> " << str_ << " </mtext>";
|
2001-11-07 17:30:26 +00:00
|
|
|
|
else
|
2002-05-30 07:09:54 +00:00
|
|
|
|
*/
|
2001-12-05 08:04:20 +00:00
|
|
|
|
os << str_;
|
2001-11-07 08:51:35 +00:00
|
|
|
|
}
|
2001-11-15 15:14:27 +00:00
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathString::write(WriteStream & os) const
|
2001-11-15 15:14:27 +00:00
|
|
|
|
{
|
2008-05-31 20:54:50 +00:00
|
|
|
|
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();
|
|
|
|
|
|
2008-06-01 14:11:36 +00:00
|
|
|
|
bool in_lyxmathsym = false;
|
2008-05-31 20:54:50 +00:00
|
|
|
|
while (cit != end) {
|
|
|
|
|
char_type const c = *cit;
|
|
|
|
|
try {
|
|
|
|
|
if (c < 0x80) {
|
2008-06-01 14:11:36 +00:00
|
|
|
|
if (in_lyxmathsym) {
|
2008-05-31 20:54:50 +00:00
|
|
|
|
os << '}';
|
2008-06-01 14:11:36 +00:00
|
|
|
|
in_lyxmathsym = false;
|
2008-05-31 20:54:50 +00:00
|
|
|
|
}
|
|
|
|
|
os << docstring(1, c);
|
|
|
|
|
} else if (can_encode) {
|
2008-06-01 14:11:36 +00:00
|
|
|
|
if (!in_lyxmathsym) {
|
|
|
|
|
os << "\\lyxmathsym{";
|
|
|
|
|
in_lyxmathsym = true;
|
2008-05-31 20:54:50 +00:00
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
}
|
2008-06-01 14:11:36 +00:00
|
|
|
|
if (in_lyxmathsym)
|
2008-05-31 20:54:50 +00:00
|
|
|
|
os << '}';
|
2001-11-15 15:14:27 +00:00
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|