1999-09-27 18:44:28 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/*
|
|
|
|
* File: math_defs.h
|
|
|
|
* Purpose: Math editor definitions
|
|
|
|
* Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
|
|
|
|
* Created: January 1996
|
|
|
|
* Description: Math paragraph and objects for a WYSIWYG math editor.
|
|
|
|
*
|
|
|
|
* Dependencies: Xlib
|
|
|
|
*
|
2000-03-09 03:36:48 +00:00
|
|
|
* Copyright: 1996, 1997 Alejandro Aguilar Sierra
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
|
|
|
* Version: 0.8beta, Mathed & Lyx project.
|
|
|
|
*
|
|
|
|
* You are free to use and modify this code under the terms of
|
|
|
|
* the GNU General Public Licence version 2 or later.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
#ifndef MATH_DEFS
|
|
|
|
#define MATH_DEFS
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma interface
|
|
|
|
#endif
|
|
|
|
|
2000-03-28 02:18:55 +00:00
|
|
|
#include <iosfwd>
|
2000-01-10 16:28:29 +00:00
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
#include "LString.h"
|
1999-10-13 10:34:07 +00:00
|
|
|
#include "debug.h"
|
1999-10-02 16:21:10 +00:00
|
|
|
|
2001-02-13 13:28:32 +00:00
|
|
|
//#include "array.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-02-13 13:28:32 +00:00
|
|
|
class MathedArray;
|
2000-02-10 17:53:36 +00:00
|
|
|
class Painter;
|
|
|
|
|
2001-02-13 13:28:32 +00:00
|
|
|
#ifndef byte
|
|
|
|
#define byte unsigned char
|
|
|
|
#endif
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-11-22 16:19:48 +00:00
|
|
|
enum math_align {
|
|
|
|
///
|
|
|
|
MATH_ALIGN_LEFT = 1,
|
|
|
|
///
|
|
|
|
MATH_ALIGN_RIGHT = 2,
|
|
|
|
///
|
|
|
|
MATH_ALIGN_BOTTOM = 4,
|
|
|
|
///
|
|
|
|
MATH_ALIGN_TOP = 8
|
|
|
|
};
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2000-09-29 18:44:07 +00:00
|
|
|
static int const MATH_COLSEP = 8;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2000-09-29 18:44:07 +00:00
|
|
|
static int const MATH_ROWSEP = 8;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
/// Standard Math Sizes (Math mode styles)
|
|
|
|
enum MathedStyles {
|
|
|
|
///
|
1999-12-07 00:44:53 +00:00
|
|
|
LM_ST_DISPLAY = 0,
|
|
|
|
///
|
|
|
|
LM_ST_TEXT,
|
|
|
|
///
|
|
|
|
LM_ST_SCRIPT,
|
|
|
|
///
|
|
|
|
LM_ST_SCRIPTSCRIPT
|
1999-09-27 18:44:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/** The restrictions of a standard LaTeX math paragraph
|
|
|
|
allows to get a small number of text codes (<30) */
|
|
|
|
enum MathedTextCodes {
|
1999-12-07 00:44:53 +00:00
|
|
|
/// This must be >= 0
|
|
|
|
LM_TC_MIN = 0,
|
|
|
|
/// Open and Close group
|
|
|
|
LM_TC_OPEN,
|
|
|
|
///
|
|
|
|
LM_TC_CLOSE,
|
|
|
|
/// Tabulator
|
|
|
|
LM_TC_TAB,
|
|
|
|
/// New line
|
|
|
|
LM_TC_CR,
|
|
|
|
/// Math Inset
|
|
|
|
LM_TC_INSET,
|
|
|
|
/// Super and sub scripts
|
|
|
|
LM_TC_UP,
|
|
|
|
///
|
|
|
|
LM_TC_DOWN,
|
|
|
|
/// Editable Math Inset
|
|
|
|
LM_TC_ACTIVE_INSET,
|
|
|
|
/// Editable Text Inset
|
|
|
|
LM_TC_TEXT_INSET,
|
|
|
|
///
|
|
|
|
LM_FONT_BEGIN,
|
|
|
|
/// Internal code for constants
|
|
|
|
LM_TC_CONST,
|
|
|
|
/// Internal code for variables
|
|
|
|
LM_TC_VAR,
|
|
|
|
///
|
|
|
|
LM_TC_RM,
|
|
|
|
///
|
|
|
|
LM_TC_CAL,
|
|
|
|
///
|
|
|
|
LM_TC_BF,
|
|
|
|
///
|
|
|
|
LM_TC_SF,
|
|
|
|
///
|
|
|
|
LM_TC_TT,
|
|
|
|
///
|
|
|
|
LM_TC_IT,
|
|
|
|
///
|
|
|
|
LM_TC_TEXTRM,
|
|
|
|
/// Math mode TeX characters ",;:{}"
|
|
|
|
LM_TC_TEX,
|
|
|
|
/// Special characters "{}&#_%"
|
|
|
|
LM_TC_SPECIAL,
|
|
|
|
/// Internal code for operators
|
|
|
|
LM_TC_BOP,
|
|
|
|
/// Internal code for symbols
|
|
|
|
LM_TC_SYMB,
|
|
|
|
///
|
|
|
|
LM_TC_BOPS,
|
|
|
|
///
|
|
|
|
LM_TC_BSYM,
|
|
|
|
///
|
|
|
|
LM_FONT_END,
|
|
|
|
|
|
|
|
/// This must be < 32
|
|
|
|
LM_TC_MAX
|
1999-09-27 18:44:28 +00:00
|
|
|
};
|
|
|
|
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
2000-04-04 00:19:15 +00:00
|
|
|
std::ostream & operator<<(std::ostream &, MathedTextCodes mtc);
|
1999-10-07 18:44:17 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
#define LM_TC_NORMAL LM_TC_VAR
|
|
|
|
|
|
|
|
|
|
|
|
/// Types of lyx-math insets
|
|
|
|
enum MathedInsetTypes {
|
1999-12-07 00:44:53 +00:00
|
|
|
///
|
|
|
|
LM_OT_MIN = 0,
|
|
|
|
/// A simple paragraph
|
|
|
|
LM_OT_PAR,
|
|
|
|
/// A simple numbered paragraph
|
|
|
|
LM_OT_PARN,
|
|
|
|
/// A multiline paragraph
|
|
|
|
LM_OT_MPAR,
|
|
|
|
/// A multiline numbered paragraph
|
|
|
|
LM_OT_MPARN,
|
2001-02-03 21:02:22 +00:00
|
|
|
///
|
2001-02-11 09:58:20 +00:00
|
|
|
LM_OT_ALIGN,
|
|
|
|
///
|
|
|
|
LM_OT_ALIGNN,
|
|
|
|
///
|
2001-02-03 21:02:22 +00:00
|
|
|
LM_OT_ALIGNAT,
|
|
|
|
///
|
|
|
|
LM_OT_ALIGNATN,
|
|
|
|
///
|
|
|
|
LM_OT_MULTLINE,
|
|
|
|
///
|
|
|
|
LM_OT_MULTLINEN,
|
1999-12-07 00:44:53 +00:00
|
|
|
/// An array
|
|
|
|
LM_OT_MATRIX,
|
2001-02-03 21:02:22 +00:00
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
/// A big operator
|
|
|
|
LM_OT_BIGOP,
|
|
|
|
/// A LaTeX macro
|
|
|
|
LM_OT_UNDEF,
|
|
|
|
///
|
|
|
|
LM_OT_FUNC,
|
|
|
|
///
|
|
|
|
LM_OT_FUNCLIM,
|
|
|
|
///
|
|
|
|
LM_OT_SCRIPT,
|
|
|
|
///
|
|
|
|
LM_OT_SPACE,
|
|
|
|
///
|
|
|
|
LM_OT_DOTS,
|
|
|
|
/// A fraction
|
|
|
|
LM_OT_FRAC,
|
|
|
|
///
|
|
|
|
LM_OT_ATOP,
|
|
|
|
///
|
|
|
|
LM_OT_STACKREL,
|
|
|
|
/// A radical
|
|
|
|
LM_OT_SQRT,
|
|
|
|
/// A delimiter
|
|
|
|
LM_OT_DELIM,
|
|
|
|
/// A decoration
|
|
|
|
LM_OT_DECO,
|
|
|
|
/// An accent
|
|
|
|
LM_OT_ACCENT,
|
|
|
|
///
|
|
|
|
LM_OT_MACRO,
|
|
|
|
///
|
|
|
|
LM_OT_MACRO_ARG,
|
|
|
|
///
|
|
|
|
LM_OT_MAX
|
1999-09-27 18:44:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
///
|
|
|
|
enum MathedBinaryTypes {
|
|
|
|
///
|
1999-12-07 00:44:53 +00:00
|
|
|
LMB_NONE = 0,
|
|
|
|
///
|
|
|
|
LMB_RELATION,
|
|
|
|
///
|
|
|
|
LMB_OPERATOR,
|
|
|
|
///
|
|
|
|
LMB_BOP = (LMB_RELATION | LMB_OPERATOR)
|
1999-09-27 18:44:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class MathParInset;
|
|
|
|
|
|
|
|
|
|
|
|
/// Paragraph permissions
|
|
|
|
enum MathedParFlag {
|
1999-12-07 00:44:53 +00:00
|
|
|
LMPF_BASIC = 0,
|
|
|
|
/// If false can use a non-standard size
|
|
|
|
LMPF_FIXED_SIZE = 1,
|
|
|
|
/// If true can insert newlines
|
|
|
|
LMPF_ALLOW_CR = 2,
|
|
|
|
/// If true can use tabs
|
|
|
|
LMPF_ALLOW_TAB = 4,
|
|
|
|
/// If true can insert new columns
|
|
|
|
LMPF_ALLOW_NEW_COL = 8,
|
|
|
|
/// Smaller than current size (frac)
|
|
|
|
LMPF_SMALLER = 16,
|
|
|
|
/// Script size (subscript, stackrel)
|
|
|
|
LMPF_SCRIPT = 32
|
1999-09-27 18:44:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/************************* Prototypes **********************************/
|
|
|
|
///
|
2001-02-12 08:55:14 +00:00
|
|
|
MathedArray * mathed_parse(unsigned flags, MathedArray * data,
|
1999-11-22 16:19:48 +00:00
|
|
|
MathParInset ** mt);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2000-04-19 01:42:55 +00:00
|
|
|
void mathed_write(MathParInset *, std::ostream &, int *, bool fragile,
|
2000-09-14 17:53:12 +00:00
|
|
|
string const & label = string());
|
2000-01-06 02:44:26 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2000-04-04 00:19:15 +00:00
|
|
|
void mathed_parser_file(std::istream &, int);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
int mathed_parser_lineno();
|
|
|
|
///
|
|
|
|
int MathedLookupBOP(short);
|
|
|
|
|
|
|
|
/************************ Inline functions ********************************/
|
2000-07-15 23:51:46 +00:00
|
|
|
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
2000-03-07 01:14:37 +00:00
|
|
|
inline
|
|
|
|
bool MathIsInset(short x)
|
1999-11-22 16:19:48 +00:00
|
|
|
{
|
|
|
|
return LM_TC_INSET <= x && x <= LM_TC_ACTIVE_INSET;
|
|
|
|
}
|
|
|
|
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
2000-03-07 01:14:37 +00:00
|
|
|
inline
|
|
|
|
bool MathIsFont(short x)
|
1999-11-22 16:19:48 +00:00
|
|
|
{
|
|
|
|
return LM_TC_CONST <= x && x <= LM_TC_BSYM;
|
|
|
|
}
|
|
|
|
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
2000-03-07 01:14:37 +00:00
|
|
|
inline
|
|
|
|
bool MathIsAlphaFont(short x)
|
1999-11-22 16:19:48 +00:00
|
|
|
{
|
|
|
|
return LM_TC_VAR <= x && x <= LM_TC_TEXTRM;
|
|
|
|
}
|
|
|
|
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
2000-03-07 01:14:37 +00:00
|
|
|
inline
|
|
|
|
bool MathIsActive(short x)
|
1999-11-22 16:19:48 +00:00
|
|
|
{
|
|
|
|
return LM_TC_INSET < x && x <= LM_TC_ACTIVE_INSET;
|
|
|
|
}
|
|
|
|
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
2000-03-07 01:14:37 +00:00
|
|
|
inline
|
|
|
|
bool MathIsUp(short x)
|
1999-11-22 16:19:48 +00:00
|
|
|
{
|
|
|
|
return x == LM_TC_UP;
|
|
|
|
}
|
|
|
|
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
2000-03-07 01:14:37 +00:00
|
|
|
inline
|
|
|
|
bool MathIsDown(short x)
|
1999-11-22 16:19:48 +00:00
|
|
|
{
|
|
|
|
return x == LM_TC_DOWN;
|
|
|
|
}
|
|
|
|
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
2000-03-07 01:14:37 +00:00
|
|
|
inline
|
|
|
|
bool MathIsScript(short x)
|
1999-11-22 16:19:48 +00:00
|
|
|
{
|
|
|
|
return x == LM_TC_DOWN || x == LM_TC_UP;
|
|
|
|
}
|
|
|
|
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
2000-03-07 01:14:37 +00:00
|
|
|
inline
|
|
|
|
bool MathIsBOPS(short x)
|
1999-11-22 16:19:48 +00:00
|
|
|
{
|
|
|
|
return MathedLookupBOP(x) > LMB_NONE;
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
2000-03-07 01:14:37 +00:00
|
|
|
inline
|
|
|
|
bool MathIsBinary(short x)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-22 16:19:48 +00:00
|
|
|
return x == LM_TC_BOP || x == LM_TC_BOPS;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
2000-03-07 01:14:37 +00:00
|
|
|
inline
|
|
|
|
bool MathIsSymbol(short x) {
|
1999-11-22 16:19:48 +00:00
|
|
|
return LM_TC_SYMB <= x && x <= LM_TC_BSYM;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-03 21:02:22 +00:00
|
|
|
inline
|
|
|
|
bool is_eqn_type(short int type)
|
|
|
|
{
|
|
|
|
return type >= LM_OT_MIN && type < LM_OT_MATRIX;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline
|
|
|
|
bool is_matrix_type(short int type)
|
|
|
|
{
|
|
|
|
return type == LM_OT_MATRIX;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
bool is_multiline(short int type)
|
|
|
|
{
|
|
|
|
return type >= LM_OT_MPAR && type < LM_OT_MATRIX;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline bool is_ams(short int type)
|
|
|
|
{
|
|
|
|
return type > LM_OT_MPARN && type < LM_OT_MATRIX;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
bool is_singlely_numbered(short int type)
|
|
|
|
{
|
|
|
|
return type == LM_OT_PARN || type == LM_OT_MULTLINEN;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
bool is_multi_numbered(short int type)
|
|
|
|
{
|
2001-02-11 09:58:20 +00:00
|
|
|
return type == LM_OT_MPARN || type == LM_OT_ALIGNN
|
|
|
|
|| type == LM_OT_ALIGNATN;
|
2001-02-03 21:02:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
bool is_numbered(short int type)
|
|
|
|
{
|
|
|
|
return is_singlely_numbered(type) || is_multi_numbered(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
bool is_multicolumn(short int type)
|
|
|
|
{
|
2001-02-11 09:58:20 +00:00
|
|
|
return type == LM_OT_ALIGN || type == LM_OT_ALIGNN
|
|
|
|
|| type == LM_OT_ALIGNAT || type == LM_OT_ALIGNATN;
|
2001-02-03 21:02:22 +00:00
|
|
|
}
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
#endif
|