4

I am working in TexStudio (2.9.0). I want to change the type of a pair of matching parenthesis. For example,

\command{something (involving (even)(more)parenthesis)}

should become

\command{something [involving (even)(more)parenthesis]}

Note that the parenthesis after something changed from ( ) to [ ].

Am I overlooking a feature of TeXstudio? Might this be possible with user-defined makros?


As a remark: Creation of these parentheses is easily possible by selecting the text and pressing the opening parenthesis of the desired type. So a selected text becomes (text) on pressing (. Unfortunately, there is no way to later change this comfortably to [text].

1 Answer 1

5

Indeed this is possible with a user macro. the key is the function app.jumpToBracket() which stands behind Idefix -> Prentheses -> Jump to Match. If the cursor is at one bracket, it moves to the other.

After placing the cursor before the first bracket, run

%SCRIPT
cursor.deleteChar()
cursor.insertText('[')
app.jumpToBracket()
cursor.deleteChar()
cursor.insertText(']')

That's the basic principle. You may add additional checks that the cursor is really next to a bracket and/or make it work if the cursor is after the bracket (use cursor.deletePreviousChar() instead).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.