mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-09-20 15:01:58 +00:00
Correctly terminate a user math macro in certain circumstances
If a macro has only optionals and none is specified and a [ immediately follows, we have to terminate the macro with {}, otherwise what follows is taken to be an optional argument. Fixes #11665.
This commit is contained in:
parent
99e636ae7b
commit
fece5d4f37
@ -1214,8 +1214,11 @@ void InsetMathMacro::write(TeXMathStream & os) const
|
||||
}
|
||||
|
||||
// add space if there was no argument
|
||||
if (first)
|
||||
// or add braces if we have optionals but none are present and [ follows
|
||||
if (first) {
|
||||
os.pendingSpace(true);
|
||||
os.useBraces(d->optionals_ > 0);
|
||||
}
|
||||
|
||||
// write \(no)limits modifiers if relevant
|
||||
writeLimits(os);
|
||||
|
@ -106,6 +106,8 @@ TeXMathStream & operator<<(TeXMathStream & ws, docstring const & s)
|
||||
} else if (ws.pendingSpace()) {
|
||||
if (isAlphaASCII(s[first]))
|
||||
ws.os() << ' ';
|
||||
else if (s[first] == '[' && ws.useBraces())
|
||||
ws.os() << "{}";
|
||||
else if (s[first] == ' ' && ws.textMode())
|
||||
ws.os() << '\\';
|
||||
ws.pendingSpace(false);
|
||||
@ -148,9 +150,17 @@ void TeXMathStream::addlines(unsigned int n)
|
||||
}
|
||||
|
||||
|
||||
void TeXMathStream::pendingSpace(bool how)
|
||||
void TeXMathStream::pendingSpace(bool space)
|
||||
{
|
||||
pendingspace_ = how;
|
||||
pendingspace_ = space;
|
||||
if (!space)
|
||||
usebraces_ = false;
|
||||
}
|
||||
|
||||
|
||||
void TeXMathStream::useBraces(bool braces)
|
||||
{
|
||||
usebraces_ = braces;
|
||||
}
|
||||
|
||||
|
||||
@ -226,6 +236,8 @@ TeXMathStream & operator<<(TeXMathStream & ws, char c)
|
||||
} else if (ws.pendingSpace()) {
|
||||
if (isAlphaASCII(c))
|
||||
ws.os() << ' ';
|
||||
else if (c == '[' && ws.useBraces())
|
||||
ws.os() << "{}";
|
||||
else if (c == ' ' && ws.textMode())
|
||||
ws.os() << '\\';
|
||||
ws.pendingSpace(false);
|
||||
|
@ -80,9 +80,13 @@ public:
|
||||
/// tell which ulem command type we are inside
|
||||
UlemCmdType ulemCmd() const { return ulemcmd_; }
|
||||
/// writes space if next thing is isalpha()
|
||||
void pendingSpace(bool how);
|
||||
void pendingSpace(bool space);
|
||||
/// writes space if next thing is isalpha()
|
||||
bool pendingSpace() const { return pendingspace_; }
|
||||
/// write braces if a space is pending and next char is [
|
||||
void useBraces(bool braces);
|
||||
/// write braces if a space is pending and next char is [
|
||||
bool useBraces() const { return usebraces_; }
|
||||
/// tell whether to write the closing brace of \ensuremath
|
||||
void pendingBrace(bool brace);
|
||||
/// tell whether to write the closing brace of \ensuremath
|
||||
@ -124,6 +128,8 @@ private:
|
||||
OutputType output_ = wsDefault;
|
||||
/// do we have a space pending?
|
||||
bool pendingspace_ = false;
|
||||
/// do we have to write braces when a space is pending and [ follows?
|
||||
bool usebraces_ = false;
|
||||
/// do we have a brace pending?
|
||||
bool pendingbrace_ = false;
|
||||
/// are we in text mode when producing latex code?
|
||||
|
Loading…
Reference in New Issue
Block a user