I am a new LaTeX user. How can I auto-indent all my LaTeX code in TeXstudio? Does TeXstudio have an auto function?
-
See the Idefix menu. – Sigur Feb 09 '16 at 16:30
-
I am assuming, that you have TeXstudio in mind. If not, please roll my edition back. – Przemysław Scherwentke Feb 09 '16 at 16:32
-
I am trying to find this function in all menu but I don't find it! I have TexStudio 2.10.4 on Windows – Luca Angelino Feb 09 '16 at 16:46
-
@Sigur in Idefix menu I don't find this function – Luca Angelino Feb 09 '16 at 16:48
-
@LucaAngelino, don't you have Idefix>Indent? – Sigur Feb 09 '16 at 16:50
-
Oh yesss! I had the italian language and there is a types in the word translate: ident – Luca Angelino Feb 09 '16 at 17:06
-
@Sigur Can you make that into an official answer? – Johannes_B Jul 24 '16 at 07:30
-
@Johannes_B, done! – Sigur Jul 25 '16 at 11:45
-
Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. – samcarter_is_at_topanswers.xyz Jan 12 '17 at 16:49
-
Also it is almost duplicate with this https://tex.stackexchange.com/questions/327361/texstudio-keyboard-shortcut-to-auto-indent-latex-code that asks for shortcut and have not been answered but have a useful comment. – koleygr Sep 04 '17 at 20:57
-
2Take a look at latexindent – cmhughes Sep 28 '17 at 20:37
4 Answers
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.
- 231
-
1I'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
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.
- 173
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".
- 143
-
5This 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
Use the menu
Idefix > Indent
with selected text.
- 37,330
-
21This 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
-
1This 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