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

  • SEARCH
  • Home
  • 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 7408941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:59:52+00:00 2026-05-29T05:59:52+00:00

I’m using emacs with cdlatex-mode to edit LaTeX files. I would like to know

  • 0

I’m using emacs with cdlatex-mode to edit LaTeX files. I would like to know how to insert a LaTeX environment around a block of text that is already written so that the \begin{} goes before the selected text and the \end{} goes after the selected text. I’ve tried to use cdlatex-environment function but doing so erases the selected text.

  • 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-29T05:59:52+00:00Added an answer on May 29, 2026 at 5:59 am

    AUCTeX

    If you use auctex:

    1. Mark the block of text you want to enclose in an environment.
    2. Press C-c C-e.
    3. Enter an environment type of your choice (you can only type some characters and use tab completion) and press Enter.

    See the manual for details.

    Note that there is a similar method to enclose marked text in macros. Do as 1–3 but instead press C-c C-e or C-c Enter instead. See the manual for details.

    YASnippet

    If you use YASnippet you can create a snippet with similar behavior as above. For example you can use the following (you have replace “keybinding” with a proper keybinding):

    # -*- mode: snippet -*-
    # name: LaTeX environment
    # key: "keybinding"
    # --
    \begin{$1}
      `yas/selected-text`$0
    \end{$1}
    

    If you want a snippet for macros too you can use something like the following:

    # -*- mode: snippet -*-
    # name: LaTeX macro
    # key: "keybinding"
    # --
    \$1{`yas/selected-text`$0}
    

    Elisp

    Even if I recommend the above approaches there might be situations where you want instead to use some simple elisp function. The following is just something rough which has far less functionality than the above approaches:

    (defun ltx-environment (start end env)
      "Insert LaTeX environment."
      (interactive "r\nsEnvironment type: ")
      (save-excursion
        (if (region-active-p)
        (progn
          (goto-char end)
          (newline)
          (insert "\\end{" env "}")
          (goto-char start)
          (insert "\\begin{" env "}") (newline))
          (insert "\\begin{" env "}") (newline) (newline)
          (insert "\\end{" env "} "))))
    

    And for macros if you want that too:

    (defun ltx-macro (start end env)
      "Insert LaTeX macro."
      (interactive "r\nsMacro: ")
      (save-excursion
        (if (region-active-p)
        (progn
          (goto-char end) (insert "}")
          (goto-char start) (insert "\\" env "{"))
          (insert "\\" env "{}"))))
    

    To use them put them in your .emacs and do M-x ltx-environment or ltx-macro respectively.

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

Sidebar

Related Questions

I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I have thousands of HTML files to process using Groovy/Java and I need to
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
I've got a string that has curly quotes in it. I'd like to replace

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.