#include "support/lstrings.h"
#include "support/TempFile.h"
#include "support/textutils.h"
+#include "support/unique_ptr.h"
#include <algorithm>
#include <sstream>
"det", "dim", "exp", "gcd", "hom", "inf", "ker",
"lg", "lim", "liminf", "limsup", "ln", "log",
"max", "min", "sec", "sin", "sinh", "sup",
- "tan", "tanh", "Pr", 0
+ "tan", "tanh", "Pr", nullptr
};
static size_t const npos = lyx::docstring::npos;
// try to extract an "argument" to some function.
// returns position behind the argument
MathData::iterator extractArgument(MathData & ar,
- MathData::iterator pos, MathData::iterator last,
+ MathData::iterator pos, MathData::iterator last,
ExternalMath kind, bool function = false)
{
// nothing to get here
continue;
if (!arr.front()->asGridInset())
continue;
- ar[i] = MathAtom(new InsetMathMatrix(*(arr.front()->asGridInset()),
+ ar[i] = MathAtom(new InsetMathMatrix(*(arr.front()->asGridInset()),
inset->left_, inset->right_));
}
//
-// split scripts into seperate super- and subscript insets. sub goes in
+// split scripts into separate super- and subscript insets. sub goes in
// front of super...
//
// create extra script inset and move superscript over
InsetMathScript * p = ar[i].nucleus()->asScriptInset();
- auto_ptr<InsetMathScript> q(new InsetMathScript(buf, true));
+ auto q = make_unique<InsetMathScript>(buf, true);
swap(q->up(), p->up());
p->removeScript(true);
extractScript(exp, jt, ar.end(), true);
// create a proper inset as replacement
- auto_ptr<InsetMathExFunc> p(new InsetMathExFunc(buf, name));
+ auto p = lyx::make_unique<InsetMathExFunc>(buf, name);
// jt points to the "argument". Get hold of this.
- MathData::iterator st =
+ MathData::iterator st =
extractArgument(p->cell(0), jt, ar.end(), kind, true);
// replace the function name by a real function inset
if (!testIntegral(*it))
continue;
- // core ist part from behind the scripts to the 'd'
- auto_ptr<InsetMathExInt> p(new InsetMathExInt(buf, from_ascii("int")));
+ // core is part from behind the scripts to the 'd'
+ auto p = lyx::make_unique<InsetMathExInt>(buf, from_ascii("int"));
// handle scripts if available
if (!testIntSymbol(*it)) {
continue;
// create a proper inset as replacement
- auto_ptr<InsetMathExInt> p(new InsetMathExInt(buf, from_ascii("sum")));
+ auto p = lyx::make_unique<InsetMathExInt>(buf, from_ascii("sum"));
// collect lower bound and summation index
InsetMathScript const * sub = ar[i]->asScriptInset();
if (sub && sub->hasDown()) {
// try to figure out the summation index from the subscript
- MathData const & ar = sub->down();
+ MathData const & md = sub->down();
MathData::const_iterator xt =
- find_if(ar.begin(), ar.end(), &testEqualSign);
- if (xt != ar.end()) {
+ find_if(md.begin(), md.end(), &testEqualSign);
+ if (xt != md.end()) {
// we found a '=', use everything in front of that as index,
// and everything behind as lower index
- p->cell(1) = MathData(buf, ar.begin(), xt);
- p->cell(2) = MathData(buf, xt + 1, ar.end());
+ p->cell(1) = MathData(buf, md.begin(), xt);
+ p->cell(2) = MathData(buf, xt + 1, md.end());
} else {
// use everything as summation index, don't use scripts.
- p->cell(1) = ar;
+ p->cell(1) = md;
}
}
}
// create a proper diff inset
- auto_ptr<InsetMathDiff> diff(new InsetMathDiff(buf));
+ auto diff = lyx::make_unique<InsetMathDiff>(buf);
// collect function, let jt point behind last used item
MathData::iterator jt = it + 1;
int mult = 1;
if (extractNumber(script->up(), mult)) {
//lyxerr << "mult: " << mult << endl;
- for (int i = 0; i < mult; ++i)
+ if (mult < 0 || mult > 1000) {
+ lyxerr << "Cannot differentiate less than 0 or more than 1000 times !" << endl;
+ continue;
+ }
+ for (int ii = 0; ii < mult; ++ii)
diff->addDer(MathData(buf, dt + 1, st));
}
} else {
{
// In order to avoid parsing problems with command interpreters
// we pass input data through a file
- TempFile tempfile("casinput");
- FileName const cas_tmpfile = tempfile.name();
+ // Since the CAS is supposed to read the temp file we need
+ // to unlock it on windows (bug 10262).
+ unique_ptr<TempFile> tempfile(new TempFile("casinput"));
+ tempfile->setAutoRemove(false);
+ FileName const cas_tmpfile = tempfile->name();
+ tempfile.reset();
+
if (cas_tmpfile.empty()) {
lyxerr << "Warning: cannot create temporary file."
<< endl;
lyxerr << "calling: " << cmd
<< "\ninput: '" << data << "'" << endl;
cmd_ret const ret = runCommand(command);
- return ret.second;
+ cas_tmpfile.removeFile();
+ return ret.result;
}
size_t get_matching_brace(string const & str, size_t i)
if (tmp.size() < 2)
return MathData();
- out = subst(tmp[1], "\\>", string());
+ out = subst(subst(tmp[1], "\\>", string()), "{\\it ", "\\mathit{");
lyxerr << "output: '" << out << "'" << endl;
// Ugly code that tries to make the result prettier
return res;
}
-}
+} // namespace
-} // anon namespace
+} // namespace
-void write(MathData const & dat, WriteStream & wi)
+void write(MathData const & dat, TeXMathStream & wi)
{
wi.firstitem() = true;
docstring s;
}
-void writeString(docstring const & s, WriteStream & os)
+void writeString(docstring const & s, TeXMathStream & os)
{
- if (!os.latex() || os.lockedMode()) {
+ if (!os.latex()) {
os << (os.asciiOnly() ? escape(s) : s);
return;
}
- docstring::const_iterator cit = s.begin();
- docstring::const_iterator end = s.end();
+ if (os.lockedMode()) {
+ bool space;
+ docstring cmd;
+ for (char_type c : s) {
+ try {
+ Encodings::latexMathChar(c, true, os.encoding(), cmd, space);
+ os << cmd;
+ os.pendingSpace(space);
+ } catch (EncodingException const & e) {
+ switch (os.output()) {
+ case TeXMathStream::wsDryrun: {
+ os << "<" << _("LyX Warning: ")
+ << _("uncodable character") << " '";
+ os << docstring(1, e.failed_char);
+ os << "'>";
+ break;
+ }
+ case TeXMathStream::wsPreview: {
+ // indicate the encoding error by a boxed '?'
+ os << "{\\fboxsep=1pt\\fbox{?}}";
+ LYXERR0("Uncodable character" << " '"
+ << docstring(1, e.failed_char)
+ << "'");
+ break;
+ }
+ case TeXMathStream::wsDefault:
+ default:
+ // throw again
+ throw;
+ }
+ }
+ }
+ return;
+ }
// We may already be inside an \ensuremath command.
bool in_forced_mode = os.pendingBrace();
// We will take care of matching braces.
os.pendingBrace(false);
- while (cit != end) {
+ for (char_type const c : s) {
bool mathmode = in_forced_mode ? os.textMode() : !os.textMode();
- char_type const c = *cit;
docstring command(1, c);
try {
bool termination = false;
os.pendingSpace(true);
} catch (EncodingException const & e) {
switch (os.output()) {
- case WriteStream::wsDryrun: {
+ case TeXMathStream::wsDryrun: {
os << "<" << _("LyX Warning: ")
<< _("uncodable character") << " '";
os << docstring(1, e.failed_char);
os << "'>";
break;
}
- case WriteStream::wsPreview: {
+ case TeXMathStream::wsPreview: {
// indicate the encoding error by a boxed '?'
os << "{\\fboxsep=1pt\\fbox{?}}";
LYXERR0("Uncodable character" << " '"
<< "'");
break;
}
- case WriteStream::wsDefault:
+ case TeXMathStream::wsDefault:
default:
// throw again
- throw(e);
+ throw;
}
}
- ++cit;
}
if (in_forced_mode && os.textMode()) {
}
-void mathmlize(MathData const & dat, MathStream & os)
+void mathmlize(MathData const & dat, MathMLStream & ms)
{
MathData ar = dat;
extractStructure(ar, MATHML);
if (ar.empty())
- os << "<mrow/>";
+ ms << "<" << from_ascii(ms.namespacedTag("mrow")) << "/>";
else if (ar.size() == 1)
- os << ar.front();
+ ms << ar.front();
else {
- os << MTag("mrow");
+ ms << MTag("mrow");
for (MathData::const_iterator it = ar.begin(); it != ar.end(); ++it)
- (*it)->mathmlize(os);
- os << ETag("mrow");
+ (*it)->mathmlize(ms);
+ ms << ETag("mrow");
}
}