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 7042847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:13:04+00:00 2026-05-28T02:13:04+00:00

My problem is that I am writing a LaTeX document in emacs that has

  • 0

My problem is that I am writing a LaTeX document in emacs that has a lot of C code in it. I am using both the \minted and the \verbatim environments in various places. When I compile the LaTeX (using pdflatex), the resulting pdf looks fine. In the raw LaTeX code, I would like to be able to auto-indent using the rules of the C-major mode.

For example, I want to be able to mark the following region

\begin{verbatim} 

void main(void)
{
printf("Hello World \n\r");
}

\end{verbatim}

And have emacs auto-format it to look like

\begin{verbatim}

void main(void)
{
    printf("Hello World \n\r");
}

\end{verbatim}   

In other words, I want to be able to run indent-region on the part that is actually C code using the rules from C mode, even though I am in LaTeX mode.

Does anyone know if this is possible?

  • 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-28T02:13:04+00:00Added an answer on May 28, 2026 at 2:13 am

    Here’s a quick fix. With a bit of work you could make this general – i.e., check for the current major-mode, and switch back to that mode after you’re done. As is, it switches to c-mode, indents, then switches to LaTeX-mode (AucTex), which solves the immediate problem:

    (defun indent-region-as-c (beg end)
      "Switch to c-mode, indent the region, then switch back to LaTeX mode."
      (interactive "r")
      (save-restriction
        (narrow-to-region beg end)
        (c-mode)
        (indent-region (point-min) (point-max)))
        (LaTeX-mode))
    

    Bind that to your favourite key and you should be all set.

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

Sidebar

Related Questions

I am writing my MSc with LaTeX and I have the problem that sometimes
I have a problem that output string must be utf8-formatted, I am writing currently
I have a problem with writing a catch clause for an exception that is
I'm currently writing a Java app that interfaces with a MySQL database. My problem
I'm writing a custom text-to-speech program that uses SAPI 5, and one problem I'm
I have a problem, that I can't solve. I am writing an application that
I'm writing a LaTeX document in vim, and I have it hard wrapping at
I am writing a Web application that has a user interface for editing data.
I'm writing a JavaSCript class that has a method that recursively calls itself. Scheduler.prototype.updateTimer
Complete LaTeX and LyX newbie here. I am currently writing a document in LyX

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.