*
* Dependencies: Mathed
*
- * Copyright: (c) 1996, 1997 Alejandro Aguilar Sierra
+ * Copyright: 1996, 1997 Alejandro Aguilar Sierra
*
* Version: 0.2, Mathed & Lyx project.
*
#include "support/lstrings.h"
#include "debug.h"
+using std::ostream;
+using std::endl;
ostream & operator<<(ostream & o, MathedTextCodes mtc)
{
}
-void MathMacro::Write(ostream & os)
-{
- string output;
- MathMacro::Write(output);
- os << output;
-}
-
-
-void MathMacro::Write(string &file)
+void MathMacro::Write(ostream & os, bool fragile)
{
if (tmplate->flags & MMF_Exp) {
lyxerr[Debug::MATHED] << "Expand " << tmplate->flags
<< ' ' << MMF_Exp << endl;
tmplate->update(this);
- tmplate->Write(file);
+ tmplate->Write(os, fragile);
} else {
if (tmplate->flags & MMF_Env) {
- file += "\\begin{";
- file += name;
- file += "} ";
+ os << "\\begin{"
+ << name
+ << "} ";
} else {
- file += '\\';
- file += name;
+ os << '\\' << name;
}
// if (options) {
// file += '[';
// }
if (!(tmplate->flags & MMF_Env) && nargs > 0)
- file += '{';
+ os << '{';
for (int i = 0; i < nargs; ++i) {
array = args[i].array;
- MathParInset::Write(file);
+ MathParInset::Write(os, fragile);
if (i < nargs - 1)
- file += "}{";
+ os << "}{";
}
if (tmplate->flags & MMF_Env) {
- file += "\\end{";
- file += name;
- file += '}';
+ os << "\\end{"
+ << name
+ << '}';
} else {
if (nargs > 0)
- file += '}';
+ os << '}';
else
- file += ' ';
+ os << ' ';
}
}
}
-
/*--------------- Macro argument -----------------------------------*/
MathMacroArgument::MathMacroArgument(int n)
if (expnd_mode) {
MathParInset::draw(pain, x, baseline);
} else {
- unsigned char s[3];
- sprintf(reinterpret_cast<char*>(s), "#%d", number);
- drawStr(pain, LM_TC_TEX, size, x, baseline, &s[0], 2);
+#ifdef HAVE_SSTREAM
+ std::ostringstream ost;
+ ost << '#' << number;
+ drawStr(pain, LM_TC_TEX, size, x, baseline,
+ reinterpret_cast<byte const *>(ost.str().c_str()), 2);
+#else
+ char s[3];
+ ostrstream ost(s, 3);
+ ost << '#' << number << '\0';
+ drawStr(pain, LM_TC_TEX, size, x, baseline,
+ reinterpret_cast<byte *>(ost.str()), 2);
+#endif
}
}
if (expnd_mode) {
MathParInset::Metrics();
} else {
- unsigned char s[3];
- sprintf(reinterpret_cast<char*>(s), "#%d", number);
- width = mathed_string_width(LM_TC_TEX, size, &s[0], 2);
- mathed_string_height(LM_TC_TEX, size, &s[0], 2, ascent, descent);
+#ifdef HAVE_SSTREAM
+ std::ostringstream ost;
+ ost << '#' << number;
+ width = mathed_string_width(LM_TC_TEX, size,
+ reinterpret_cast<byte const *>(ost.str().c_str()), 2);
+ mathed_string_height(LM_TC_TEX, size,
+ reinterpret_cast<byte const *>(ost.str().c_str()),
+ 2, ascent, descent);
+#else
+ char s[3];
+ ostrstream ost(s, 3);
+ ost << '#' << number << '\0';
+ width = mathed_string_width(LM_TC_TEX, size,
+ reinterpret_cast<byte *>
+ (ost.str()), 2);
+ mathed_string_height(LM_TC_TEX, size,
+ reinterpret_cast<byte *>(ost.str()),
+ 2, ascent, descent);
+#endif
}
}
-void MathMacroArgument::Write(ostream & os)
-{
- string output;
- MathMacroArgument::Write(output);
- os << output;
-}
-
-
-void MathMacroArgument::Write(string & file)
+void MathMacroArgument::Write(ostream & os, bool fragile)
{
if (expnd_mode) {
- MathParInset::Write(file);
+ MathParInset::Write(os, fragile);
} else {
- file += '#';
- file += tostr(number);
- file += ' ';
+ os << '#' << number << ' ';
}
}
}
-void MathMacroTemplate::WriteDef(ostream & os)
+void MathMacroTemplate::WriteDef(ostream & os, bool fragile)
{
os << "\n\\newcommand{\\" << name << "}";
for (int i = 0; i < nargs; ++i) {
args[i].setExpand(false);
}
- Write(os);
+ Write(os, fragile);
os << "}\n";
}
-void MathMacroTemplate::WriteDef(string & file)
-{
- file += "\n\\newcommand{\\";
- file += name;
- file += '}';
-
- if (nargs > 0 ) {
- file += '[';
- file += tostr(nargs);
- file += ']';
- }
-
- file += '{';
-
- for (int i = 0; i < nargs; ++i) {
- args[i].setExpand(false);
- }
- Write(file);
- file += "}\n";
-}
-
-
void MathMacroTemplate::setArgument(LyxArrayBase * a, int i)
{
args[i].SetData(a);
/* -------------------------- MathMacroTable -----------------------*/
-MathMacroTable::MathMacroTable(int n): max_macros(n)
+MathMacroTable::MathMacroTable(int n) : max_macros(n)
{
macro_table = new MathMacroTemplateP[max_macros];
num_macros = 0;