# Indenting style of LaTeX files with Sublime Text

Here is a part of my LaTeX code and what I want it to be:

...
\begin{table}
\begin{tabularx}{\textwidth}{|l|l|l|X|X|X|X|}
...


However, if I re-indent it in Sublime Text 3, it becomes:

...
\begin{table}
\begin{tabularx}{\textwidth}{|l|l|l|X|X|X|X|}
...


Then the folding function is also invalid, how do I fix this? I'm using LaTeXTools.

• Use latexindent – user11232 Mar 10 '14 at 5:53
• which latex plug-in are you using? – Holene Mar 10 '14 at 6:23
• – user11232 Mar 10 '14 at 7:18
• By the way, \begin{center}\begin{table} is wrong. – egreg Mar 10 '14 at 8:32
• Unless I'm mistaken, latexindent isn't available directly as a Sublime Text 3 plugin, though right? – obfuscation May 8 '14 at 9:36

## 2 Answers

You should use the plugin latexindent. Please see here for the documentation and the download.

Here is an example how to use it with arara and how the code looks after the indentation.

% arara: pdflatex
% arara: indent: { overwrite : yes }

\documentclass{article}
\usepackage{tabularx}
\usepackage{booktabs}

\begin{document}
\begin{table}
\centering
\begin{tabularx}{\textwidth}{lllXXXX}
\toprule
l & l & l & X & X & X & X \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}


I found that albertxing's gist worked for me in ST3. To summarize, paste & save as LaTeX/Indentation Rules.tmPreferences in your user profile folder (Sublime's Preferences > Browse Packages > LatexTools). Restart Sublime, highlight all and Edit > Line > ReIndent.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>name</key>
<string>Indentation Rules</string>
<key>scope</key>
<string>text.tex, sources.bib</string>
<key>settings</key>
<dict>
<key>decreaseIndentPattern</key>
<string>(?x)
^\s*\\end\{[^\{\}]+\}.*$| ^\s*\\\].*$
|   ^\s*\}.*
|   ^\s*\%.*$$end$$.*$</string> <key>increaseIndentPattern</key> <string>(?x) ^\s*\\begin\{[^\{\}]+\}(\{.*\}|$.*$)*$
|   ^.*\\\[\s*$| ^.*\\(.+)\{$
|   ^\s*\\((sub)[0,2])?section(\*)?\{.*\}.*\$
</string>
</dict>
<key>uuid</key>
<string>02EB44C6-9203-4F4C-BFCB-7E3360B12842</string>
</dict>
</plist>

• Question. I go into my packages folder and I see LaTeXTools. Does this mean that I would use that folder, or create another folder called 'LaTeX' with a subfolder 'Indentation', and a file Rules.tmPreferences? I'm a complete beginner to Latex, I'm not even sure that I'm using the same plugin that will require this config file – Zach Smith Jul 1 '16 at 17:07