I frequently find myself typesetting algorithms, and I choose the algorithmicx/algpseudocode package for that. I like the package, it is simple to use and has everything I typically need.

The problem (a big inconvenience, actually) is that Emacs (AUCTeX) destroys the indentation inside the algorithmic environment, and that renders the algorithms much harder to read in the LaTeX source.

Is there any (simple) way to tell Emacs to keep the contents of the algorithmic environment with their original indentation while still performing the highlighting of the code?

1 Answer 1


You should customize the variable LaTeX-indent-environment-list to add an entry for algorithmic to be current-indentation. I.e. INS insert new entry, complete with algorithmic for the Environment: and specify current-indentation for Function:. See the Indenting section of the AuCTeX info page for more detail.

Here is a screenshoot of how such customizations look like in the customize interface

Screen shot

  • Thanks for the answer. It worked, but only after I changed the valued of the «Function» field to current-indentation, like it is for the verbatim environment.
    – Jeff
    Oct 3, 2017 at 18:05
  • Thanks for checking this - I wrote current-indentation first and then changed it to ignore, but forgot to retest. Answer updated. Oct 3, 2017 at 18:15
  • @AndrewSwann How can I specify current-indentation or change the «Function» field?
    – alper
    Jan 6, 2022 at 12:53
  • @alper I have now added an image. Does that help? Jan 6, 2022 at 16:20
  • @AndrewSwann Thanks I have added a entry as Environmet: algorithmic Function: current-indentation but it did not make any indent change :-( I have added it as a question to explain my question emacs.stackexchange.com/q/69996/18414
    – alper
    Jan 7, 2022 at 9:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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