mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-18 21:45:24 +00:00
Backport cumulative fix for bug #6284.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_6_X@31710 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
3bfd4a66c2
commit
fe41e57d12
@ -70,7 +70,6 @@ following hack as starting point to write some macros:
|
||||
#include "support/debug.h"
|
||||
#include "support/convert.h"
|
||||
#include "support/docstream.h"
|
||||
#include "support/lstrings.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
@ -80,8 +79,6 @@ using namespace std;
|
||||
|
||||
namespace lyx {
|
||||
|
||||
using support::subst;
|
||||
|
||||
namespace {
|
||||
|
||||
InsetMath::mode_type asMode(InsetMath::mode_type oldmode, docstring const & str)
|
||||
@ -102,23 +99,52 @@ bool stared(docstring const & s)
|
||||
}
|
||||
|
||||
|
||||
docstring const repl(docstring const & oldstr, char_type const c,
|
||||
docstring const & macro, bool textmode = false)
|
||||
{
|
||||
docstring newstr;
|
||||
size_t i;
|
||||
size_t j;
|
||||
|
||||
for (i = 0, j = 0; i < oldstr.size(); ++i) {
|
||||
if (c == oldstr[i]) {
|
||||
newstr.append(oldstr, j, i - j);
|
||||
newstr.append(macro);
|
||||
j = i + 1;
|
||||
if (macro.size() > 2 && j < oldstr.size())
|
||||
newstr += (textmode && oldstr[j] == ' ' ? '\\' : ' ');
|
||||
}
|
||||
}
|
||||
|
||||
// Any substitution?
|
||||
if (j == 0)
|
||||
return oldstr;
|
||||
|
||||
newstr.append(oldstr, j, i - j);
|
||||
return newstr;
|
||||
}
|
||||
|
||||
|
||||
docstring escapeSpecialChars(docstring const & str, bool textmode)
|
||||
{
|
||||
docstring const backslash = textmode ? from_ascii("\\textbackslash ")
|
||||
: from_ascii("\\backslash ");
|
||||
docstring const caret = textmode ? from_ascii("\\textasciicircum ")
|
||||
: from_ascii("\\mathcircumflex ");
|
||||
docstring const backslash = textmode ? from_ascii("\\textbackslash")
|
||||
: from_ascii("\\backslash");
|
||||
docstring const caret = textmode ? from_ascii("\\textasciicircum")
|
||||
: from_ascii("\\mathcircumflex");
|
||||
docstring const tilde = textmode ? from_ascii("\\textasciitilde")
|
||||
: from_ascii("\\sim");
|
||||
|
||||
return subst(subst(subst(subst(subst(subst(subst(subst(subst(str,
|
||||
from_ascii("\\"), backslash),
|
||||
from_ascii("^"), caret),
|
||||
from_ascii("_"), from_ascii("\\_")),
|
||||
from_ascii("$"), from_ascii("\\$")),
|
||||
from_ascii("#"), from_ascii("\\#")),
|
||||
from_ascii("&"), from_ascii("\\&")),
|
||||
from_ascii("%"), from_ascii("\\%")),
|
||||
from_ascii("{"), from_ascii("\\{")),
|
||||
from_ascii("}"), from_ascii("\\}"));
|
||||
return repl(repl(repl(repl(repl(repl(repl(repl(repl(repl(str,
|
||||
'\\', backslash, textmode),
|
||||
'^', caret, textmode),
|
||||
'~', tilde, textmode),
|
||||
'_', from_ascii("\\_")),
|
||||
'$', from_ascii("\\$")),
|
||||
'#', from_ascii("\\#")),
|
||||
'&', from_ascii("\\&")),
|
||||
'%', from_ascii("\\%")),
|
||||
'{', from_ascii("\\{")),
|
||||
'}', from_ascii("\\}"));
|
||||
}
|
||||
|
||||
|
||||
@ -1777,7 +1803,6 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
|
||||
if (mode == InsetMath::TEXT_MODE) {
|
||||
int num_tokens = 0;
|
||||
docstring cmd = prevToken().asInput();
|
||||
skipSpaces();
|
||||
CatCode cat = nextToken().cat();
|
||||
if (cat == catBegin) {
|
||||
int count = 0;
|
||||
|
@ -93,6 +93,8 @@ WriteStream & operator<<(WriteStream & ws, docstring const & s)
|
||||
} else if (ws.pendingSpace() && s.length() > 0) {
|
||||
if (isAlphaASCII(s[0]))
|
||||
ws.os() << ' ';
|
||||
else if (s[0] == ' ' && ws.textMode())
|
||||
ws.os() << '\\';
|
||||
ws.pendingSpace(false);
|
||||
}
|
||||
ws.os() << s;
|
||||
@ -185,6 +187,8 @@ WriteStream & operator<<(WriteStream & ws, char const * s)
|
||||
} else if (ws.pendingSpace() && strlen(s) > 0) {
|
||||
if (isAlphaASCII(s[0]))
|
||||
ws.os() << ' ';
|
||||
else if (s[0] == ' ' && ws.textMode())
|
||||
ws.os() << '\\';
|
||||
ws.pendingSpace(false);
|
||||
}
|
||||
ws.os() << s;
|
||||
@ -203,6 +207,8 @@ WriteStream & operator<<(WriteStream & ws, char c)
|
||||
} else if (ws.pendingSpace()) {
|
||||
if (isAlphaASCII(c))
|
||||
ws.os() << ' ';
|
||||
else if (c == ' ' && ws.textMode())
|
||||
ws.os() << '\\';
|
||||
ws.pendingSpace(false);
|
||||
}
|
||||
ws.os() << c;
|
||||
|
@ -235,6 +235,9 @@ What's new
|
||||
- Fix the painting of the last character of a paragraph, e.g.
|
||||
added/deleted paragraph breaks in change tracking.
|
||||
|
||||
- Do not swallow spaces after a LaTeX macro appearing in text mode
|
||||
inside mathed (bug 6284).
|
||||
|
||||
|
||||
* DOCUMENTATION AND LOCALIZATION
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user