[TxMt] LaTeX Tidy and code folding with \labels

3 messages
Open this post in threaded view
|

[TxMt] LaTeX Tidy and code folding with \labels

 Hi guys, I guess this is primarily of interest to Rene Schwaiger. A long time ago we discussed LaTeX Tidy, \labels and code folding. I love everything about LaTex Tidy except for the fact that it puts \labels on a separate line to \begin or \end, so when I use code folding all I see is a list of \begins, \ends, \sections and the like, without a \label in sight. Rene pointed me to latextidy.pl, which was the help I needed, and I hacked the file so the code now ends         $string =~ s/({[^}]*}[ \t]*)(\n[ \t]*)(($[^$]*\][ \t]*)*(\\label[ \t]*($[^$]*\][ \t]*)*{[^}]*}[ \t]*)*)\n?[ \t]*/$1$3$2/mg;         $string =~ s/((\\label[ \t]*($[^$]*\][ \t]*)*{[^}]*}[ \t]*)+)(\n[ \t]*)(\\end{[^}]*})/$4$1$5/mg;         $string =~ s/(\\section.*(\\label[ \t]*($[^$]*\][ \t]*)*{[^}]*}[ \t]*))(\S)/$1\n$4/mg;$string =~ s/(?<=\S)[ \t]*(?:\n[ \t]*){0,2}(\\section)/\n\n\n$1/mg;$string =~ s/(?<=\S)[ \t]*(?:\n[ \t]*){0,1}(\\subsection)/\n\n$1/mg; print$string; I’ve been using this for a while now and it has proved fairly reliable. I’ve allowed for optional arguments on \labels, labels pinned to \end (for captioned environments), and insert blank lines before \sections and \subsections. Now when I code fold I see not just the environments but their \labels, which mean something to me. This message is intended in the spirit of giving back. Please feel free to ignore this hack, or try it out, change it, whatever. Regards Robert Milton _______________________________________________ textmate mailing list [hidden email] http://lists.macromates.com/listinfo/textmate
 Hi Robert, > On 29 Nov 2016, at 12:05 , Robert Milton <[hidden email]> wrote: > > Hi guys, > I guess this is primarily of interest to Rene Schwaiger. A long time ago we discussed LaTeX Tidy, \labels and code folding. I love everything about LaTex Tidy except for the fact that it puts \labels on a separate line to \begin or \end, so when I use code folding all I see is a list of \begins, \ends, \sections and the like, without a \label in sight. Rene pointed me to latextidy.pl, which was the help I needed, and I hacked the file so the code now ends > > $string =~ s/({[^}]*}[ \t]*)(\n[ \t]*)(($[^$]*\][ \t]*)*(\\label[ \t]*($[^$]*\][ \t]*)*{[^}]*}[ \t]*)*)\n?[ \t]*/$1$3$2/mg; > $string =~ s/((\\label[ \t]*($[^$]*\][ \t]*)*{[^}]*}[ \t]*)+)(\n[ \t]*)(\\end{[^}]*})/$4$1$5/mg; > $string =~ s/(\\section.*(\\label[ \t]*($[^$]*\][ \t]*)*{[^}]*}[ \t]*))(\S)/$1\n$4/mg; >$string =~ s/(?<=\S)[ \t]*(?:\n[ \t]*){0,2}(\\section)/\n\n\n$1/mg; >$string =~ s/(?<=\S)[ \t]*(?:\n[ \t]*){0,1}(\\subsection)/\n\n$1/mg; > > print$string; > > I’ve been using this for a while now and it has proved fairly reliable. I’ve allowed for optional arguments on \labels, labels pinned to \end (for captioned environments), and insert blank lines before \sections and \subsections. Now when I code fold I see not just the environments but their \labels, which mean something to me. thank you very much for looking into this. I would be very interested in merging your changes! Can you please open a pull request [1] containing your changes at the official GitHub page of the LaTeX bundle [2]? [1]: https://help.github.com/articles/creating-a-pull-request[2]: https://github.com/textmate/latex.tmbundle> This message is intended in the spirit of giving back. Please feel free to ignore this hack, or try it out, change it, whatever. > > Regards > Robert Milton Kind regards,   René _______________________________________________ textmate mailing list [hidden email] http://lists.macromates.com/listinfo/textmate
 Done.On 29 Nov 2016, at 12:17, René Schwaiger <[hidden email]> wrote:Hi Robert,On 29 Nov 2016, at 12:05 , Robert Milton <[hidden email]> wrote:Hi guys,I guess this is primarily of interest to Rene Schwaiger. A long time ago we discussed LaTeX Tidy, \labels and code folding. I love everything about LaTex Tidy except for the fact that it puts \labels on a separate line to \begin or \end, so when I use code folding all I see is a list of \begins, \ends, \sections and the like, without a \label in sight. Rene pointed me to latextidy.pl, which was the help I needed, and I hacked the file so the code now ends $string =~ s/({[^}]*}[ \t]*)(\n[ \t]*)(($[^$]*\][ \t]*)*(\\label[ \t]*($[^$]*\][ \t]*)*{[^}]*}[ \t]*)*)\n?[ \t]*/$1$3$2/mg; $string =~ s/((\\label[ \t]*($[^$]*\][ \t]*)*{[^}]*}[ \t]*)+)(\n[ \t]*)(\\end{[^}]*})/$4$1$5/mg; $string =~ s/(\\section.*(\\label[ \t]*($[^$]*\][ \t]*)*{[^}]*}[ \t]*))(\S)/$1\n$4/mg;$string =~ s/(?<=\S)[ \t]*(?:\n[ \t]*){0,2}(\\section)/\n\n\n$1/mg;$string =~ s/(?<=\S)[ \t]*(?:\n[ \t]*){0,1}(\\subsection)/\n\n$1/mg; print$string;I’ve been using this for a while now and it has proved fairly reliable. I’ve allowed for optional arguments on \labels, labels pinned to \end (for captioned environments), and insert blank lines before \sections and \subsections. Now when I code fold I see not just the environments but their \labels, which mean something to me.thank you very much for looking into this. I would be very interested in merging your changes! Can you please open a pull request [1] containing your changes at the official GitHub page of the LaTeX bundle [2]?[1]: https://help.github.com/articles/creating-a-pull-request[2]: https://github.com/textmate/latex.tmbundleThis message is intended in the spirit of giving back. Please feel free to ignore this hack, or try it out, change it, whatever.RegardsRobert MiltonKind regards, René_______________________________________________textmate mailing list[hidden email]http://lists.macromates.com/listinfo/textmate_______________________________________________ textmate mailing list [hidden email] http://lists.macromates.com/listinfo/textmate