|
1701 | 1701 | Entry: function (name) {
|
1702 | 1702 | this.Push(STACKITEM.cell().With({isEntry: true, name: name}));
|
1703 | 1703 | if (this.stack.Top().isCases) {
|
| 1704 | + // |
| 1705 | + // Make second column be in \text{...} (unless it is already |
| 1706 | + // in a \text{...}, for backward compatibility). |
| 1707 | + // |
1704 | 1708 | var string = this.string;
|
1705 |
| - var braces = 0, i = this.i, m = string.length; |
| 1709 | + var braces = 0, close = -1, i = this.i, m = string.length; |
| 1710 | + // |
| 1711 | + // Look through the string character by character... |
| 1712 | + // |
1706 | 1713 | while (i < m) {
|
1707 | 1714 | var c = string.charAt(i);
|
1708 |
| - if (c === "{") {braces++; i++} |
1709 |
| - else if (c === "}") {if (braces === 0) {m = 0} else {braces--; i++}} |
1710 |
| - else if (c === "&" && braces === 0) { |
| 1715 | + if (c === "{") { |
| 1716 | + // |
| 1717 | + // Increase the nested brace count and go on |
| 1718 | + // |
| 1719 | + braces++; |
| 1720 | + i++; |
| 1721 | + } else if (c === "}") { |
| 1722 | + // |
| 1723 | + // If there are too many close braces, just end (we will get an |
| 1724 | + // error message later when the rest of the string is parsed) |
| 1725 | + // Otherwise |
| 1726 | + // decrease the nested brace count, |
| 1727 | + // if it is now zero and we haven't already marked the end of the |
| 1728 | + // first brace group, record the position (use to check for \text{} later) |
| 1729 | + // go on to the next character. |
| 1730 | + // |
| 1731 | + if (braces === 0) { |
| 1732 | + m = 0; |
| 1733 | + } else { |
| 1734 | + braces--; |
| 1735 | + if (braces === 0 && close < 0) { |
| 1736 | + close = i - this.i; |
| 1737 | + } |
| 1738 | + i++; |
| 1739 | + } |
| 1740 | + } else if (c === "&" && braces === 0) { |
| 1741 | + // |
| 1742 | + // Extra alignment tabs are not allowed in cases |
| 1743 | + // |
1711 | 1744 | TEX.Error(["ExtraAlignTab","Extra alignment tab in \\cases text"]);
|
1712 | 1745 | } else if (c === "\\") {
|
| 1746 | + // |
| 1747 | + // If the macro is \cr or \\, end the search, otherwise skip the macro |
| 1748 | + // (multi-letter names don't matter, as we will skip the rest of the |
| 1749 | + // characters in the main loop) |
| 1750 | + // |
1713 | 1751 | if (string.substr(i).match(/^((\\cr)[^a-zA-Z]|\\\\)/)) {m = 0} else {i += 2}
|
1714 |
| - } else {i++} |
| 1752 | + } else { |
| 1753 | + // |
| 1754 | + // Go on to the next character |
| 1755 | + // |
| 1756 | + i++; |
| 1757 | + } |
1715 | 1758 | }
|
| 1759 | + // |
| 1760 | + // Check if the second column text is already in \text{}, |
| 1761 | + // If not, process the second column as text and continue parsing from there, |
| 1762 | + // (otherwise process the second column as normal, since it is in \text{} |
| 1763 | + // |
1716 | 1764 | var text = string.substr(this.i,i-this.i);
|
1717 |
| - if (!text.match(/^\s*\\text[^a-zA-Z]/)) { |
| 1765 | + if (!text.match(/^\s*\\text[^a-zA-Z]/) || close !== text.replace(/\s+$/,'').length - 1) { |
1718 | 1766 | this.Push.apply(this,this.InternalMath(text,0));
|
1719 | 1767 | this.i = i;
|
1720 | 1768 | }
|
|
0 commit comments