2003-08-19 13:00:56 +00:00
|
|
|
|
/**
|
2006-09-17 09:14:18 +00:00
|
|
|
|
* \file MathFactory.C
|
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-08-13 14:19:16 +00:00
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "MathFactory.h"
|
2006-09-17 10:00:15 +00:00
|
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "InsetMathAMSArray.h"
|
2006-09-17 10:00:15 +00:00
|
|
|
|
#include "InsetMathArray.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "InsetMathBinom.h"
|
|
|
|
|
#include "InsetMathBoldSymbol.h"
|
2006-09-17 10:00:15 +00:00
|
|
|
|
#include "InsetMathBoxed.h"
|
|
|
|
|
#include "InsetMathBox.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "InsetMathCases.h"
|
|
|
|
|
#include "InsetMathColor.h"
|
|
|
|
|
#include "InsetMathDecoration.h"
|
|
|
|
|
#include "InsetMathDFrac.h"
|
|
|
|
|
#include "InsetMathDots.h"
|
|
|
|
|
#include "InsetMathFBox.h"
|
|
|
|
|
#include "InsetMathFont.h"
|
|
|
|
|
#include "InsetMathFontOld.h"
|
|
|
|
|
#include "InsetMathFrac.h"
|
2006-09-17 10:00:15 +00:00
|
|
|
|
#include "InsetMathFrameBox.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "InsetMathKern.h"
|
|
|
|
|
#include "InsetMathLefteqn.h"
|
|
|
|
|
#include "InsetMathMacro.h"
|
|
|
|
|
#include "InsetMathMakebox.h"
|
|
|
|
|
#include "InsetMathOverset.h"
|
|
|
|
|
#include "InsetMathPhantom.h"
|
2006-09-17 10:00:15 +00:00
|
|
|
|
#include "InsetMathRef.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "InsetMathRoot.h"
|
|
|
|
|
#include "InsetMathSize.h"
|
|
|
|
|
#include "InsetMathSpace.h"
|
|
|
|
|
#include "InsetMathSplit.h"
|
|
|
|
|
#include "InsetMathSqrt.h"
|
|
|
|
|
#include "InsetMathStackrel.h"
|
|
|
|
|
#include "InsetMathSubstack.h"
|
|
|
|
|
#include "InsetMathSymbol.h"
|
|
|
|
|
#include "InsetMathTabular.h"
|
|
|
|
|
#include "InsetMathTFrac.h"
|
|
|
|
|
#include "InsetMathUnderset.h"
|
|
|
|
|
#include "InsetMathUnknown.h"
|
|
|
|
|
#include "InsetMathXArrow.h"
|
|
|
|
|
#include "InsetMathXYMatrix.h"
|
2006-09-17 10:00:15 +00:00
|
|
|
|
#include "MathMacroArgument.h"
|
|
|
|
|
#include "MathMacroTable.h"
|
|
|
|
|
#include "MathParser.h"
|
|
|
|
|
#include "MathSupport.h"
|
2002-06-24 15:51:35 +00:00
|
|
|
|
|
2002-05-30 07:09:54 +00:00
|
|
|
|
#include "debug.h"
|
2004-04-06 19:25:39 +00:00
|
|
|
|
|
2007-04-06 08:30:37 +00:00
|
|
|
|
#include "insets/insetcommand.h"
|
|
|
|
|
|
2002-05-30 07:09:54 +00:00
|
|
|
|
#include "support/filetools.h" // LibFileSearch
|
2003-03-04 16:39:13 +00:00
|
|
|
|
#include "support/lstrings.h"
|
2004-04-06 19:25:39 +00:00
|
|
|
|
|
2006-10-03 16:17:32 +00:00
|
|
|
|
#include "frontends/FontLoader.h"
|
2002-05-30 07:09:54 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
|
using support::libFileSearch;
|
|
|
|
|
using support::split;
|
2002-05-30 07:09:54 +00:00
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2002-11-04 00:15:56 +00:00
|
|
|
|
using std::endl;
|
2003-09-05 18:02:24 +00:00
|
|
|
|
using std::istringstream;
|
2006-10-21 11:15:37 +00:00
|
|
|
|
using std::vector;
|
2002-11-04 00:15:56 +00:00
|
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
|
bool has_math_fonts;
|
|
|
|
|
|
2002-11-04 02:12:42 +00:00
|
|
|
|
|
2002-05-30 07:09:54 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
// file scope
|
2006-10-22 10:15:23 +00:00
|
|
|
|
typedef std::map<docstring, latexkeys> WordList;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
2002-05-30 07:09:54 +00:00
|
|
|
|
WordList theWordList;
|
|
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
bool math_font_available(docstring & name)
|
2002-06-18 15:44:30 +00:00
|
|
|
|
{
|
|
|
|
|
LyXFont f;
|
|
|
|
|
augmentFont(f, name);
|
|
|
|
|
|
|
|
|
|
// Do we have the font proper?
|
2006-10-11 17:24:46 +00:00
|
|
|
|
if (theFontLoader().available(f))
|
2002-06-18 15:44:30 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
// can we fake it?
|
|
|
|
|
if (name == "eufrak") {
|
2006-10-22 10:15:23 +00:00
|
|
|
|
name = from_ascii("lyxfakefrak");
|
2002-06-18 15:44:30 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::MATHED)
|
2006-10-22 10:15:23 +00:00
|
|
|
|
<< "font " << to_utf8(name) << " not available and I can't fake it"
|
2002-11-04 00:15:56 +00:00
|
|
|
|
<< endl;
|
2002-06-18 15:44:30 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2002-05-30 07:09:54 +00:00
|
|
|
|
|
2002-07-11 09:34:58 +00:00
|
|
|
|
void initSymbols()
|
2002-05-30 07:09:54 +00:00
|
|
|
|
{
|
2006-11-26 21:30:39 +00:00
|
|
|
|
support::FileName const filename = libFileSearch(string(), "symbols");
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::MATHED) << "read symbols from " << filename << endl;
|
2002-07-11 09:34:58 +00:00
|
|
|
|
if (filename.empty()) {
|
2002-11-04 00:15:56 +00:00
|
|
|
|
lyxerr << "Could not find symbols file" << endl;
|
2002-07-11 09:34:58 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2006-11-26 21:30:39 +00:00
|
|
|
|
std::ifstream fs(filename.toFilesystemEncoding().c_str());
|
2002-07-12 14:24:47 +00:00
|
|
|
|
string line;
|
2002-10-14 20:19:32 +00:00
|
|
|
|
bool skip = false;
|
2002-11-04 02:12:42 +00:00
|
|
|
|
while (getline(fs, line)) {
|
2002-05-30 07:09:54 +00:00
|
|
|
|
int charid = 0;
|
|
|
|
|
int fallbackid = 0;
|
2006-11-17 20:43:49 +00:00
|
|
|
|
if (line.empty() || line[0] == '#')
|
2002-07-11 09:34:58 +00:00
|
|
|
|
continue;
|
2002-07-12 14:24:47 +00:00
|
|
|
|
|
2002-10-28 10:39:12 +00:00
|
|
|
|
// special case of iffont/else/endif
|
2002-10-14 20:19:32 +00:00
|
|
|
|
if (line.size() >= 7 && line.substr(0, 6) == "iffont") {
|
2003-09-15 11:00:00 +00:00
|
|
|
|
istringstream is(line);
|
2002-10-14 20:19:32 +00:00
|
|
|
|
string tmp;
|
|
|
|
|
is >> tmp;
|
|
|
|
|
is >> tmp;
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring t = from_utf8(tmp);
|
|
|
|
|
skip = !math_font_available(t);
|
2002-10-14 20:19:32 +00:00
|
|
|
|
continue;
|
2002-10-21 13:38:02 +00:00
|
|
|
|
} else if (line.size() >= 4 && line.substr(0, 4) == "else") {
|
|
|
|
|
skip = !skip;
|
|
|
|
|
} else if (line.size() >= 5 && line.substr(0, 5) == "endif") {
|
2002-10-14 20:19:32 +00:00
|
|
|
|
skip = false;
|
|
|
|
|
continue;
|
|
|
|
|
} else if (skip)
|
|
|
|
|
continue;
|
|
|
|
|
|
2002-07-12 14:24:47 +00:00
|
|
|
|
// special case of pre-defined macros
|
|
|
|
|
if (line.size() > 8 && line.substr(0, 5) == "\\def\\") {
|
2004-04-13 06:27:29 +00:00
|
|
|
|
//lyxerr << "macro definition: '" << line << '\'' << endl;
|
2006-11-13 17:35:18 +00:00
|
|
|
|
istringstream is(line);
|
|
|
|
|
string macro;
|
|
|
|
|
string requires;
|
|
|
|
|
is >> macro >> requires;
|
|
|
|
|
MacroTable::globalMacros().insert(from_utf8(macro), requires);
|
2002-07-12 14:24:47 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
idocstringstream is(from_utf8(line));
|
2002-10-14 20:19:32 +00:00
|
|
|
|
latexkeys tmp;
|
2006-11-13 17:35:18 +00:00
|
|
|
|
is >> tmp.name >> tmp.inset;
|
2002-11-04 00:15:56 +00:00
|
|
|
|
if (isFontName(tmp.inset))
|
2002-07-11 09:34:58 +00:00
|
|
|
|
is >> charid >> fallbackid >> tmp.extra >> tmp.xmlname;
|
|
|
|
|
else
|
|
|
|
|
is >> tmp.extra;
|
2006-11-13 17:35:18 +00:00
|
|
|
|
// requires is optional
|
|
|
|
|
if (is)
|
|
|
|
|
is >> tmp.requires;
|
|
|
|
|
else {
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::MATHED) << "skipping line '" << line << '\'' << endl;
|
|
|
|
|
LYXERR(Debug::MATHED)
|
2006-10-22 10:15:23 +00:00
|
|
|
|
<< to_utf8(tmp.name) << ' ' << to_utf8(tmp.inset) << ' ' << to_utf8(tmp.extra) << endl;
|
2002-05-30 07:09:54 +00:00
|
|
|
|
continue;
|
2002-07-11 09:34:58 +00:00
|
|
|
|
}
|
2002-05-30 07:09:54 +00:00
|
|
|
|
|
2002-07-11 09:34:58 +00:00
|
|
|
|
if (isFontName(tmp.inset)) {
|
|
|
|
|
// tmp.inset _is_ the fontname here.
|
|
|
|
|
// create fallbacks if necessary
|
2002-12-18 22:15:59 +00:00
|
|
|
|
|
2005-06-07 17:21:51 +00:00
|
|
|
|
// store requirements as long as we can
|
2006-11-13 17:35:18 +00:00
|
|
|
|
if (tmp.requires.empty() &&
|
|
|
|
|
(tmp.inset == "msa" || tmp.inset == "msb"))
|
2006-10-22 10:15:23 +00:00
|
|
|
|
tmp.requires = from_ascii("amssymb");
|
2006-11-13 17:35:18 +00:00
|
|
|
|
else if (tmp.inset == "wasy")
|
|
|
|
|
tmp.requires = from_ascii("wasysym");
|
2005-06-07 17:21:51 +00:00
|
|
|
|
|
2002-12-18 22:15:59 +00:00
|
|
|
|
// symbol font is not available sometimes
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring symbol_font = from_ascii("lyxsymbol");
|
2002-12-18 22:15:59 +00:00
|
|
|
|
|
2002-11-04 02:12:42 +00:00
|
|
|
|
if (tmp.extra == "func" || tmp.extra == "funclim" || tmp.extra == "special") {
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::MATHED) << "symbol abuse for " << to_utf8(tmp.name) << endl;
|
2006-10-22 10:15:23 +00:00
|
|
|
|
tmp.draw = tmp.name;
|
2002-07-11 09:34:58 +00:00
|
|
|
|
} else if (math_font_available(tmp.inset)) {
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::MATHED) << "symbol available for " << to_utf8(tmp.name) << endl;
|
2006-10-21 11:15:37 +00:00
|
|
|
|
tmp.draw.push_back(char_type(charid));
|
2002-12-18 22:15:59 +00:00
|
|
|
|
} else if (fallbackid && math_font_available(symbol_font)) {
|
2002-07-11 09:34:58 +00:00
|
|
|
|
if (tmp.inset == "cmex")
|
2006-10-22 10:15:23 +00:00
|
|
|
|
tmp.inset = from_ascii("lyxsymbol");
|
2002-07-11 09:34:58 +00:00
|
|
|
|
else
|
2006-10-22 10:15:23 +00:00
|
|
|
|
tmp.inset = from_ascii("lyxboldsymbol");
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::MATHED) << "symbol fallback for " << to_utf8(tmp.name) << endl;
|
2006-10-21 11:15:37 +00:00
|
|
|
|
tmp.draw.push_back(char_type(fallbackid));
|
2002-07-11 09:34:58 +00:00
|
|
|
|
} else {
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::MATHED) << "faking " << to_utf8(tmp.name) << endl;
|
2006-10-22 10:15:23 +00:00
|
|
|
|
tmp.draw = tmp.name;
|
|
|
|
|
tmp.inset = from_ascii("lyxtex");
|
2002-07-11 09:34:58 +00:00
|
|
|
|
}
|
2002-06-18 15:44:30 +00:00
|
|
|
|
} else {
|
2002-07-11 09:34:58 +00:00
|
|
|
|
// it's a proper inset
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::MATHED) << "inset " << to_utf8(tmp.inset)
|
2006-10-22 10:15:23 +00:00
|
|
|
|
<< " used for " << to_utf8(tmp.name)
|
2002-11-04 02:12:42 +00:00
|
|
|
|
<< endl;
|
2002-05-30 07:09:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (theWordList.find(tmp.name) != theWordList.end())
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::MATHED)
|
2006-10-22 10:15:23 +00:00
|
|
|
|
<< "readSymbols: inset " << to_utf8(tmp.name)
|
2002-11-04 02:12:42 +00:00
|
|
|
|
<< " already exists." << endl;
|
2002-05-30 07:09:54 +00:00
|
|
|
|
else
|
|
|
|
|
theWordList[tmp.name] = tmp;
|
2002-11-04 02:12:42 +00:00
|
|
|
|
|
2007-04-01 10:09:49 +00:00
|
|
|
|
LYXERR(Debug::MATHED)
|
2006-10-22 10:15:23 +00:00
|
|
|
|
<< "read symbol '" << to_utf8(tmp.name)
|
|
|
|
|
<< " inset: " << to_utf8(tmp.inset)
|
2002-11-04 02:12:42 +00:00
|
|
|
|
<< " draw: " << int(tmp.draw.empty() ? 0 : tmp.draw[0])
|
2006-10-22 10:15:23 +00:00
|
|
|
|
<< " extra: " << to_utf8(tmp.extra)
|
2006-11-13 17:35:18 +00:00
|
|
|
|
<< " requires: " << to_utf8(tmp.requires)
|
2002-11-27 10:30:28 +00:00
|
|
|
|
<< '\'' << endl;
|
2002-05-30 07:09:54 +00:00
|
|
|
|
}
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring tmp = from_ascii("cmm");
|
|
|
|
|
docstring tmp2 = from_ascii("cmsy");
|
2002-10-28 10:39:12 +00:00
|
|
|
|
has_math_fonts = math_font_available(tmp) && math_font_available(tmp2);
|
2002-05-30 07:09:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
|
|
2002-07-12 14:24:47 +00:00
|
|
|
|
void initMath()
|
2002-05-30 07:09:54 +00:00
|
|
|
|
{
|
|
|
|
|
static bool initialized = false;
|
|
|
|
|
if (!initialized) {
|
2006-01-24 11:04:30 +00:00
|
|
|
|
initialized = true;
|
2004-04-13 06:27:29 +00:00
|
|
|
|
initParser();
|
2006-10-14 14:15:06 +00:00
|
|
|
|
initSymbols();
|
2002-05-30 07:09:54 +00:00
|
|
|
|
}
|
2002-07-12 14:24:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-05-30 07:09:54 +00:00
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
latexkeys const * in_word_set(docstring const & str)
|
2002-07-12 14:24:47 +00:00
|
|
|
|
{
|
2002-05-30 07:09:54 +00:00
|
|
|
|
WordList::iterator it = theWordList.find(str);
|
2005-07-15 08:51:34 +00:00
|
|
|
|
return it != theWordList.end() ? &(it->second) : 0;
|
2001-08-13 14:19:16 +00:00
|
|
|
|
}
|
2001-08-15 05:50:39 +00:00
|
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
MathAtom createInsetMath(char const * const s)
|
|
|
|
|
{
|
|
|
|
|
return createInsetMath(from_utf8(s));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MathAtom createInsetMath(docstring const & s)
|
2001-08-15 05:50:39 +00:00
|
|
|
|
{
|
2004-04-13 06:27:29 +00:00
|
|
|
|
//lyxerr << "creating inset with name: '" << s << '\'' << endl;
|
2002-07-31 17:26:14 +00:00
|
|
|
|
latexkeys const * l = in_word_set(s);
|
|
|
|
|
if (l) {
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring const & inset = l->inset;
|
2003-10-02 15:46:33 +00:00
|
|
|
|
//lyxerr << " found inset: '" << inset << '\'' << endl;
|
2002-07-31 17:26:14 +00:00
|
|
|
|
if (inset == "ref")
|
|
|
|
|
return MathAtom(new RefInset(l->name));
|
2003-08-22 16:01:13 +00:00
|
|
|
|
if (inset == "overset")
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return MathAtom(new InsetMathOverset);
|
2002-07-31 17:26:14 +00:00
|
|
|
|
if (inset == "underset")
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return MathAtom(new InsetMathUnderset);
|
2002-07-31 17:26:14 +00:00
|
|
|
|
if (inset == "decoration")
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return MathAtom(new InsetMathDecoration(l));
|
2002-07-31 17:26:14 +00:00
|
|
|
|
if (inset == "space")
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return MathAtom(new InsetMathSpace(l->name));
|
2002-07-31 17:26:14 +00:00
|
|
|
|
if (inset == "dots")
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return MathAtom(new InsetMathDots(l));
|
2005-03-16 17:06:47 +00:00
|
|
|
|
if (inset == "mbox")
|
2006-09-16 18:11:38 +00:00
|
|
|
|
// return MathAtom(new InsetMathMBox);
|
|
|
|
|
// InsetMathMBox is proposed to replace InsetMathBox,
|
2005-03-16 17:06:47 +00:00
|
|
|
|
// but is not ready yet (it needs a BufferView for
|
|
|
|
|
// construction)
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return MathAtom(new InsetMathBox(l->name));
|
2004-08-13 13:19:58 +00:00
|
|
|
|
// if (inset == "fbox")
|
2006-09-16 18:11:38 +00:00
|
|
|
|
// return MathAtom(new InsetMathFBox(l));
|
2002-07-31 17:26:14 +00:00
|
|
|
|
if (inset == "style")
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return MathAtom(new InsetMathSize(l));
|
2002-07-31 17:26:14 +00:00
|
|
|
|
if (inset == "font")
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return MathAtom(new InsetMathFont(l));
|
2002-07-31 17:26:14 +00:00
|
|
|
|
if (inset == "oldfont")
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return MathAtom(new InsetMathFontOld(l));
|
2002-07-31 17:26:14 +00:00
|
|
|
|
if (inset == "matrix")
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return MathAtom(new InsetMathAMSArray(s));
|
2006-10-03 19:45:43 +00:00
|
|
|
|
if (inset == "split")
|
|
|
|
|
return MathAtom(new InsetMathSplit(s));
|
2006-04-20 09:55:45 +00:00
|
|
|
|
if (inset == "big")
|
2006-09-16 18:11:38 +00:00
|
|
|
|
// we can't create a InsetMathBig, since the argument
|
2006-04-20 09:55:45 +00:00
|
|
|
|
// is missing.
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return MathAtom(new InsetMathUnknown(s));
|
|
|
|
|
return MathAtom(new InsetMathSymbol(l));
|
2002-07-31 17:26:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-09-12 14:31:18 +00:00
|
|
|
|
if (s.size() == 2 && s[0] == '#' && s[1] >= '1' && s[1] <= '9')
|
2001-10-12 12:02:49 +00:00
|
|
|
|
return MathAtom(new MathMacroArgument(s[1] - '0'));
|
2001-10-23 09:03:07 +00:00
|
|
|
|
if (s.size() == 3 && s[0] == '\\' && s[1] == '#'
|
|
|
|
|
&& s[2] >= '1' && s[2] <= '9')
|
2001-10-12 12:02:49 +00:00
|
|
|
|
return MathAtom(new MathMacroArgument(s[2] - '0'));
|
2004-08-13 15:06:46 +00:00
|
|
|
|
if (s == "boxed")
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return MathAtom(new InsetMathBoxed());
|
2004-08-13 13:19:58 +00:00
|
|
|
|
if (s == "fbox")
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return MathAtom(new InsetMathFBox());
|
2002-08-29 09:57:57 +00:00
|
|
|
|
if (s == "framebox")
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return MathAtom(new InsetMathFrameBox);
|
2003-05-07 07:46:04 +00:00
|
|
|
|
if (s == "makebox")
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return MathAtom(new InsetMathMakebox);
|
2002-03-27 10:51:46 +00:00
|
|
|
|
if (s == "kern")
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return MathAtom(new InsetMathKern);
|
2006-10-31 19:10:30 +00:00
|
|
|
|
if (s.substr(0, 8) == "xymatrix") {
|
|
|
|
|
char spacing_code = '\0';
|
|
|
|
|
LyXLength spacing;
|
|
|
|
|
size_t const len = s.length();
|
|
|
|
|
size_t i = 8;
|
|
|
|
|
if (i < len && s[i] == '@') {
|
|
|
|
|
++i;
|
|
|
|
|
if (i < len) {
|
|
|
|
|
switch (s[i]) {
|
|
|
|
|
case 'R':
|
|
|
|
|
case 'C':
|
|
|
|
|
case 'M':
|
|
|
|
|
case 'W':
|
|
|
|
|
case 'H':
|
|
|
|
|
case 'L':
|
2006-11-05 12:22:05 +00:00
|
|
|
|
spacing_code = static_cast<char>(s[i]);
|
2006-10-31 19:10:30 +00:00
|
|
|
|
++i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (i < len && s[i] == '=') {
|
|
|
|
|
++i;
|
|
|
|
|
spacing = LyXLength(to_ascii(s.substr(i)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return MathAtom(new InsetMathXYMatrix(spacing, spacing_code));
|
|
|
|
|
}
|
2002-02-15 15:01:01 +00:00
|
|
|
|
if (s == "xrightarrow" || s == "xleftarrow")
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return MathAtom(new InsetMathXArrow(s));
|
2004-08-14 14:03:42 +00:00
|
|
|
|
if (s == "split" || s == "gathered" || s == "aligned" || s == "alignedat")
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return MathAtom(new InsetMathSplit(s));
|
2002-02-14 14:19:52 +00:00
|
|
|
|
if (s == "cases")
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return MathAtom(new InsetMathCases);
|
2002-02-14 14:52:23 +00:00
|
|
|
|
if (s == "substack")
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return MathAtom(new InsetMathSubstack);
|
2002-02-14 14:52:23 +00:00
|
|
|
|
if (s == "subarray" || s == "array")
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return MathAtom(new InsetMathArray(s, 1, 1));
|
2002-05-30 07:09:54 +00:00
|
|
|
|
if (s == "sqrt")
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return MathAtom(new InsetMathSqrt);
|
2002-05-30 07:09:54 +00:00
|
|
|
|
if (s == "root")
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return MathAtom(new InsetMathRoot);
|
2003-03-03 16:15:38 +00:00
|
|
|
|
if (s == "tabular")
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return MathAtom(new InsetMathTabular(s, 1, 1));
|
2002-07-10 10:51:43 +00:00
|
|
|
|
if (s == "stackrel")
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return MathAtom(new InsetMathStackrel);
|
2002-05-30 07:09:54 +00:00
|
|
|
|
if (s == "binom" || s == "choose")
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return MathAtom(new InsetMathBinom(s == "choose"));
|
2006-07-19 10:50:18 +00:00
|
|
|
|
if (s == "frac")
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return MathAtom(new InsetMathFrac);
|
2006-07-19 10:50:18 +00:00
|
|
|
|
if (s == "over")
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return MathAtom(new InsetMathFrac(InsetMathFrac::OVER));
|
2006-04-06 09:46:01 +00:00
|
|
|
|
if (s == "nicefrac")
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return MathAtom(new InsetMathFrac(InsetMathFrac::NICEFRAC));
|
2002-08-28 08:30:27 +00:00
|
|
|
|
//if (s == "infer")
|
|
|
|
|
// return MathAtom(new MathInferInset);
|
2002-05-30 07:09:54 +00:00
|
|
|
|
if (s == "atop")
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return MathAtom(new InsetMathFrac(InsetMathFrac::ATOP));
|
2002-05-30 07:09:54 +00:00
|
|
|
|
if (s == "lefteqn")
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return MathAtom(new InsetMathLefteqn);
|
2003-09-12 10:14:31 +00:00
|
|
|
|
if (s == "boldsymbol")
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return MathAtom(new InsetMathBoldSymbol);
|
2005-06-17 14:35:19 +00:00
|
|
|
|
if (s == "color" || s == "normalcolor")
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return MathAtom(new InsetMathColor(true));
|
2003-10-28 08:51:33 +00:00
|
|
|
|
if (s == "textcolor")
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return MathAtom(new InsetMathColor(false));
|
2003-10-07 08:51:14 +00:00
|
|
|
|
if (s == "dfrac")
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return MathAtom(new InsetMathDFrac);
|
2004-11-11 12:01:34 +00:00
|
|
|
|
if (s == "tfrac")
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return MathAtom(new InsetMathTFrac);
|
2006-04-15 09:54:24 +00:00
|
|
|
|
if (s == "hphantom")
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return MathAtom(new InsetMathPhantom(InsetMathPhantom::hphantom));
|
2006-04-15 09:54:24 +00:00
|
|
|
|
if (s == "phantom")
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return MathAtom(new InsetMathPhantom(InsetMathPhantom::phantom));
|
2006-04-15 09:54:24 +00:00
|
|
|
|
if (s == "vphantom")
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return MathAtom(new InsetMathPhantom(InsetMathPhantom::vphantom));
|
2001-08-15 05:50:39 +00:00
|
|
|
|
|
2007-04-17 16:49:17 +00:00
|
|
|
|
if (MacroTable::globalMacros().has(s))
|
|
|
|
|
return MathAtom(new MathMacro(s,
|
|
|
|
|
MacroTable::globalMacros().get(s).numargs()));
|
|
|
|
|
//if (MacroTable::localMacros().has(s))
|
|
|
|
|
// return MathAtom(new MathMacro(s,
|
|
|
|
|
// MacroTable::localMacros().get(s).numargs()));
|
|
|
|
|
|
|
|
|
|
//lyxerr << "creating unknown inset '" << s << "'" << endl;
|
|
|
|
|
return MathAtom(new InsetMathUnknown(s));
|
2001-08-15 05:50:39 +00:00
|
|
|
|
}
|
2003-03-04 16:39:13 +00:00
|
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
bool createInsetMath_fromDialogStr(docstring const & str, MathArray & ar)
|
2003-03-04 16:39:13 +00:00
|
|
|
|
{
|
|
|
|
|
// An example str:
|
2007-04-06 08:30:37 +00:00
|
|
|
|
// "ref LatexCommand ref\nreference \"sec:Title\"\n\\end_inset\n\n";
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring name;
|
|
|
|
|
docstring body = split(str, name, ' ');
|
2003-03-04 16:39:13 +00:00
|
|
|
|
|
|
|
|
|
if (name != "ref" )
|
|
|
|
|
return false;
|
|
|
|
|
|
2007-04-06 08:30:37 +00:00
|
|
|
|
InsetCommandParams icp("ref");
|
|
|
|
|
// FIXME UNICODE
|
|
|
|
|
InsetCommandMailer::string2params("ref", to_utf8(str), icp);
|
|
|
|
|
mathed_parse_cell(ar, icp.getCommand());
|
2003-03-04 16:39:13 +00:00
|
|
|
|
if (ar.size() != 1)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return ar[0].nucleus();
|
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|