void CommandInset::write(WriteStream & os) const
{
- ModeSpecifier specifier(os, currentMode(), lockedMode());
+ ModeSpecifier specifier(os, currentMode(), lockedMode(), asciiOnly());
MathEnsurer ensurer(os, needs_math_mode_);
- bool const ascii = os.asciiOnly();
- os.asciiOnly(asciiOnly());
os << '\\' << name_;
if (cell(1).size())
os << '[' << cell(1) << ']';
os << '{' << cell(0) << '}';
- os.asciiOnly(ascii);
}
}
-int ensureMode(WriteStream & os, InsetMath::mode_type mode, bool locked)
+int ensureMode(WriteStream & os, InsetMath::mode_type mode,
+ bool locked, bool ascii)
{
bool textmode = mode == InsetMath::TEXT_MODE;
if (os.latex() && textmode && os.pendingBrace()) {
os.pendingSpace(false);
os.textMode(true);
}
- int oldmodes = os.textMode() ? 1 : 0;
+ int oldmodes = os.textMode() ? 0x01 : 0;
os.textMode(textmode);
- oldmodes |= os.lockedMode() ? 2 : 0;
+ oldmodes |= os.lockedMode() ? 0x02 : 0;
os.lockedMode(locked);
+ oldmodes |= os.asciiOnly() ? 0x04 : 0;
+ os.asciiOnly(ascii);
return oldmodes;
}
bool ensureMath(WriteStream & os, bool needs_math_mode = true, bool macro = false);
/// ensure the requested mode, possibly by closing \ensuremath
-int ensureMode(WriteStream & os, InsetMath::mode_type mode, bool locked);
+int ensureMode(WriteStream & os, InsetMath::mode_type mode, bool locked, bool ascii);
/**
* the mode needs being temporarily switched when a command would not work
* in the current mode. As there are cases where this switching is to be
* avoided, the optional third parameter can be used to lock the mode.
+ * When the mode is locked, the optional fourth parameter specifies whether
+ * strings are to be output by using a suitable ascii representation.
*
* Example 1:
*
*
* Sets the current mode to text mode and disallows mode switching.
*
+ * Example 3:
+ *
+ * ModeSpecifier specifier(os, TEXT_MODE, true, true);
+ *
+ * Sets the current mode to text mode, disallows mode switching, and outputs
+ * strings as ascii only.
+ *
* At the end of specifier's scope the mode is reset to its previous value.
*/
class ModeSpecifier
public:
///
explicit ModeSpecifier(WriteStream & os, InsetMath::mode_type mode,
- bool locked = false)
- : os_(os), oldmodes_(ensureMode(os, mode, locked)) {}
+ bool locked = false, bool ascii = false)
+ : os_(os), oldmodes_(ensureMode(os, mode, locked, ascii)) {}
///
~ModeSpecifier()
{
- os_.textMode(oldmodes_ & 1);
- os_.lockedMode(oldmodes_ & 2);
+ os_.textMode(oldmodes_ & 0x01);
+ os_.lockedMode(oldmodes_ & 0x02);
+ os_.asciiOnly(oldmodes_ & 0x04);
}
private:
///