Repository: Khan/KaTeX
Pull request #1741 (2018-10-13 09:49:32)

Add support for `\lparen` and `\rparen` delimiters.
Add support for `\lparen` and `\rparen` delimiters as synonyms of `(` and `)` respectively.
See #806.

khanbot: Hey @AlbertHilb,

Thanks for the PR! Mind signing our [Contributor License Agreement](http://khanacademy.org/r/cla)?

When you've done so, go ahead and comment `[clabot:check]` and I'll check again.

Yours truly,
khanbot
codecov[bot]: # [Codecov](https://codecov.io/gh/Khan/KaTeX/pull/1741?src=pr&el=h1) Report
> Merging [#1741](https://codecov.io/gh/Khan/KaTeX/pull/1741?src=pr&el=desc) into [master](https://codecov.io/gh/Khan/KaTeX/commit/a51dc4b0727dad43187e8cf006cf1aeb32cb4de3?src=pr&el=desc) will **decrease** coverage by `0.06%`.
> The diff coverage is `100%`.


[![Impacted file tree graph](https://codecov.io/gh/Khan/KaTeX/pull/1741/graphs/tree.svg?width=650&token=vfDnj2P77o&height=150&src=pr)](https://codecov.io/gh/Khan/KaTeX/pull/1741?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master    #1741      +/-   ##
==========================================
- Coverage   93.95%   93.89%   -0.07%     
==========================================
  Files          78       78              
  Lines        4584     4571      -13     
  Branches      809      805       -4     
==========================================
- Hits         4307     4292      -15     
- Misses        245      246       +1     
- Partials       32       33       +1
```

| Flag | Coverage Δ | |
|---|---|---|
| #screenshotter | `88.76% <100%> (+0.19%)` | :arrow_up: |
| #test | `85.25% <100%> (-0.13%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/Khan/KaTeX/pull/1741?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/functions/delimsizing.js](https://codecov.io/gh/Khan/KaTeX/pull/1741/diff?src=pr&el=tree#diff-c3JjL2Z1bmN0aW9ucy9kZWxpbXNpemluZy5qcw==) | `96.55% <ø> (ø)` | :arrow_up: |
| [src/delimiter.js](https://codecov.io/gh/Khan/KaTeX/pull/1741/diff?src=pr&el=tree#diff-c3JjL2RlbGltaXRlci5qcw==) | `83.83% <100%> (ø)` | :arrow_up: |
| [src/symbols.js](https://codecov.io/gh/Khan/KaTeX/pull/1741/diff?src=pr&el=tree#diff-c3JjL3N5bWJvbHMuanM=) | `100% <100%> (ø)` | :arrow_up: |
| [src/utils.js](https://codecov.io/gh/Khan/KaTeX/pull/1741/diff?src=pr&el=tree#diff-c3JjL3V0aWxzLmpz) | `85.71% <0%> (-7.39%)` | :arrow_down: |
| [src/buildCommon.js](https://codecov.io/gh/Khan/KaTeX/pull/1741/diff?src=pr&el=tree#diff-c3JjL2J1aWxkQ29tbW9uLmpz) | `98.44% <0%> (-0.03%)` | :arrow_down: |
| [src/Lexer.js](https://codecov.io/gh/Khan/KaTeX/pull/1741/diff?src=pr&el=tree#diff-c3JjL0xleGVyLmpz) | `100% <0%> (ø)` | :arrow_up: |
| [src/functions/href.js](https://codecov.io/gh/Khan/KaTeX/pull/1741/diff?src=pr&el=tree#diff-c3JjL2Z1bmN0aW9ucy9ocmVmLmpz) | `100% <0%> (ø)` | :arrow_up: |
| [src/parseNode.js](https://codecov.io/gh/Khan/KaTeX/pull/1741/diff?src=pr&el=tree#diff-c3JjL3BhcnNlTm9kZS5qcw==) | `84.21% <0%> (ø)` | :arrow_up: |
| [src/functions/enclose.js](https://codecov.io/gh/Khan/KaTeX/pull/1741/diff?src=pr&el=tree#diff-c3JjL2Z1bmN0aW9ucy9lbmNsb3NlLmpz) | `100% <0%> (ø)` | :arrow_up: |
| [src/SourceLocation.js](https://codecov.io/gh/Khan/KaTeX/pull/1741/diff?src=pr&el=tree#diff-c3JjL1NvdXJjZUxvY2F0aW9uLmpz) | `100% <0%> (ø)` | :arrow_up: |
| ... and [3 more](https://codecov.io/gh/Khan/KaTeX/pull/1741/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/Khan/KaTeX/pull/1741?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/Khan/KaTeX/pull/1741?src=pr&el=footer). Last update [a51dc4b...d4149f1](https://codecov.io/gh/Khan/KaTeX/pull/1741?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

AlbertHilb: [clabot:check]
khanbot: CLA signature looks good :+1:
edemaine: @AlbertHilb Thanks! One more request: could you add some simple tests? https://github.com/Khan/KaTeX/blob/master/test/katex-spec.js#L1199-L1200 would be easy to add to.
AlbertHilb: Test added and spaces fixed.

Patch:
diff --git a/docs/support_table.md b/docs/support_table.md
index ce3ac8de..e7a26ed3 100644
--- a/docs/support_table.md
+++ b/docs/support_table.md
@@ -587,6 +587,7 @@ table td {
 |\lor|$\lor$||
 |\lower|<span style="color:firebrick;">Not supported</span>||
 |\lozenge|$\lozenge$||
+|\lparen|$\lparen$||
 |\Lrarr|$\Lrarr$||
 |\lrArr|$\lrArr$||
 |\lrarr|$\lrarr$||
@@ -864,6 +865,7 @@ table td {
 |\rmoustache|$\rmoustache$||
 |\root|<span style="color:firebrick;">Not supported</span>||
 |\rotatebox|<span style="color:firebrick;">Not supported</span>|[Issue #681](https://github.com/Khan/KaTeX/issues/681)|
+|\rparen|$\rparen$||
 |\rq|$\rq$||
 |\Rrightarrow|$\Rrightarrow$||
 |\Rsh|$\Rsh$||
diff --git a/docs/supported.md b/docs/supported.md
index 6fa48d89..303f6199 100644
--- a/docs/supported.md
+++ b/docs/supported.md
@@ -53,14 +53,14 @@ See also [letters](#letters)
 
 ||||||
 |:-----------------------------------|:---------------------------------------|:----------|:-------------------------------------------------------|:-----
-|$( )$ `( )` |$\lt~\gt$ `\lt \gt` |$⌈~⌉$ `⌈ ⌉`|$\lceil~\rceil$ `\lceil`<br>$~~~~~$`\rceil`  |$\uparrow$ `\uparrow`
-|$[ ]$ `[ ]` |$\lbrack~\rbrack$ `\lbrack`<br>$~~~~$`\rbrack`|$⌊~⌋$ `⌊ ⌋`|$\lfloor~\rfloor$ `\lfloor`<br>$~~~~~$`\rfloor` |$\downarrow$ `\downarrow`
+|$(~)$ `( )` |$\lparen~\rparen$ `\lparen`<br>$~~~~$`\rparen`|$⌈~⌉$ `⌈ ⌉`|$\lceil~\rceil$ `\lceil`<br>$~~~~~$`\rceil`  |$\uparrow$ `\uparrow`
+|$[~]$ `[ ]` |$\lbrack~\rbrack$ `\lbrack`<br>$~~~~$`\rbrack`|$⌊~⌋$ `⌊ ⌋`|$\lfloor~\rfloor$ `\lfloor`<br>$~~~~~$`\rfloor` |$\downarrow$ `\downarrow`
 |$\{ \}$ `\{ \}`|$\lbrace \rbrace$ `\lbrace`<br>$~~~~$`\rbrace`|$⎰⎱$ `⎰⎱`  |$\lmoustache \rmoustache$ `\lmoustache`<br>$~~~~$`\rmoustache`|$\updownarrow$ `\updownarrow`
 |$⟨~⟩$ `⟨ ⟩` |$\langle~\rangle$ `\langle`<br>$~~~~$`\rangle`|$⟮~⟯$ `⟮ ⟯`|$\lgroup~\rgroup$ `\lgroup`<br>$~~~~~$`\rgroup` |$\Uparrow$ `\Uparrow`
 |$\vert$ <code>&#124;</code> |$\vert$ `\vert` |$┌ ┐$ `┌ ┐`|$\ulcorner \urcorner$ `\ulcorner`<br>$~~~~$`\urcorner`  |$\Downarrow$ `\Downarrow`
 |$\Vert$ <code>&#92;&#124;</code> |$\Vert$ `\Vert` |$└ ┘$ `└ ┘`|$\llcorner \lrcorner$ `\llcorner`<br>$~~~~$`\lrcorner`  |$\Updownarrow$ `\Updownarrow`
 |$\lvert~\rvert$ `\lvert`<br>$~~~~$`\rvert`|$\lVert~\rVert$ `\lVert`<br>$~~~~~$`\rVert` |`\left.`|  `\right.` |$\backslash$ `\backslash`
-|$\lang~\rang$ `\lang`<br>$~~~~$`\rang`
+|$\lang~\rang$ `\lang`<br>$~~~~$`\rang`|$\lt~\gt$ `\lt \gt`|
 
 **Delimiter Sizing**
 
diff --git a/src/delimiter.js b/src/delimiter.js
index 3bad853f..a150406b 100644
--- a/src/delimiter.js
+++ b/src/delimiter.js
@@ -245,12 +245,12 @@ const makeStackedDelim = function(
         top = "\u23a4";
         repeat = bottom = "\u23a5";
         font = "Size4-Regular";
-    } else if (delim === "(") {
+    } else if (delim === "(" || delim === "\\lparen") {
         top = "\u239b";
         repeat = "\u239c";
         bottom = "\u239d";
         font = "Size4-Regular";
-    } else if (delim === ")") {
+    } else if (delim === ")" || delim === "\\rparen") {
         top = "\u239e";
         repeat = "\u239f";
         bottom = "\u23a0";
@@ -489,7 +489,8 @@ const makeSqrtImage = function(
 // There are three kinds of delimiters, delimiters that stack when they become
 // too large
 const stackLargeDelimiters = [
-    "(", ")", "[", "\\lbrack", "]", "\\rbrack",
+    "(", "\\lparen", ")", "\\rparen",
+    "[", "\\lbrack", "]", "\\rbrack",
     "\\{", "\\lbrace", "\\}", "\\rbrace",
     "\\lfloor", "\\rfloor", "\u230a", "\u230b",
     "\\lceil", "\\rceil", "\u2308", "\u2309",
diff --git a/src/functions/delimsizing.js b/src/functions/delimsizing.js
index d81a510e..533764a1 100644
--- a/src/functions/delimsizing.js
+++ b/src/functions/delimsizing.js
@@ -35,7 +35,8 @@ const delimiterSizes = {
 };
 
 const delimiters = [
-    "(", ")", "[", "\\lbrack", "]", "\\rbrack",
+    "(", "\\lparen", ")", "\\rparen",
+    "[", "\\lbrack", "]", "\\rbrack",
     "\\{", "\\lbrace", "\\}", "\\rbrace",
     "\\lfloor", "\\rfloor", "\u230a", "\u230b",
     "\\lceil", "\\rceil", "\u2308", "\u2309",
diff --git a/src/symbols.js b/src/symbols.js
index 916cedbf..a589ef36 100644
--- a/src/symbols.js
+++ b/src/symbols.js
@@ -625,6 +625,8 @@ defineSymbol(math, main, open, "[", "\\lbrack");
 defineSymbol(text, main, textord, "[", "\\lbrack");
 defineSymbol(math, main, close, "]", "\\rbrack");
 defineSymbol(text, main, textord, "]", "\\rbrack");
+defineSymbol(math, main, open, "(", "\\lparen");
+defineSymbol(math, main, close, ")", "\\rparen");
 defineSymbol(text, main, textord, "<", "\\textless"); // in T1 fontenc
 defineSymbol(text, main, textord, ">", "\\textgreater"); // in T1 fontenc
 defineSymbol(math, main, open, "\u230a", "\\lfloor", true);


Test patch:
diff --git a/test/katex-spec.js b/test/katex-spec.js
index b4cb6ba9..c227a37f 100644
--- a/test/katex-spec.js
+++ b/test/katex-spec.js
@@ -1198,6 +1198,7 @@ describe("left/right builder", () => {
     const cases = [
         [r`\left\langle \right\rangle`, r`\left< \right>`],
         [r`\left\langle \right\rangle`, '\\left\u27e8 \\right\u27e9'],
+        [r`\left\lparen \right\rparen`, r`\left( \right)`],
     ];
 
     for (const [actual, expected] of cases) {