mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-26 03:11:59 +00:00
basic support for \xymatrix
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3482 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
5f4027ce80
commit
b5fd9ac98d
@ -1,3 +1,8 @@
|
||||
|
||||
2002-02-01 André Pönitz <poenitz@gmx.net>
|
||||
|
||||
* math_xymatrixinset.[Ch]: some support for \xymatrix
|
||||
|
||||
2002-02-01 André Pönitz <poenitz@gmx.net>
|
||||
|
||||
* math_undersetinset.[Ch]: implement direct support for \underset
|
||||
|
@ -128,4 +128,6 @@ libmathed_la_SOURCES = \
|
||||
math_undersetinset.C \
|
||||
math_undersetinset.h \
|
||||
math_xdata.C \
|
||||
math_xdata.h
|
||||
math_xdata.h \
|
||||
math_xymatrix.C \
|
||||
math_xymatrix.h
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "math_symbolinset.h"
|
||||
#include "math_undersetinset.h"
|
||||
#include "math_unknowninset.h"
|
||||
#include "math_xymatrix.h"
|
||||
|
||||
|
||||
MathAtom createMathInset(latexkeys const * l)
|
||||
@ -90,6 +91,9 @@ MathAtom createMathInset(string const & s)
|
||||
&& s[2] >= '1' && s[2] <= '9')
|
||||
return MathAtom(new MathMacroArgument(s[2] - '0'));
|
||||
|
||||
if (s == "xymatrix")
|
||||
return MathAtom(new MathXYMatrixInset);
|
||||
|
||||
latexkeys const * l = in_word_set(s);
|
||||
if (l)
|
||||
return createMathInset(l);
|
||||
|
@ -139,8 +139,9 @@ enum {
|
||||
FLAG_END = 1 << 3, // next \\end ends the parsing process
|
||||
FLAG_BRACK_END = 1 << 4, // next closing bracket ends the parsing process
|
||||
FLAG_BOX = 1 << 5, // we are in a box
|
||||
FLAG_ITEM = 1 << 7, // read a (possibly braced token)
|
||||
FLAG_BLOCK = 1 << 8, // next block ends the parsing process
|
||||
FLAG_ITEM = 1 << 6, // read a (possibly braced token)
|
||||
FLAG_BLOCK = 1 << 7, // next block ends the parsing process
|
||||
FLAG_BLOCK2 = 1 << 8, // next block2 ends the parsing process
|
||||
FLAG_LEAVE = 1 << 9 // leave the loop at the end
|
||||
};
|
||||
|
||||
@ -263,6 +264,8 @@ private:
|
||||
void error(string const & msg);
|
||||
///
|
||||
bool parse_lines(MathAtom & t, bool numbered, bool outmost);
|
||||
/// parses {... & ... \\ ... & ... }
|
||||
bool parse_lines2(MathAtom & t);
|
||||
|
||||
private:
|
||||
///
|
||||
@ -281,6 +284,10 @@ private:
|
||||
Token const & getToken();
|
||||
/// skips spaces if any
|
||||
void skipSpaces();
|
||||
/// skips opening brace
|
||||
void skipBegin();
|
||||
/// skips closing brace
|
||||
void skipEnd();
|
||||
/// counts a sequence of hlines
|
||||
int readHLines();
|
||||
///
|
||||
@ -359,6 +366,24 @@ void Parser::skipSpaces()
|
||||
}
|
||||
|
||||
|
||||
void Parser::skipBegin()
|
||||
{
|
||||
if (nextToken().cat() == catBegin)
|
||||
getToken();
|
||||
else
|
||||
lyxerr << "'{' expected\n";
|
||||
}
|
||||
|
||||
|
||||
void Parser::skipEnd()
|
||||
{
|
||||
if (nextToken().cat() == catEnd)
|
||||
getToken();
|
||||
else
|
||||
lyxerr << "'}' expected\n";
|
||||
}
|
||||
|
||||
|
||||
int Parser::readHLines()
|
||||
{
|
||||
int num = 0;
|
||||
@ -504,8 +529,6 @@ bool Parser::parse_lines(MathAtom & t, bool numbered, bool outmost)
|
||||
return false;
|
||||
}
|
||||
|
||||
MathInset::col_type const cols = p->ncols();
|
||||
|
||||
// save global variables
|
||||
bool const saved_num = curr_num_;
|
||||
string const saved_label = curr_label_;
|
||||
@ -519,9 +542,10 @@ bool Parser::parse_lines(MathAtom & t, bool numbered, bool outmost)
|
||||
curr_label_.erase();
|
||||
|
||||
// reading a row
|
||||
for (MathInset::col_type col = 0; col < cols; ++col) {
|
||||
for (MathInset::col_type col = 0; col < p->ncols(); ++col) {
|
||||
//lyxerr << "reading cell " << row << " " << col << "\n";
|
||||
parse_into(p->cell(col + row * cols), FLAG_BLOCK);
|
||||
|
||||
parse_into(p->cell(col + row * p->ncols()), FLAG_BLOCK);
|
||||
|
||||
// break if cell is not followed by an ampersand
|
||||
if (nextToken().cat() != catAlign) {
|
||||
@ -582,6 +606,62 @@ bool Parser::parse_lines(MathAtom & t, bool numbered, bool outmost)
|
||||
}
|
||||
|
||||
|
||||
bool Parser::parse_lines2(MathAtom & t)
|
||||
{
|
||||
MathGridInset * p = t->asGridInset();
|
||||
if (!p) {
|
||||
lyxerr << "error in Parser::parse_lines() 1\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
skipBegin();
|
||||
|
||||
for (int row = 0; true; ++row) {
|
||||
// reading a row
|
||||
for (MathInset::col_type col = 0; true; ++col) {
|
||||
//lyxerr << "reading cell " << row << " " << col << " " << p->ncols() << "\n";
|
||||
|
||||
if (col >= p->ncols()) {
|
||||
//lyxerr << "adding col " << col << "\n";
|
||||
p->addCol(p->ncols());
|
||||
}
|
||||
|
||||
parse_into(p->cell(col + row * p->ncols()), FLAG_BLOCK2);
|
||||
//lyxerr << "read cell: " << p->cell(col + row * p->ncols()) << "\n";
|
||||
|
||||
// break if cell is not followed by an ampersand
|
||||
if (nextToken().cat() != catAlign) {
|
||||
//lyxerr << "less cells read than normal in row/col: " << row << " " << col << "\n";
|
||||
break;
|
||||
}
|
||||
|
||||
// skip the ampersand
|
||||
getToken();
|
||||
}
|
||||
|
||||
// is a \\ coming?
|
||||
if (nextToken().isCR()) {
|
||||
// skip the cr-token
|
||||
getToken();
|
||||
}
|
||||
|
||||
// we are finished if the next token is an '}'
|
||||
if (nextToken().cat() == catEnd) {
|
||||
// skip the end-token
|
||||
getToken();
|
||||
// leave the 'read a line'-loop
|
||||
break;
|
||||
}
|
||||
|
||||
// otherwise, we have to start a new row
|
||||
p->appendRow();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Parser::parse_macro(string & name)
|
||||
{
|
||||
name = "{error}";
|
||||
@ -751,7 +831,7 @@ void Parser::parse_into(MathArray & array, unsigned flags, MathTextCodes code)
|
||||
while (good()) {
|
||||
Token const & t = getToken();
|
||||
|
||||
//lyxerr << "t: " << t << " flags: " << flags << "'\n";
|
||||
//lyxerr << "t: " << t << " flags: " << flags << "\n";
|
||||
//array.dump(lyxerr);
|
||||
//lyxerr << "\n";
|
||||
|
||||
@ -775,6 +855,14 @@ void Parser::parse_into(MathArray & array, unsigned flags, MathTextCodes code)
|
||||
}
|
||||
}
|
||||
|
||||
if (flags & FLAG_BLOCK2) {
|
||||
if (t.cat() == catAlign || t.isCR() || t.cs() == "end"
|
||||
|| t.cat() == catEnd) {
|
||||
putback();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// cat codes
|
||||
//
|
||||
@ -967,6 +1055,12 @@ void Parser::parse_into(MathArray & array, unsigned flags, MathTextCodes code)
|
||||
return;
|
||||
}
|
||||
|
||||
else if (t.cs() == "xymatrix") {
|
||||
array.push_back(createMathInset(t.cs()));
|
||||
parse_lines2(array.back());
|
||||
// skip closing brace
|
||||
}
|
||||
|
||||
// Disabled
|
||||
#if 0
|
||||
else if (t.cs() == "mbox") {
|
||||
|
53
src/mathed/math_xymatrix.C
Normal file
53
src/mathed/math_xymatrix.C
Normal file
@ -0,0 +1,53 @@
|
||||
#include <config.h>
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
|
||||
#include "math_xymatrix.h"
|
||||
#include "math_mathmlstream.h"
|
||||
#include "math_streamstr.h"
|
||||
|
||||
|
||||
MathXYMatrixInset::MathXYMatrixInset()
|
||||
: MathGridInset(1, 1)
|
||||
{}
|
||||
|
||||
|
||||
MathInset * MathXYMatrixInset::clone() const
|
||||
{
|
||||
return new MathXYMatrixInset(*this);
|
||||
}
|
||||
|
||||
|
||||
void MathXYMatrixInset::metrics(MathMetricsInfo const & st) const
|
||||
{
|
||||
MathMetricsInfo mi = st;
|
||||
if (mi.style == LM_ST_DISPLAY)
|
||||
mi.style = LM_ST_TEXT;
|
||||
MathGridInset::metrics(mi);
|
||||
}
|
||||
|
||||
|
||||
void MathXYMatrixInset::write(WriteStream & os) const
|
||||
{
|
||||
os << "\\xymatrix{";
|
||||
MathGridInset::write(os);
|
||||
os << "}\n";
|
||||
}
|
||||
|
||||
|
||||
void MathXYMatrixInset::normalize(NormalStream & os) const
|
||||
{
|
||||
os << "[xymatrix ";
|
||||
MathGridInset::normalize(os);
|
||||
os << "]";
|
||||
}
|
||||
|
||||
|
||||
void MathXYMatrixInset::maplize(MapleStream & os) const
|
||||
{
|
||||
os << "xymatrix(";
|
||||
MathGridInset::maplize(os);
|
||||
os << ")";
|
||||
}
|
31
src/mathed/math_xymatrix.h
Normal file
31
src/mathed/math_xymatrix.h
Normal file
@ -0,0 +1,31 @@
|
||||
// -*- C++ -*-
|
||||
#ifndef MATH_XYMATRIX_H
|
||||
#define MATH_XYMATRIX_H
|
||||
|
||||
#include "math_gridinset.h"
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
|
||||
class MathXYMatrixInset : public MathGridInset {
|
||||
public:
|
||||
///
|
||||
MathXYMatrixInset();
|
||||
///
|
||||
MathInset * clone() const;
|
||||
///
|
||||
void metrics(MathMetricsInfo const & st) const;
|
||||
///
|
||||
MathXYMatrixInset * asXYMatrixInset() { return this; }
|
||||
|
||||
///
|
||||
void write(WriteStream & os) const;
|
||||
///
|
||||
void normalize(NormalStream &) const;
|
||||
///
|
||||
void maplize(MapleStream &) const;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user