X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2Fmath_write.C;h=959a5bcb7fb8115733dfabc0ebe1a6cef804ba80;hb=8dccec5c46a1689fe3ea37144252e952771e1e1c;hp=10818a181f7f570a6174e72e0ace8a111ca540ba;hpb=27de1486ca34aaad446adb798d71a77d6f6304da;p=lyx.git diff --git a/src/mathed/math_write.C b/src/mathed/math_write.C index 10818a181f..959a5bcb7f 100644 --- a/src/mathed/math_write.C +++ b/src/mathed/math_write.C @@ -16,19 +16,21 @@ */ #include + #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", @@ -40,19 +42,20 @@ char const *math_font_name[] = { 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 += ' '; @@ -61,15 +64,16 @@ MathSpaceInset::Write(LString &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; @@ -77,14 +81,15 @@ MathDotsInset::Write(LString &outf) } -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; @@ -94,29 +99,30 @@ void MathSqrtInset::Write(LString &outf) } -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 += ' '; } } @@ -127,28 +133,29 @@ void MathDelimInset::Write(LString &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 += '{'; @@ -157,19 +164,20 @@ void MathDecorationInset::Write(LString &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 += ' '; @@ -177,7 +185,7 @@ void MathAccentInset::Write(LString &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 += '{'; @@ -190,49 +198,51 @@ void MathAccentInset::Write(LString &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; @@ -244,23 +254,23 @@ void MathFracInset::Write(LString &outf) } -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)) { @@ -273,52 +283,54 @@ void MathParInset::Write(LString &outf) } 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 @@ -333,7 +345,7 @@ void MathParInset::Write(LString &outf) { if (crow) { if (!crow->isNumbered()) { - outf +="\\nonumber "; + outf += "\\nonumber "; } if (crow->getLabel()) { outf += "\\label{"; @@ -348,14 +360,14 @@ void MathParInset::Write(LString &outf) 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{"; @@ -370,22 +382,23 @@ void MathParInset::Write(LString &outf) } -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 += '{'; @@ -403,27 +416,29 @@ void MathMatrixInset::Write(LString &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 @@ -433,7 +448,7 @@ void mathed_write(MathParInset* p, LString& outf, int* newlines, outf += "\n"; number_of_newlines++; } - if (mathed_env==LM_EN_DISPLAY){ + if (mathed_env == LM_EN_DISPLAY){ outf += "\\[\n"; } else { @@ -444,7 +459,7 @@ void mathed_write(MathParInset* p, LString& outf, int* newlines, 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"; @@ -453,11 +468,11 @@ void mathed_write(MathParInset* p, LString& outf, int* newlines, 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++; } @@ -465,7 +480,7 @@ void mathed_write(MathParInset* p, LString& outf, int* newlines, outf += "\n\\end{"; outf += latex_mathenv[mathed_env]; outf += "}\n"; - number_of_newlines+=2; + number_of_newlines+= 2; } *newlines = number_of_newlines; }