3

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.

1

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}
1

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>
  • 1
    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

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.