How to create a TeXstudio macro to apply "Align Columns" for all matrices I want
After learning about about the command Align Columns
I immediately fell in love with it and created a shortcut (Ctrl + Alt + T
== Alt Gr + T
) to use it in a blink of an eye. So far so good.
Recently I learned I could execute commands with TeXstudio's macros and not just use it to insert predefined text.
At this point I asked if it was possible to automatize the whole Search
and Align Columns
manual procedure.
I found the following infos about it:
- automatic-code-alignment-with-texstudio
- aligning-table-within-latex-editor
- emultiple-find-replace-in-texstudio-using-script-macros
- texstudio/wiki/Scripts/
- usermanual_en.html#SECTION33
Unfortunately, I could not install latexindent
so I must find a way around, and I don't know the syntax enough to create from scratch.
I searched for info and tried some but I have no idea how to perform something like Align Columns
of any shortcut in the MACRO
environment.
The idea is have something like this
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation}
\begin{split}
\begin{pmatrix}
a & b \\
c & d
\end{pmatrix} \\
\begin{bmatrix}
a & b \\
c & d
\end{bmatrix} \\
\begin{Bmatrix}
a & b\\
c & d
\end{Bmatrix} \\
\begin{vmatrix}
a & b \\
c & d
\end{vmatrix} \\
\begin{Vmatrix}
a & b \\
c & d
\end{Vmatrix} \\
\end{split}
\end{equation}
\end{document}
Apply the macro, which sketch I let below
%SCRIPT
options = "g"
scope = editor.document().cursor(0, 0, -1);
editor.find("matrix", options, scope, "");
//eval("AlignColumns");
//eval("Ctrl + Alt + T");
//editor.findNext();
and get the same result as manually go around using Search
(F3
) and Align Columns
(Alt Gr + T
) the whole document.
Adding array
, tabular
, split
, and others environments that use &
would also be something interesting.
latexindent
does much more than just aligning tables and matrices, but I could not install Perl at the computer I use, therefore I asked for a specific workaround. Find a subset of word, apply the command. I don't know how to apply to command via macro.