10

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 }
\input{header}
\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.

LaRiFaRi
  • 43,807
  • 1
    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 08 '13 at 12:39

1 Answers1

9

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 ]  }
\input{header}
\begin{document}
\include{chapter/foo}
\end{document}

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.

cmhughes
  • 100,947
  • 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 08 '13 at 13:17
  • For a cool "let me indent all your source code for you with the cool tool I found", this solution is a bit unwieldy. I am just thinking of all my .tikz and mydefs.tex-files... – LaRiFaRi Aug 08 '13 at 13:27
  • @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 08 '13 at 14:57
  • Thank you. I think I am fine for the moment. Maybe IDEs like TC will adapt your script some time... Would be cool. – LaRiFaRi Aug 09 '13 at 10:32
  • 2
    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 03 '17 at 01:16
  • @DiaaAbidou no problem :) when I click on https://github.com/cereda/arara/blob/master/rules/indent.yaml it takes me to a valid file -- have I misunderstood? – cmhughes Aug 12 '17 at 14:53
  • 1
    No problem :) feel free to contact me at GitHub if ever you'd like to chat about latexindent:) – cmhughes Aug 12 '17 at 19:29
  • @cmhughes You probably know that but when using intervals of the for [a,b), latexindent fails. Now I'm using the package interval so it no longer matters for me. Apart from that, would you know how to indent all files in a folder, using arara (and not the command I posted three comments above)? – anderstood Sep 21 '17 at 19:49
  • @anderstood could you post a complete example in which latexindent.pl fails at https://github.com/cmhughes/latexindent.pl/issues. I'm not sure how to translate your command into arara, that sounds like it could be a new question :) – cmhughes Sep 21 '17 at 19:57