Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6952397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:20:39+00:00 2026-05-27T14:20:39+00:00

While this question concerns the formatting of LaTeX within Emacs (and maybe Auctex), I

  • 0

While this question concerns the formatting of LaTeX within Emacs (and maybe Auctex), I believe this can be applied to more general situations in Emacs concerning delimiters like parentheses, brackets, and braces.

I am looking to be able to do the following with Emacs (and elisp), and don’t know where to begin. Say I have:

(This is in parentheses)

With some keybinding in Emacs, I want Emacs to find the matching delimiter to whichever one is by my cursor (something I know Emacs can do since it can highlight matching delimiters in various modes) and be able to change both of them to

\left( This is in parentheses \right)

The delimiters I would like this to work with are: (...), [...], \lvert ... \rvert, \langle ... \rangle, \{ ... \}. What elisp would I need to accomplish this task?

More general ways to handle matching delimiters are welcome.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:20:40+00:00Added an answer on May 27, 2026 at 2:20 pm

    Evaluate the command below in Emacs. After reloading you can put the point (text cursor) immediately after a closing paren. Then do M-x replace-matching-parens to replace the closing ) with \right) and the matching start paren ( with \left(.

    (defun replace-matching-parens ()
      (interactive)
      (save-excursion
        (let ((end-point (point)))
          (backward-list)
          (let ((start-point (point)))
            (goto-char end-point)
            (re-search-backward ")" nil t)
            (replace-match " \\\\right)" nil nil)
    
            (goto-char start-point)
            (re-search-forward "(" nil t)
            (replace-match "\\\\left( " nil nil)))))
    

    The interactive bit indicates that I want a “command”, so it can be executed using M-x. To avoid the cursor ending up in a strange place after execution I’m wrapping the logic in save-excursion. The point jumps back to the opening paren using backward-list and holds on to the start and end positions of the paren-matched region. Lastly, starting at the end and working backwards I replace the strings. By replacing backwards rather than forwards I avoid invalidating end-point before I need it.

    Generalizing this to handle different kinds of delimiters shouldn’t be too bad. backward-list ought to work with any pair of strings emacs recognizes as analogues of ( and ). To add more parenthesis-like string pairs, check out set-syntax-table in this Parenthesis Matching article.

    Use global-set-key to setup a key binding to replace-matching-parens.

    Fair warning: replace-matching-parens is the first elisp command I’ve implemented, so it may not align with best practices. To all the gurus out there, I’m open to constructive criticism.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

G'day, Edit: While this question covers a situation that can arise in programming a
I am aware of this question , but I believe my concerns are very
While answering this question, I got these confusing results: double d = 0.49999999999999990d; //output
While working on this question , I noticed that GCC (v4.7)'s implementation of std::function
Yesterday while going through this question, I found a curious case of passing and
Unlike this question: Linker Error while building application using Boost Asio in Visual Studio
While reading the answers to this question I got a doubt regarding the default
While trying to answer this question I found that the code int* p =
While I realize that this question has been asked once or twice ago but
While trying to answer this question I found without () (which invokes C++ most

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.