22

I am a new LaTeX user. How can I auto-indent all my LaTeX code in TeXstudio? Does TeXstudio have an auto function?

andselisk
  • 2,675

4 Answers4

10

There is also Indent and unindent automatically under Options -> Editor -> Indentation Mode.

I understand the author is happy with previous suggestions, but I hope it may help others since this question is pretty close to the top result for certain searches.

Alex
  • 231
  • 1
    I'm still missing a way to make TeXstudio re-format code, for example when I paste code in it does not get auto-formated. – Scolytus Nov 06 '19 at 09:59
  • 2
    @Scolytus: It seems unlikely such a feature currently exists in TeXstudio, unfortunately. There is an open feature request with a comment suggesting a workaround for MikTeX users: https://sourceforge.net/p/texstudio/feature-requests/954/ – Alex Nov 19 '19 at 16:44
1

Here's a workaround if you have a JetBrains IDE, including community editions. You can install a free TeXiFy IDEA plugin. Then start a tex project, which will have a main.tex file, or just create a new LaTeX file in your current coding project. Then copy/paste your TexStudio text, press Command-Alt-L to reformat the file, then copy back.

Unfortunately, the formatting functionality is a bit basic, although you might tinker with the IDE's Code Style settings for LaTeX. Still, it can save time versus manual formatting.

0

Go to Option >> Configure TexStudio >> select "Shortcuts" in left pane

Expand the option "Idefix" in right side pane >>

Here you find the Indent, Unindent. You can assign new shortcut from "Current shortcut" or "Additional Shortcut".

Amartya
  • 143
  • 5
    This is no auto-indent, but only indents the selected text using a shortcut. You could also press TAB and SHIFT+TAB. The question was to auto-indent all code at once. – Jack Miller Feb 05 '19 at 05:37
-1

Use the menu

Idefix > Indent

with selected text.

Sigur
  • 37,330
  • 21
    This is no auto or smart indent, but only indents the whole selected text another level. Doesn't answer the question IMHO. – Elmar Zander Mar 07 '17 at 19:39
  • 1
    This is not the answer to the question, this will just indent the code. This is the exact same as selecting the code and pressing the tab key. – Austin Downey Sep 19 '17 at 02:53
  • @AustinDowney The OP seemed happy with it: https://tex.stackexchange.com/questions/292023/how-can-i-auto-indent-in-texstudio#comment707125_292023 – samcarter_is_at_topanswers.xyz Dec 12 '18 at 02:31
  • @samcarter, I am surprised with negative vote, anyway. I'd like to know definition of auto, without clicking anywhere in the editor. – Sigur Dec 12 '18 at 10:54
  • 1
    @Sigur There are some editors (not sure if there editors for latex, but certainly for other programming languages) that will automatically indent the code as you write. But as I understood the OP's reactions to your solution, I think your method is really what the OP was looking for. (unfortunately I cannot upvote more than once :( ) – samcarter_is_at_topanswers.xyz Dec 12 '18 at 11:05