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