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.
|
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author André Pönitz
|
2003-08-19 13:00:56 +00:00
|
|
|
*
|
|
|
|
* 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"
|
2008-10-23 00:48:06 +00:00
|
|
|
#include "InsetMathSpecialChar.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
#include "InsetMathSplit.h"
|
|
|
|
#include "InsetMathSqrt.h"
|
|
|
|
#include "InsetMathStackrel.h"
|
|
|
|
#include "InsetMathSubstack.h"
|
|
|
|
#include "InsetMathSymbol.h"
|
|
|
|
#include "InsetMathTabular.h"
|
|
|
|
#include "InsetMathUnderset.h"
|
|
|
|
#include "InsetMathUnknown.h"
|
2008-11-16 00:18:52 +00:00
|
|
|
#include "InsetMathHull.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
#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"
|
2008-12-22 18:12:32 +00:00
|
|
|
#include "insets/InsetSpace.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
|
|
|
|
2009-11-11 01:48:07 +00:00
|
|
|
#include "Buffer.h"
|
|
|
|
#include "BufferParams.h"
|
2008-12-22 18:12:32 +00:00
|
|
|
#include "Encoding.h"
|
2008-02-07 09:12:19 +00:00
|
|
|
#include "LyX.h" // use_gui
|
2008-12-22 18:12:32 +00:00
|
|
|
#include "OutputParams.h"
|
2008-02-07 09:12:19 +00:00
|
|
|
|
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;
|
2010-03-10 16:58:20 +00:00
|
|
|
continue;
|
2002-10-21 13:38:02 +00:00
|
|
|
} 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;
|
2009-11-08 11:45:46 +00:00
|
|
|
MacroTable::globalMacros().insert(0, 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-23 19:30:51 +00:00
|
|
|
bool isSpecialChar(docstring const & name)
|
2008-10-23 00:48:06 +00:00
|
|
|
{
|
2008-10-23 19:30:51 +00:00
|
|
|
if (name.size() != 1)
|
|
|
|
return name == "textasciicircum" || name == "mathcircumflex" ||
|
|
|
|
name == "textasciitilde" || name == "textbackslash";
|
|
|
|
|
|
|
|
char_type const c = name.at(0);
|
|
|
|
return c == '{' || c == '}' || c == '&' || c == '$' ||
|
2008-10-26 18:32:25 +00:00
|
|
|
c == '#' || c == '%' || c == '_' || c == ' ';
|
2008-10-23 00:48:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-04 23:03:48 +00:00
|
|
|
int ensureMode(WriteStream & os, InsetMath::mode_type mode,
|
|
|
|
bool locked, bool ascii)
|
2008-06-17 11:10:43 +00:00
|
|
|
{
|
|
|
|
bool textmode = mode == InsetMath::TEXT_MODE;
|
|
|
|
if (os.latex() && textmode && os.pendingBrace()) {
|
|
|
|
os.os() << '}';
|
|
|
|
os.pendingBrace(false);
|
|
|
|
os.pendingSpace(false);
|
|
|
|
os.textMode(true);
|
|
|
|
}
|
2010-02-04 23:03:48 +00:00
|
|
|
int oldmodes = os.textMode() ? 0x01 : 0;
|
2008-06-17 11:10:43 +00:00
|
|
|
os.textMode(textmode);
|
2010-02-04 23:03:48 +00:00
|
|
|
oldmodes |= os.lockedMode() ? 0x02 : 0;
|
2009-07-03 00:05:58 +00:00
|
|
|
os.lockedMode(locked);
|
2010-02-04 23:03:48 +00:00
|
|
|
oldmodes |= os.asciiOnly() ? 0x04 : 0;
|
|
|
|
os.asciiOnly(ascii);
|
2009-07-03 00:05:58 +00:00
|
|
|
return oldmodes;
|
2008-06-17 11:10:43 +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
|
|
|
{
|
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
|
|
|
|
|
|
|
|
2009-11-08 11:45:46 +00:00
|
|
|
MathAtom createInsetMath(char const * const s, Buffer * buf)
|
2006-10-22 10:15:23 +00:00
|
|
|
{
|
2009-11-08 11:45:46 +00:00
|
|
|
return createInsetMath(from_utf8(s), buf);
|
2006-10-22 10:15:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-08 11:45:46 +00:00
|
|
|
MathAtom createInsetMath(docstring const & s, Buffer * buf)
|
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;
|
2009-11-11 01:48:07 +00:00
|
|
|
if ((s == "ce" || s == "cf") && buf
|
|
|
|
&& buf->params().use_mhchem == BufferParams::package_off)
|
|
|
|
return MathAtom(new MathMacro(buf, s));
|
|
|
|
|
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")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathRef(buf, l->name));
|
2003-08-22 16:01:13 +00:00
|
|
|
if (inset == "overset")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathOverset(buf));
|
2002-07-31 17:26:14 +00:00
|
|
|
if (inset == "underset")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathUnderset(buf));
|
2002-07-31 17:26:14 +00:00
|
|
|
if (inset == "decoration")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathDecoration(buf, l));
|
2002-07-31 17:26:14 +00:00
|
|
|
if (inset == "space")
|
2008-12-22 18:12:32 +00:00
|
|
|
return MathAtom(new InsetMathSpace(to_ascii(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)
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathBox(buf, 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")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathSize(buf, l));
|
2002-07-31 17:26:14 +00:00
|
|
|
if (inset == "font")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathFont(buf, l));
|
2002-07-31 17:26:14 +00:00
|
|
|
if (inset == "oldfont")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathFontOld(buf, l));
|
2002-07-31 17:26:14 +00:00
|
|
|
if (inset == "matrix")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathAMSArray(buf, s));
|
2006-10-03 19:45:43 +00:00
|
|
|
if (inset == "split")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathSplit(buf, 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")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathBoxed(buf));
|
2004-08-13 13:19:58 +00:00
|
|
|
if (s == "fbox")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathFBox(buf));
|
2002-08-29 09:57:57 +00:00
|
|
|
if (s == "framebox")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathMakebox(buf, true));
|
2003-05-07 07:46:04 +00:00
|
|
|
if (s == "makebox")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathMakebox(buf, 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;
|
2009-12-13 21:32:08 +00:00
|
|
|
bool equal_spacing = false;
|
2006-10-31 19:10:30 +00:00
|
|
|
size_t const len = s.length();
|
|
|
|
size_t i = 8;
|
|
|
|
if (i < len && s[i] == '@') {
|
|
|
|
++i;
|
2009-12-13 21:32:08 +00:00
|
|
|
if (i < len && s[i] == '!') {
|
|
|
|
equal_spacing = true;
|
|
|
|
++i;
|
|
|
|
if (i < len) {
|
|
|
|
switch (s[i]) {
|
|
|
|
case '0':
|
|
|
|
case 'R':
|
|
|
|
case 'C':
|
|
|
|
spacing_code = static_cast<char>(s[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (i < len) {
|
2006-10-31 19:10:30 +00:00
|
|
|
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;
|
|
|
|
}
|
2009-12-13 21:32:08 +00:00
|
|
|
if (i < len && s[i] == '=') {
|
|
|
|
++i;
|
|
|
|
spacing = Length(to_ascii(s.substr(i)));
|
|
|
|
}
|
2006-10-31 19:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
2009-12-13 21:32:08 +00:00
|
|
|
return MathAtom(new InsetMathXYMatrix(buf, spacing, spacing_code,
|
|
|
|
equal_spacing));
|
2006-10-31 19:10:30 +00:00
|
|
|
}
|
2002-02-15 15:01:01 +00:00
|
|
|
if (s == "xrightarrow" || s == "xleftarrow")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathXArrow(buf, s));
|
2009-12-31 22:31:12 +00:00
|
|
|
if (s == "split" || s == "alignedat")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathSplit(buf, s));
|
2002-02-14 14:19:52 +00:00
|
|
|
if (s == "cases")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathCases(buf));
|
2002-02-14 14:52:23 +00:00
|
|
|
if (s == "substack")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathSubstack(buf));
|
2002-02-14 14:52:23 +00:00
|
|
|
if (s == "subarray" || s == "array")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathArray(buf, s, 1, 1));
|
2002-05-30 07:09:54 +00:00
|
|
|
if (s == "sqrt")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathSqrt(buf));
|
2002-05-30 07:09:54 +00:00
|
|
|
if (s == "root")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathRoot(buf));
|
2003-03-03 16:15:38 +00:00
|
|
|
if (s == "tabular")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathTabular(buf, s, 1, 1));
|
2002-07-10 10:51:43 +00:00
|
|
|
if (s == "stackrel")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathStackrel(buf));
|
2008-03-31 01:23:25 +00:00
|
|
|
if (s == "binom")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathBinom(buf, InsetMathBinom::BINOM));
|
2009-04-05 19:52:53 +00:00
|
|
|
if (s == "dbinom")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathBinom(buf, InsetMathBinom::DBINOM));
|
2009-04-05 19:52:53 +00:00
|
|
|
if (s == "tbinom")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathBinom(buf, InsetMathBinom::TBINOM));
|
2008-03-31 01:23:25 +00:00
|
|
|
if (s == "choose")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathBinom(buf, InsetMathBinom::CHOOSE));
|
2008-03-31 01:23:25 +00:00
|
|
|
if (s == "brace")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathBinom(buf, InsetMathBinom::BRACE));
|
2008-03-31 01:23:25 +00:00
|
|
|
if (s == "brack")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathBinom(buf, InsetMathBinom::BRACK));
|
2006-07-19 10:50:18 +00:00
|
|
|
if (s == "frac")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathFrac(buf));
|
2009-04-05 19:52:53 +00:00
|
|
|
if (s == "cfrac")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathFrac(buf, InsetMathFrac::CFRAC));
|
2009-04-05 19:52:53 +00:00
|
|
|
if (s == "dfrac")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathFrac(buf, InsetMathFrac::DFRAC));
|
2009-04-05 19:52:53 +00:00
|
|
|
if (s == "tfrac")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathFrac(buf, InsetMathFrac::TFRAC));
|
2006-07-19 10:50:18 +00:00
|
|
|
if (s == "over")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathFrac(buf, InsetMathFrac::OVER));
|
2006-04-06 09:46:01 +00:00
|
|
|
if (s == "nicefrac")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathFrac(buf, InsetMathFrac::NICEFRAC));
|
2007-09-12 08:15:33 +00:00
|
|
|
if (s == "unitfrac")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathFrac(buf, InsetMathFrac::UNITFRAC));
|
2009-04-05 19:52:53 +00:00
|
|
|
// These string values are only for math toolbar use, no LaTeX names
|
2007-09-15 16:39:51 +00:00
|
|
|
if (s == "unitfracthree")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathFrac(buf, InsetMathFrac::UNITFRAC, 3));
|
2007-09-18 15:04:58 +00:00
|
|
|
if (s == "unitone")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathFrac(buf, InsetMathFrac::UNIT, 1));
|
2007-10-01 12:43:40 +00:00
|
|
|
if (s == "unittwo")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathFrac(buf, InsetMathFrac::UNIT));
|
2009-04-06 23:58:42 +00:00
|
|
|
if (s == "cfracleft")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathFrac(buf, InsetMathFrac::CFRACLEFT));
|
2009-04-06 23:58:42 +00:00
|
|
|
if (s == "cfracright")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathFrac(buf, InsetMathFrac::CFRACRIGHT));
|
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")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathFrac(buf, InsetMathFrac::ATOP));
|
2002-05-30 07:09:54 +00:00
|
|
|
if (s == "lefteqn")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathLefteqn(buf));
|
2008-04-01 02:29:41 +00:00
|
|
|
if (s == "boldsymbol")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathBoldSymbol(buf, InsetMathBoldSymbol::AMS_BOLD));
|
2008-04-01 02:29:41 +00:00
|
|
|
if (s == "bm")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathBoldSymbol(buf, InsetMathBoldSymbol::BM_BOLD));
|
2008-03-12 14:33:16 +00:00
|
|
|
if (s == "heavysymbol" || s == "hm")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathBoldSymbol(buf, InsetMathBoldSymbol::BM_HEAVY));
|
2005-06-17 14:35:19 +00:00
|
|
|
if (s == "color" || s == "normalcolor")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathColor(buf, true));
|
2003-10-28 08:51:33 +00:00
|
|
|
if (s == "textcolor")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathColor(buf, false));
|
2006-04-15 09:54:24 +00:00
|
|
|
if (s == "hphantom")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathPhantom(buf, InsetMathPhantom::hphantom));
|
2006-04-15 09:54:24 +00:00
|
|
|
if (s == "phantom")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathPhantom(buf, InsetMathPhantom::phantom));
|
2006-04-15 09:54:24 +00:00
|
|
|
if (s == "vphantom")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathPhantom(buf, InsetMathPhantom::vphantom));
|
2008-09-04 22:24:07 +00:00
|
|
|
if (s == "ensuremath")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathEnsureMath(buf));
|
2008-10-23 00:48:06 +00:00
|
|
|
if (isSpecialChar(s))
|
|
|
|
return MathAtom(new InsetMathSpecialChar(s));
|
2001-08-15 05:50:39 +00:00
|
|
|
|
2008-11-16 00:18:52 +00:00
|
|
|
if (s == "regexp")
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new InsetMathHull(buf, hullRegexp));
|
2008-11-16 00:18:52 +00:00
|
|
|
|
2009-11-08 11:45:46 +00:00
|
|
|
return MathAtom(new MathMacro(buf, 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
|
|
|
|
2008-12-22 18:12:32 +00:00
|
|
|
if (name == "ref") {
|
|
|
|
InsetCommandParams icp(REF_CODE);
|
|
|
|
// FIXME UNICODE
|
|
|
|
InsetCommand::string2params("ref", to_utf8(str), icp);
|
2010-02-13 13:08:32 +00:00
|
|
|
Encoding const * const utf8 = encodings.fromLyXName("utf8");
|
|
|
|
OutputParams op(utf8);
|
|
|
|
mathed_parse_cell(ar, icp.getCommand(op));
|
2008-12-22 18:12:32 +00:00
|
|
|
} else if (name == "mathspace") {
|
|
|
|
InsetSpaceParams isp(true);
|
|
|
|
InsetSpace::string2params(to_utf8(str), isp);
|
|
|
|
InsetSpace is(isp);
|
|
|
|
odocstringstream os;
|
|
|
|
Encoding const * const ascii = encodings.fromLyXName("ascii");
|
|
|
|
OutputParams op(ascii);
|
|
|
|
is.latex(os, op);
|
|
|
|
mathed_parse_cell(ar, os.str());
|
|
|
|
if (ar.size() == 2) {
|
|
|
|
// remove "{}"
|
|
|
|
if (ar[1].nucleus()->asBraceInset())
|
|
|
|
ar.pop_back();
|
|
|
|
}
|
|
|
|
} else
|
2003-03-04 16:39:13 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (ar.size() != 1)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return ar[0].nucleus();
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
2009-04-06 22:12:22 +00:00
|
|
|
bool isAsciiOrMathAlpha(char_type c)
|
|
|
|
{
|
|
|
|
return c < 0x80 || Encodings::isMathAlpha(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|