2003-08-19 13:00:56 +00:00
|
|
|
|
/**
|
2007-04-25 03:01:35 +00:00
|
|
|
|
* \file MathFactory.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-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 "InsetMathBoldSymbol.h"
|
2006-09-17 10:00:15 +00:00
|
|
|
|
#include "InsetMathBox.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "InsetMathCases.h"
|
|
|
|
|
#include "InsetMathColor.h"
|
|
|
|
|
#include "InsetMathDecoration.h"
|
|
|
|
|
#include "InsetMathDots.h"
|
2008-09-04 22:24:07 +00:00
|
|
|
|
#include "InsetMathEnsureMath.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "InsetMathFont.h"
|
|
|
|
|
#include "InsetMathFontOld.h"
|
|
|
|
|
#include "InsetMathFrac.h"
|
|
|
|
|
#include "InsetMathKern.h"
|
|
|
|
|
#include "InsetMathLefteqn.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 "InsetMathUnderset.h"
|
|
|
|
|
#include "InsetMathUnknown.h"
|
|
|
|
|
#include "InsetMathXArrow.h"
|
|
|
|
|
#include "InsetMathXYMatrix.h"
|
2007-04-28 20:44:46 +00:00
|
|
|
|
#include "MacroTable.h"
|
2007-11-01 11:27:02 +00:00
|
|
|
|
#include "MathMacro.h"
|
|
|
|
|
#include "MathMacroArgument.h"
|
2006-09-17 10:00:15 +00:00
|
|
|
|
#include "MathParser.h"
|
2008-06-17 11:10:43 +00:00
|
|
|
|
#include "MathStream.h"
|
2006-09-17 10:00:15 +00:00
|
|
|
|
#include "MathSupport.h"
|
2002-06-24 15:51:35 +00:00
|
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
|
#include "insets/InsetCommand.h"
|
2007-04-06 08:30:37 +00:00
|
|
|
|
|
2008-02-18 07:14:42 +00:00
|
|
|
|
#include "support/debug.h"
|
2007-11-05 22:54:53 +00:00
|
|
|
|
#include "support/docstream.h"
|
2007-12-17 16:04:46 +00:00
|
|
|
|
#include "support/FileName.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
|
|
|
|
|
2008-02-07 09:12:19 +00:00
|
|
|
|
#include "LyX.h" // use_gui
|
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
|
using namespace std;
|
2007-12-12 18:57:56 +00:00
|
|
|
|
using namespace lyx::support;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
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 {
|
|
|
|
|
|
2008-02-23 18:11:35 +00:00
|
|
|
|
MathWordList theWordList;
|
2002-05-30 07:09:54 +00:00
|
|
|
|
|
|
|
|
|
|
2008-02-27 23:11:50 +00:00
|
|
|
|
bool isMathFontAvailable(docstring & name)
|
2002-06-18 15:44:30 +00:00
|
|
|
|
{
|
2008-10-22 09:11:42 +00:00
|
|
|
|
if (!use_gui)
|
|
|
|
|
return false;
|
|
|
|
|
|
2007-10-28 18:51:54 +00:00
|
|
|
|
FontInfo f;
|
2002-06-18 15:44:30 +00:00
|
|
|
|
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-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::MATHED,
|
|
|
|
|
"font " << to_utf8(name) << " not available and I can't fake it");
|
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
|
|
|
|
{
|
2007-12-12 19:57:42 +00:00
|
|
|
|
FileName const filename = libFileSearch(string(), "symbols");
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::MATHED, "read symbols from " << filename);
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
|
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);
|
2008-02-27 23:11:50 +00:00
|
|
|
|
skip = !isMathFontAvailable(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-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::MATHED, "skipping line '" << line << "'\n"
|
|
|
|
|
<< to_utf8(tmp.name) << ' ' << to_utf8(tmp.inset) << ' '
|
|
|
|
|
<< to_utf8(tmp.extra));
|
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
|
2007-06-22 21:25:41 +00:00
|
|
|
|
if (tmp.requires.empty()) {
|
|
|
|
|
if (tmp.inset == "msa" || tmp.inset == "msb")
|
|
|
|
|
tmp.requires = from_ascii("amssymb");
|
|
|
|
|
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-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::MATHED, "symbol abuse for " << to_utf8(tmp.name));
|
2006-10-22 10:15:23 +00:00
|
|
|
|
tmp.draw = tmp.name;
|
2008-02-27 23:11:50 +00:00
|
|
|
|
} else if (isMathFontAvailable(tmp.inset)) {
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::MATHED, "symbol available for " << to_utf8(tmp.name));
|
2006-10-21 11:15:37 +00:00
|
|
|
|
tmp.draw.push_back(char_type(charid));
|
2008-02-27 23:11:50 +00:00
|
|
|
|
} else if (fallbackid && isMathFontAvailable(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-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::MATHED, "symbol fallback for " << to_utf8(tmp.name));
|
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-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::MATHED, "faking " << to_utf8(tmp.name));
|
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-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::MATHED, "inset " << to_utf8(tmp.inset)
|
|
|
|
|
<< " used for " << to_utf8(tmp.name));
|
2002-05-30 07:09:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (theWordList.find(tmp.name) != theWordList.end())
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::MATHED, "readSymbols: inset " << to_utf8(tmp.name)
|
|
|
|
|
<< " already exists.");
|
2002-05-30 07:09:54 +00:00
|
|
|
|
else
|
|
|
|
|
theWordList[tmp.name] = tmp;
|
2002-11-04 02:12:42 +00:00
|
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::MATHED, "read symbol '" << to_utf8(tmp.name)
|
2006-10-22 10:15:23 +00:00
|
|
|
|
<< " 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)
|
2007-11-15 20:04:51 +00:00
|
|
|
|
<< " requires: " << to_utf8(tmp.requires) << '\'');
|
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");
|
2008-02-27 23:11:50 +00:00
|
|
|
|
has_math_fonts = isMathFontAvailable(tmp) && isMathFontAvailable(tmp2);
|
2002-05-30 07:09:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
2008-02-23 18:11:35 +00:00
|
|
|
|
MathWordList const & mathedWordList()
|
2008-02-21 19:42:34 +00:00
|
|
|
|
{
|
|
|
|
|
return theWordList;
|
|
|
|
|
}
|
|
|
|
|
|
2002-05-30 07:09:54 +00:00
|
|
|
|
|
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
|
|
|
|
|
2008-06-17 11:10:43 +00:00
|
|
|
|
bool ensureMath(WriteStream & os, bool needs_math_mode, bool macro)
|
|
|
|
|
{
|
|
|
|
|
bool brace = os.pendingBrace();
|
|
|
|
|
os.pendingBrace(false);
|
|
|
|
|
if (!os.latex())
|
|
|
|
|
return brace;
|
|
|
|
|
if (os.textMode() && needs_math_mode) {
|
|
|
|
|
os << "\\ensuremath{";
|
|
|
|
|
os.textMode(false);
|
|
|
|
|
brace = true;
|
|
|
|
|
} else if (macro && brace && !needs_math_mode) {
|
|
|
|
|
// This is a user defined macro, but not a MathMacro, so we
|
|
|
|
|
// cannot be sure what mode is needed. As it was entered in
|
|
|
|
|
// a text box, we restore the text mode.
|
|
|
|
|
os << '}';
|
|
|
|
|
os.textMode(true);
|
|
|
|
|
brace = false;
|
|
|
|
|
}
|
|
|
|
|
return brace;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool ensureMode(WriteStream & os, InsetMath::mode_type mode)
|
|
|
|
|
{
|
|
|
|
|
bool textmode = mode == InsetMath::TEXT_MODE;
|
|
|
|
|
if (os.latex() && textmode && os.pendingBrace()) {
|
|
|
|
|
os.os() << '}';
|
|
|
|
|
os.pendingBrace(false);
|
|
|
|
|
os.pendingSpace(false);
|
|
|
|
|
os.textMode(true);
|
|
|
|
|
}
|
|
|
|
|
bool oldmode = os.textMode();
|
|
|
|
|
os.textMode(textmode);
|
|
|
|
|
return oldmode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
latexkeys const * in_word_set(docstring const & str)
|
2002-07-12 14:24:47 +00:00
|
|
|
|
{
|
2008-02-23 18:11:35 +00:00
|
|
|
|
MathWordList::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
|
|
|
|
{
|
2007-09-18 15:06:32 +00:00
|
|
|
|
//lyxerr << "creating inset with name: '" << to_utf8(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")
|
2007-04-28 20:49:56 +00:00
|
|
|
|
return MathAtom(new InsetMathRef(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")
|
2008-02-28 12:46:32 +00:00
|
|
|
|
return MathAtom(new InsetMathMakebox(true));
|
2003-05-07 07:46:04 +00:00
|
|
|
|
if (s == "makebox")
|
2008-02-28 12:46:32 +00:00
|
|
|
|
return MathAtom(new InsetMathMakebox(false));
|
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';
|
2007-04-28 12:58:49 +00:00
|
|
|
|
Length spacing;
|
2006-10-31 19:10:30 +00:00
|
|
|
|
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;
|
2007-04-28 12:58:49 +00:00
|
|
|
|
spacing = Length(to_ascii(s.substr(i)));
|
2006-10-31 19:10:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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);
|
2008-03-31 01:23:25 +00:00
|
|
|
|
if (s == "binom")
|
|
|
|
|
return MathAtom(new InsetMathBinom(InsetMathBinom::BINOM));
|
|
|
|
|
if (s == "choose")
|
|
|
|
|
return MathAtom(new InsetMathBinom(InsetMathBinom::CHOOSE));
|
|
|
|
|
if (s == "brace")
|
|
|
|
|
return MathAtom(new InsetMathBinom(InsetMathBinom::BRACE));
|
|
|
|
|
if (s == "brack")
|
|
|
|
|
return MathAtom(new InsetMathBinom(InsetMathBinom::BRACK));
|
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));
|
2007-09-12 08:15:33 +00:00
|
|
|
|
if (s == "unitfrac")
|
|
|
|
|
return MathAtom(new InsetMathFrac(InsetMathFrac::UNITFRAC));
|
2007-09-18 15:04:58 +00:00
|
|
|
|
// This string value is only for math toolbar use. Not a LaTeX name
|
2007-09-15 16:39:51 +00:00
|
|
|
|
if (s == "unitfracthree")
|
2007-09-18 15:04:58 +00:00
|
|
|
|
return MathAtom(new InsetMathFrac(InsetMathFrac::UNITFRAC, 3));
|
|
|
|
|
if (s == "unitone")
|
|
|
|
|
return MathAtom(new InsetMathFrac(InsetMathFrac::UNIT, 1));
|
2007-10-01 12:43:40 +00:00
|
|
|
|
if (s == "unittwo")
|
2007-09-15 16:39:51 +00:00
|
|
|
|
return MathAtom(new InsetMathFrac(InsetMathFrac::UNIT));
|
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);
|
2008-04-01 02:29:41 +00:00
|
|
|
|
if (s == "boldsymbol")
|
|
|
|
|
return MathAtom(new InsetMathBoldSymbol(InsetMathBoldSymbol::AMS_BOLD));
|
|
|
|
|
if (s == "bm")
|
|
|
|
|
return MathAtom(new InsetMathBoldSymbol(InsetMathBoldSymbol::BM_BOLD));
|
2008-03-12 14:33:16 +00:00
|
|
|
|
if (s == "heavysymbol" || s == "hm")
|
2008-04-01 02:29:41 +00:00
|
|
|
|
return MathAtom(new InsetMathBoldSymbol(InsetMathBoldSymbol::BM_HEAVY));
|
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);
|
2007-10-28 21:48:51 +00:00
|
|
|
|
if (s == "dbinom")
|
|
|
|
|
return MathAtom(new InsetMathDBinom);
|
|
|
|
|
if (s == "tbinom")
|
|
|
|
|
return MathAtom(new InsetMathTBinom);
|
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));
|
2008-09-04 22:24:07 +00:00
|
|
|
|
if (s == "ensuremath")
|
|
|
|
|
return MathAtom(new InsetMathEnsureMath);
|
2001-08-15 05:50:39 +00:00
|
|
|
|
|
2007-11-01 11:13:07 +00:00
|
|
|
|
return MathAtom(new MathMacro(s));
|
2001-08-15 05:50:39 +00:00
|
|
|
|
}
|
2003-03-04 16:39:13 +00:00
|
|
|
|
|
|
|
|
|
|
2007-04-26 16:05:57 +00:00
|
|
|
|
bool createInsetMath_fromDialogStr(docstring const & str, MathData & 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-10-19 17:22:55 +00:00
|
|
|
|
InsetCommandParams icp(REF_CODE);
|
2007-04-06 08:30:37 +00:00
|
|
|
|
// FIXME UNICODE
|
2008-03-27 22:26:24 +00:00
|
|
|
|
InsetCommand::string2params("ref", to_utf8(str), icp);
|
2007-04-06 08:30:37 +00:00
|
|
|
|
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
|