Fix LaTeX exporting of \text{} to escape {}\
diff --git a/src/commands/text.js b/src/commands/text.js
index 59614ee..5af2946 100644
--- a/src/commands/text.js
+++ b/src/commands/text.js
@@ -65,7 +65,7 @@
_.latex = function() {
var contents = this.textContents();
if (contents.length === 0) return '';
- return '\\text{' + contents + '}';
+ return '\\text{' + contents.replace(/\\/g, '\\backslash ').replace(/[{}]/g, '\\$&') + '}';
};
_.html = function() {
return (
diff --git a/test/unit/publicapi.test.js b/test/unit/publicapi.test.js
index 4395cc8..4b71904 100644
--- a/test/unit/publicapi.test.js
+++ b/test/unit/publicapi.test.js
@@ -515,7 +515,7 @@
});
test('backslashes', function() {
assertPaste('something \\pi something \\asdf',
- '\\text{something \\pi something \\asdf}');
+ '\\text{something \\backslash pi something \\backslash asdf}');
});
// TODO: braces (currently broken)
test('actual math LaTeX wrapped in dollar signs', function() {
diff --git a/test/unit/typing.test.js b/test/unit/typing.test.js
index 0cb6446..a3f2253 100644
--- a/test/unit/typing.test.js
+++ b/test/unit/typing.test.js
@@ -60,7 +60,7 @@
test('\\text followed by command', function() {
mq.typedText('\\text{');
- assertLatex('\\text{{}');
+ assertLatex('\\text{\\{}');
});
});