# Put parentheses around selection

**URL:** <https://community.wolfram.com/t/put-parentheses-around-selection/13369>\
**Category:** Questions\
**Created:** [November 28, 2018, 4:42pm UTC](https://community.wolfram.com/t/put-parentheses-around-selection/13369 "2018-11-28T16:42:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![udibehar](https://avatars.discourse-cdn.com/v4/letter/u/eb8c5e/32.png) [@udibehar](https://community.wolfram.com/u/udibehar)\
**Post date:** [November 28, 2018, 4:42pm UTC](https://community.wolfram.com/t/put-parentheses-around-selection/13369/1 "2018-11-28T16:42:35Z")

</div>

Hello  
Suppose I wrote an expression, such as `xy`.  
Pressing `Ctrl`+`.` , I can select the expression.  
Now I want to put this expression in parentheses:

```
(xy)

```

This option works for putting a squre-root sign around an expression, by pressing `Ctrl`+`2`.  
What I am looking for is an equivalent shortcut for bracket, or the parentheses, punctuation mark.

---

<div class="post-metadata">

**Author:** ![gianlucagorni](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@gianlucagorni](https://community.wolfram.com/u/gianlucagorni)\
**Post date:** [November 29, 2018, 7:26am UTC](https://community.wolfram.com/t/put-parentheses-around-selection/13369/2 "2018-11-29T07:26:12Z")

</div>

I personally do that by adding this command to the file `KeyEventTranslations.tr` file inside `EventTranslations[{`

```
(* Matching parentheses*)
Item[KeyEvent["9",Modifiers->{Command,Shift}],
    FrontEndExecute[FrontEnd`NotebookApply[FrontEnd`InputNotebook[],
      "(\[SelectionPlaceholder])", Placeholder]]]

```

However, this is _not_ documented or recommended by Wolfram, and the functionality may not be maintained in future releases. The analogous command for adding `[]` or `{}` or `""` used to work some years ago but has deteriorated over time. The file is in the directory ~/Library/Mathematica/SystemFiles/FrontEnd/TextResources/Macintosh/ on my system, and was copied there from the parent unmodified file in the main Mathematica directory.

---

<div class="post-metadata">

**Author:** ![kubapod](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/kubapod/32/18662_2.png) [@kubapod](https://community.wolfram.com/u/kubapod)\
**Post date:** [November 29, 2018, 9:48am UTC](https://community.wolfram.com/t/put-parentheses-around-selection/13369/3 "2018-11-29T09:48:22Z")

</div>

Limitations and problems with .tr files made me create live templates see [**community post**](https://wolfram.discourse.group/t/11882/1) or [**mm.se post**](https://mathematica.stackexchange.com/q/164653/5478).

Once installed you can set package’s stylesheet or add templates menu to all notebooks by:

```
SetOptions[$FrontEnd, NotebookEventActions -> {
     {"MenuCommand", "InsertNewGraphic"} :> Block[{$ContextPath}
        , Needs["DevTools`"] ; DevTools`OpenNotebookMenu["CodeTemplates"]
        ]
      , ParentList
      }
    ]

```

and you are ready to go, with a caret just after the symbol you can hit Ctrl+1 followed by ( and wrapped:

![parenth.gif](https://global.discourse-cdn.com/wolfram/original/3X/e/1/e15111bad58138895515a3552005c1e0e9d8022d.gif)

---

<div class="post-metadata">

**Author:** ![jasonb](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/jasonb/32/20741_2.png) [@jasonb](https://community.wolfram.com/u/jasonb)\
**Post date:** [November 29, 2018, 3:24pm UTC](https://community.wolfram.com/t/put-parentheses-around-selection/13369/4 "2018-11-29T15:24:50Z")

</div>

This is pretty simple to do without modifying any existing settings. After you’ve selected what you want wrapped in parentheses, just hit Ctrl-6 then Delete (or Backspace). It’s not a single shortcut, but I’ve been using it for years and don’t find it cumbersome.

![Nov-29-201809-24-06.gif](https://global.discourse-cdn.com/wolfram/original/2X/9/94ce2ffdbc05c936cf23989e26ca78125a3ddb00.gif)

---

<div class="post-metadata">

**Author:** ![gdelfino](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/gdelfino/32/41294_2.png) [@gdelfino](https://community.wolfram.com/u/gdelfino)\
**Post date:** [November 29, 2018, 10:00pm UTC](https://community.wolfram.com/t/put-parentheses-around-selection/13369/5 "2018-11-29T22:00:32Z")

</div>

I am pretty sure this was available in Mathematica 2.2, but it was removed from the GUI. This is still available as a FrontEndToken. I have a palette that activates it:

```
Button["(\[SelectionPlaceholder])",  
 FrontEndExecute[
  FrontEndToken[SelectedNotebook[], "SelectionParenthesize"]]]

```

In modern text editors like Sublime Text and Atom, when you have someting selected and type “(” the selection is parentized instead of replaced. I wish this behabior was adepted by Mathematica (and also for “{” and “[”).

**Related** : [https://mathematica.stackexchange.com/questions/84720/parenthesize-what-i-have-highlighted](https://mathematica.stackexchange.com/questions/84720/parenthesize-what-i-have-highlighted)

---

<div class="post-metadata">

**Author:** ![udibehar](https://avatars.discourse-cdn.com/v4/letter/u/eb8c5e/32.png) [@udibehar](https://community.wolfram.com/u/udibehar)\
**Post date:** [December 2, 2018, 9:43am UTC](https://community.wolfram.com/t/put-parentheses-around-selection/13369/6 "2018-12-02T09:43:53Z")

</div>

Thanks a lot for all of the comments. I am sure about to adopt one of them.
