Repository: KaTeX/KaTeX (js)

Issue:
Closing substack immediately causes crash
Opening and closing a substack without any content inside causes the program to crash with a "cannot read property 'length' of undefined" error.
Here are the exact steps to reproduce (you can't see the closing curly brace appear, as the program crashes as soon as i type it):

![katex_issue](https://user-images.githubusercontent.com/40633983/85164994-6d18bc00-b265-11ea-8184-512003ea541f.gif)


The last few items on the call stack are as follows:

![image](https://user-images.githubusercontent.com/40633983/85164319-7d7c6700-b264-11ea-8fc7-29227c7e216a.png)

I have set `throwOnError: false` so i would expect faulty input to cause red text, but not a crash.
This is in chromium, on Ubuntu 18.04, using your npm-package in a react-app.


Pull request description:
Enable an empty \substack
Fixes #2276.

Patch:
diff --git a/src/environments/array.js b/src/environments/array.js
index e2ad39d3..01108eaf 100644
--- a/src/environments/array.js
+++ b/src/environments/array.js
@@ -737,7 +737,7 @@ defineEnvironment({
             arraystretch: 0.5,
         };
         res = parseArray(context.parser, res, "script");
-        if (res.body[0].length > 1) {
+        if (res.body.length > 0 &&  res.body[0].length > 1) {
             throw new ParseError("{subarray} can contain only one column");
         }
         return res;


Test patch:
diff --git a/test/katex-spec.js b/test/katex-spec.js
index 07564a87..95d909ed 100644
--- a/test/katex-spec.js
+++ b/test/katex-spec.js
@@ -2660,6 +2660,9 @@ describe("A substack function", function() {
     it("should accommodate macros in the argument", function() {
         expect`\sum_{\substack{ 0<i<\varPi \\ 0<j<\pi }}  P(i,j)`.toBuild();
     });
+    it("should accommodate an empty argument", function() {
+        expect`\sum_{\substack{}}  P(i,j)`.toBuild();
+    });
 
 });