*/
#include <config.h>
+
#include "LString.h"
#include "math_inset.h"
#include "math_iter.h"
#include "math_parser.h"
+#include "support/lstrings.h"
+#include "debug.h"
-
-extern char const *latex_mathenv[];
-extern char *latex_mathspace[];
+extern char const * latex_mathenv[];
+extern char * latex_mathspace[];
// quite a hack i know. Should be done with return values...
static int number_of_newlines;
-char const *math_font_name[] = {
+char const * math_font_name[] = {
"mathrm",
"mathcal",
"mathbf",
void
-MathSpaceInset::Write(FILE *outf)
+MathSpaceInset::Write(ostream & os)
{
- if (space>=0 && space<6) {
- LString output;
+ if (space >= 0 && space < 6) {
+ string output;
MathSpaceInset::Write(output);
- fprintf(outf, "%s", output.c_str());
+ os << output;
}
}
+
void
-MathSpaceInset::Write(LString &outf)
+MathSpaceInset::Write(string & outf)
{
- if (space>=0 && space<6) {
+ if (space >= 0 && space < 6) {
outf += '\\';
outf += latex_mathspace[space];
outf += ' ';
void
-MathDotsInset::Write(FILE *outf)
+MathDotsInset::Write(ostream & os)
{
- LString output;
+ string output;
MathDotsInset::Write(output);
- fprintf(outf, "%s", output.c_str());
-}
+ os << output;
+}
+
void
-MathDotsInset::Write(LString &outf)
+MathDotsInset::Write(string & outf)
{
outf += '\\';
outf += name;
}
-void MathSqrtInset::Write(FILE *outf)
+void MathSqrtInset::Write(ostream & os)
{
- LString output;
- MathSqrtInset::Write(output);
- fprintf(outf, "%s", output.c_str());
+ string output;
+ MathSqrtInset::Write(output);
+ os << output;
}
-void MathSqrtInset::Write(LString &outf)
+
+void MathSqrtInset::Write(string & outf)
{
outf += '\\';
outf += name;
}
-void MathDelimInset::Write(FILE *outf)
+void MathDelimInset::Write(ostream & os)
{
- LString output;
+ string output;
MathDelimInset::Write(output);
- fprintf(outf, "%s", output.c_str());
+ os << output;
}
-void MathDelimInset::Write(LString &outf)
+
+void MathDelimInset::Write(string & outf)
{
- latexkeys* l = (left != '|') ? lm_get_key_by_id(left, LM_TK_SYM): 0;
- latexkeys* r = (right != '|') ? lm_get_key_by_id(right, LM_TK_SYM): 0;
+ latexkeys * l = (left != '|') ? lm_get_key_by_id(left, LM_TK_SYM): 0;
+ latexkeys * r = (right != '|') ? lm_get_key_by_id(right, LM_TK_SYM): 0;
outf += "\\left";
if (l) {
outf += '\\';
outf += l->name;
outf += ' ';
} else {
- if (left=='{' || left=='}') {
+ if (left == '{' || left == '}') {
outf += '\\';
- outf += (char) left;
+ outf += char(left);
outf += ' ';
} else {
- outf += (char) left;
+ outf += char(left);
outf += ' ';
}
}
outf += r->name;
outf += ' ';
} else {
- if (right=='{' || right=='}') {
+ if (right == '{' || right == '}') {
outf += '\\';
- outf += (char) right;
+ outf += char(right);
outf += ' ';
} else {
- outf += (char) right;
+ outf += char(right);
outf += ' ';
}
}
}
-void MathDecorationInset::Write(FILE *outf)
+void MathDecorationInset::Write(ostream & os)
{
- LString output;
+ string output;
MathDecorationInset::Write(output);
- fprintf(outf, "%s", output.c_str());
+ os << output;
}
-void MathDecorationInset::Write(LString &outf)
+
+void MathDecorationInset::Write(string & outf)
{
- latexkeys* l = lm_get_key_by_id(deco, LM_TK_WIDE);
+ latexkeys * l = lm_get_key_by_id(deco, LM_TK_WIDE);
outf += '\\';
outf += l->name;
outf += '{';
}
-void MathAccentInset::Write(FILE *outf)
+void MathAccentInset::Write(ostream & os)
{
- LString output;
+ string output;
MathAccentInset::Write(output);
- fprintf(outf, "%s", output.c_str());
+ os << output;
}
-void MathAccentInset::Write(LString &outf)
+
+void MathAccentInset::Write(string & outf)
{
- latexkeys* l = lm_get_key_by_id(code, LM_TK_ACCENT);
+ latexkeys * l = lm_get_key_by_id(code, LM_TK_ACCENT);
outf += '\\';
outf += l->name;
- if (code!=LM_not)
+ if (code!= LM_not)
outf += '{';
else
outf += ' ';
if (inset) {
inset->Write(outf);
} else {
- if (fn>=LM_TC_RM && fn<=LM_TC_TEXTRM) {
+ if (fn>= LM_TC_RM && fn<= LM_TC_TEXTRM) {
outf += '\\';
outf += math_font_name[fn-LM_TC_RM];
outf += '{';
outf += ' ';
}
} else
- outf += (char) c;
+ outf += char(c);
- if (fn>=LM_TC_RM && fn<=LM_TC_TEXTRM)
+ if (fn>= LM_TC_RM && fn<= LM_TC_TEXTRM)
outf += '}';
}
- if (code!=LM_not)
+ if (code!= LM_not)
outf += '}';
}
-void MathBigopInset::Write(FILE *outf)
+void MathBigopInset::Write(ostream & os)
{
- LString output;
+ string output;
MathBigopInset::Write(output);
- fprintf(outf, "%s", output.c_str());
+ os << output;
}
-void MathBigopInset::Write(LString &outf)
+
+void MathBigopInset::Write(string & outf)
{
bool limp = GetLimits();
outf += '\\';
outf += name;
- if (limp && !(sym!=LM_int && sym!=LM_oint && (GetStyle()==LM_ST_DISPLAY)))
+ if (limp && !(sym!= LM_int && sym!= LM_oint && (GetStyle() == LM_ST_DISPLAY)))
outf += "\\limits ";
else
- if (!limp && (sym!=LM_int && sym!=LM_oint && (GetStyle()==LM_ST_DISPLAY)))
+ if (!limp && (sym!= LM_int && sym!= LM_oint && (GetStyle() == LM_ST_DISPLAY)))
outf += "\\nolimits ";
else
outf += ' ';
}
-void MathFracInset::Write(FILE *outf)
+void MathFracInset::Write(ostream & os)
{
- LString output;
- MathFracInset::Write(output);
- fprintf(outf, "%s", output.c_str());
+ string output;
+ MathFracInset::Write(output);
+ os << output;
}
-void MathFracInset::Write(LString &outf)
+
+void MathFracInset::Write(string & outf)
{
outf += '\\';
outf += name;
}
-void MathParInset::Write(FILE *outf)
+void MathParInset::Write(ostream & os)
{
if (!array) return;
- LString output;
+ string output;
MathParInset::Write(output);
- fprintf(outf, "%s", output.c_str());
+ os << output;
}
-void MathParInset::Write(LString &outf)
+void MathParInset::Write(string & outf)
{
if (!array) return;
int brace = 0;
- latexkeys *l;
+ latexkeys * l;
MathedIter data(array);
// hack
- MathedRowSt const* crow = getRowSt();
+ MathedRowSt const * crow = getRowSt();
data.Reset();
if (!Permit(LMPF_FIXED_SIZE)) {
}
while (data.OK()) {
byte cx = data.GetChar();
- if (cx>=' ') {
+ if (cx>= ' ') {
int ls;
- byte *s = data.GetString(ls);
+ byte * s = data.GetString(ls);
- if (data.FCode()>=LM_TC_RM && data.FCode()<=LM_TC_TEXTRM) {
+ if (data.FCode()>= LM_TC_RM && data.FCode()<= LM_TC_TEXTRM) {
outf += '\\';
outf += math_font_name[data.FCode()-LM_TC_RM];
outf += '{';
}
while (ls>0) {
if (MathIsSymbol(data.FCode())) {
- l = lm_get_key_by_id(*s,(data.FCode()==LM_TC_BSYM)?LM_TK_BIGSYM:LM_TK_SYM);
+ l = lm_get_key_by_id(*s,(data.FCode() == LM_TC_BSYM)?LM_TK_BIGSYM:LM_TK_SYM);
if (l) {
outf += '\\';
outf += l->name;
outf += ' ';
} else {
- fprintf(stderr, "Illegal symbol code[%u %d %d]", *s, ls, data.FCode());
+ lyxerr << "Illegal symbol code[" << *s
+ << " " << ls << " " << data.FCode() << "]";
}
} else {
// Is there a standard logical XOR?
- if ((data.FCode()==LM_TC_TEX && *s!='{' && *s!='}') ||
- (data.FCode()==LM_TC_SPECIAL))
+ if ((data.FCode() == LM_TC_TEX && *s!= '{' && *s!= '}') ||
+ (data.FCode() == LM_TC_SPECIAL))
outf += '\\';
else {
- if (*s=='{') brace++;
- if (*s=='}') brace--;
+ if (*s == '{') brace++;
+ if (*s == '}') brace--;
}
- if (*s=='}' && data.FCode()==LM_TC_TEX && brace<0)
- fprintf(stderr, "Math warning: Unexpected closing brace.\n");
+ if (*s == '}' && data.FCode() == LM_TC_TEX && brace<0)
+ lyxerr <<"Math warning: Unexpected closing brace."
+ << endl;
else
- outf += (char) *s;
+ outf += char(*s);
}
s++; ls--;
}
- if (data.FCode()>=LM_TC_RM && data.FCode()<=LM_TC_TEXTRM)
+ if (data.FCode()>= LM_TC_RM && data.FCode()<= LM_TC_TEXTRM)
outf += '}';
} else
if (MathIsInset(cx)) {
MathedInset *p = data.GetInset();
- if (cx==LM_TC_UP)
+ if (cx == LM_TC_UP)
outf += "^{";
- if (cx==LM_TC_DOWN)
+ if (cx == LM_TC_DOWN)
outf += "_{";
p->Write(outf);
- if (cx==LM_TC_UP || cx==LM_TC_DOWN)
+ if (cx == LM_TC_UP || cx == LM_TC_DOWN)
outf += '}';
data.Next();
} else
{
if (crow) {
if (!crow->isNumbered()) {
- outf +="\\nonumber ";
+ outf += "\\nonumber ";
}
if (crow->getLabel()) {
outf += "\\label{";
break;
}
default:
- fprintf(stderr, "WMath Error: unrecognized code[%d]", cx);
+ lyxerr << "WMath Error: unrecognized code[" << cx << "]";
return;
}
}
if (crow) {
if (!crow->isNumbered()) {
- outf +="\\nonumber ";
+ outf += "\\nonumber ";
}
if (crow->getLabel()) {
outf += "\\label{";
}
-void MathMatrixInset::Write(FILE *outf)
+void MathMatrixInset::Write(ostream & os)
{
- LString output;
+ string output;
MathMatrixInset::Write(output);
- fprintf(outf, "%s", output.c_str());
+ os << output;
}
-void MathMatrixInset::Write(LString &outf)
+
+void MathMatrixInset::Write(string & outf)
{
if (GetType() == LM_OT_MATRIX){
outf += "\\begin{";
outf += name;
outf += '}';
- if (v_align=='t' || v_align=='b') {
+ if (v_align == 't' || v_align == 'b') {
outf += '[';
- outf += (char) v_align;
+ outf += char(v_align);
outf += ']';
}
outf += '{';
}
-void mathed_write(MathParInset* p, FILE* outf, int* newlines, char fragile, char const* label)
+void mathed_write(MathParInset * p, ostream & os, int * newlines,
+ char fragile, char const * label)
{
- LString output;
+ string output;
mathed_write(p, output, newlines, fragile, label);
- fprintf(outf, "%s", output.c_str());
+ os << output;
}
+
extern int tex_code_break_column;
-void mathed_write(MathParInset* p, LString& outf, int* newlines,
- char fragile, char const* label)
+void mathed_write(MathParInset * p, string & outf, int * newlines,
+ char fragile, char const * label)
{
number_of_newlines = 0;
short mathed_env = p->GetType();
- if (mathed_env==LM_EN_INTEXT) {
+ if (mathed_env == LM_EN_INTEXT) {
if (fragile) outf += "\\protect";
outf += "\\( "; // changed from " \\( " (Albrecht Dress)
}
else {
- if (! outf.suffixIs('\n')) {
+ if (!suffixIs(outf, '\n')) {
// in batchmode we need to make sure
// a space before an equation doesn't
// make the LaTeX output different
outf += "\n";
number_of_newlines++;
}
- if (mathed_env==LM_EN_DISPLAY){
+ if (mathed_env == LM_EN_DISPLAY){
outf += "\\[\n";
}
else {
number_of_newlines++;
}
- if (label && label[0]>' ' && mathed_env==LM_EN_EQUATION){
+ if (label && label[0]>' ' && mathed_env == LM_EN_EQUATION){
outf += "\\label{";
outf += label;
outf += "}\n";
p->Write(outf);
- if (mathed_env==LM_EN_INTEXT){
+ if (mathed_env == LM_EN_INTEXT){
if (fragile) outf += "\\protect";
outf += " \\)";
}
- else if (mathed_env==LM_EN_DISPLAY){
+ else if (mathed_env == LM_EN_DISPLAY){
outf += "\\]\n";
number_of_newlines++;
}
outf += "\n\\end{";
outf += latex_mathenv[mathed_env];
outf += "}\n";
- number_of_newlines+=2;
+ number_of_newlines+= 2;
}
*newlines = number_of_newlines;
}