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?


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.

  • 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 '17 at 18:05
  • Thanks for checking this - I wrote current-indentation first and then changed it to ignore, but forgot to retest. Answer updated. – Andrew Swann Oct 3 '17 at 18:15

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.