# How is automatic indentation done for subfiles with arara and latexindent?

I guess that I have overlooked something, but I can't find a solution to run arara on my subfiles when processing my main file. I would like to autoindent my code but only succeed for the main.tex.

I installed latexindent.plx which works great. If I run % arara: indent: { overwrite : yes } on a single file document, everything works like expected.

In my actual documents the main.tex will look like this:

% arara: lualatex: { shell: yes }
% arara: indent: { overwrite : yes }
% arara: indent: { trace : yes }
\begin{document}
\include{chapter/foo}
\end{document}


For this solution, I get main.tex indented beautifully but not the header and not the chapters. As arara is looking for commands all over the source, I added another % arara: indent: { overwrite : yes } on top of some subfiles, but they don't effect the process. I would be glad for a hint, where my thinking error is.

• This is the first latexindent question- thanks very much for trying it :) I'll do some experiments and get back to you, I have an idea on what to try :) – cmhughes Aug 8 '13 at 12:39

First of all, thanks very much for trying latexindent :)

Your question is pretty much exactly the same idea as arara: making a rule to compile the main file from a chapter file and the trick is to tell arara which files you want to operate on.

As such, the following works as you want.

% arara: indent: { overwrite : yes, trace: yes, files: [ chapter/foo.tex, header.tex, chapter/bar.tex ]  }

Note that I have combined your two arara indent directives into one, otherwise you're running it twice- this shouldn't be necessary, and should probably be avoided. If latexindent does something wrong on the first pass, then the trace would have told you what happened on the second pass, which wouldn't have been very useful.
• oh that's cool. And beautiful. Works great. Nice feature would be to select all files (or even synced to \includeonly) but at first, it gives good control. main.tex is not indented now so that the annoying "file changed outside your IDE" is not appearing for all files but the selected ones. – LaRiFaRi Aug 8 '13 at 13:17
• @LaRiFaRi glad it worked. You can certainly run latexindent on a list of files- it sounds like you might need to write a batch script of some kind, which will vary depending on your operating system – cmhughes Aug 8 '13 at 14:57
• If it can help someone: the following code applies latexindent to all tex files of the current directory, on a Linux shell: find . -name '*.tex' -exec latexindent -w \$1 -- {} \;. – anderstood May 3 '17 at 1:16