void InsetMathBox::write(WriteStream & os) const
{
+ bool oldmode = os.textMode();
+ os.textMode(true);
os << '\\' << name_ << '{' << cell(0) << '}';
+ os.textMode(oldmode);
}
void InsetMathFBox::write(WriteStream & os) const
{
+ bool oldmode = os.textMode();
+ os.textMode(true);
os << "\\fbox{" << cell(0) << '}';
+ os.textMode(oldmode);
}
void InsetMathMakebox::write(WriteStream & os) const
{
+ bool oldmode = os.textMode();
+ os.textMode(true);
os << (framebox_ ? "\\framebox" : "\\makebox");
if (cell(0).size() || !os.latex()) {
os << '[' << cell(0) << ']';
os << '[' << cell(1) << ']';
}
os << '{' << cell(2) << '}';
+ os.textMode(oldmode);
}
void InsetMathBoxed::write(WriteStream & os) const
{
+ bool oldmode = os.textMode();
+ os.textMode(true);
os << "\\boxed{" << cell(0) << '}';
+ os.textMode(oldmode);
}
using cap::replaceSelection;
using cap::selClearOrDel;
+char const * text_commands[] =
+{ "text", "textrm", "textsf", "texttt", "textmd", "textbf", "textup", "textit",
+ "textsl", "textsc" };
+int const num_text_commands = sizeof(text_commands) / sizeof(*text_commands);
+
InsetMathNest::InsetMathNest(idx_type nargs)
: cells_(nargs), lock_(false), mouse_hover_(false)
void InsetMathNest::write(WriteStream & os) const
{
- os << '\\' << name().c_str();
+ bool oldmode = os.textMode();
+ docstring const latex_name = name().c_str();
+ for (int i = 0; i < num_text_commands; ++i) {
+ if (latex_name == from_ascii(text_commands[i])) {
+ os.textMode(true);
+ break;
+ }
+ }
+ os << '\\' << latex_name;
for (size_t i = 0; i < nargs(); ++i)
os << '{' << cell(i) << '}';
if (nargs() == 0)
os << "\\lyxlock";
os.pendingSpace(true);
}
+ os.textMode(oldmode);
}
docstring::const_iterator cit = str_.begin();
docstring::const_iterator end = str_.end();
- bool in_lyxmathsym = false;
+ bool in_forced_mode = false;
while (cit != end) {
char_type const c = *cit;
try {
docstring command(1, c);
if (c < 0x80 || Encodings::latexMathChar(c, command)) {
- if (in_lyxmathsym) {
+ if (os.textMode()) {
+ if (c < 0x80 && in_forced_mode) {
+ os << '}';
+ in_forced_mode = false;
+ }
+ if (c >= 0x80 && !in_forced_mode) {
+ os << "\\ensuremath{";
+ in_forced_mode = true;
+ }
+ } else if (in_forced_mode) {
os << '}';
- in_lyxmathsym = false;
+ in_forced_mode = false;
}
- os << command;
} else {
- if (!in_lyxmathsym) {
+ if (os.textMode()) {
+ if (in_forced_mode) {
+ os << '}';
+ in_forced_mode = false;
+ }
+ } else if (!in_forced_mode) {
os << "\\lyxmathsym{";
- in_lyxmathsym = true;
+ in_forced_mode = true;
}
- os << command;
}
+ os << command;
// We may need a space if the command contains a macro
// and the last char is ASCII.
if (lyx::support::contains(command, '\\')
}
++cit;
}
- if (in_lyxmathsym)
+ if (in_forced_mode)
os << '}';
}
WriteStream::WriteStream(odocstream & os, bool fragile, bool latex, bool dryrun)
: os_(os), fragile_(fragile), firstitem_(false), latex_(latex),
- dryrun_(dryrun), pendingspace_(false), line_(0)
+ dryrun_(dryrun), pendingspace_(false), textmode_(false), line_(0)
{}
WriteStream::WriteStream(odocstream & os)
: os_(os), fragile_(false), firstitem_(false), latex_(false),
- dryrun_(false), pendingspace_(false), line_(0)
+ dryrun_(false), pendingspace_(false), textmode_(false), line_(0)
{}
}
+void WriteStream::textMode(bool textmode)
+{
+ textmode_ = textmode;
+}
+
+
WriteStream & operator<<(WriteStream & ws, MathAtom const & at)
{
at->write(ws);
void pendingSpace(bool how);
/// writes space if next thing is isalpha()
bool pendingSpace() const { return pendingspace_; }
+ /// tell whether we are in text mode or not when producing latex code
+ void textMode(bool textmode);
+ /// tell whether we are in text mode or not when producing latex code
+ bool textMode() const { return textmode_; }
private:
///
odocstream & os_;
bool dryrun_;
/// do we have a space pending?
bool pendingspace_;
+ /// are we in text mode when producing latex code?
+ bool textmode_;
///
int line_;
};