I want to declare some macros in my preamble which allow me to create 2 x 2 matrices more quickly, and in particular, I want to be able to tab through the four entry positions. I feel like this is super basic and I am missing an obvious solution. Ideally I would like the command to implement smallmatrix and pmatrix.

Thanks in advance!

EDIT: I apologize for the confusion. What I mean was something like \newcommand{\norm}[1]{\left|\left|#1\right|\right|} where the command takes an argument and using tab-completion in TexWorks or enter-completion in Kile will put your cursor in the argument field automatically. I hope this clarification helps!

  • 2
    Please clarify what you mean by "tab through the four entry positions"? Perhaps you are using a smart editor (like emacs auctex) that examines your preamble and does some kind of intelligent autocompletion? – Lev Bishop Aug 17 '10 at 3:44
  • @Lev, sorry I have added a bit to my post for clarification. – BBischof Aug 17 '10 at 16:25

For the matrix macro, I've been using the following, although anything from other commenters will do:

#1 & #2 \\
#3 & #4 \\  

Then \mat{a}{b}{c}{d} produces the matrix with rows (a, b) and (c, d). Insert this in the preamble.

Then you want to enable the autocompletion of this new command. Here is how to do this for TeXworks.

First, locate the file tw-latex.txt in the completion folder TeXworks resource directory; in Ubuntu, it is ~/.TeXworks/completion, on other systems, refer to the manual. Edit it as administrator (it's read-only by default on Linux).

Somewhere in the file (in alphabetical order, ideally), add the following line:


This will add the Tab and Ctrl+Tab autocompletion for your new \mat command.

Alternatively, in TeXworks you can define an autocompletion macro like this:

\mat:=\left(\begin{array}{cc}#INS# & • \\• & • \\ \end{array}\right)#RET#

This will auto-expand \mat to the whole construction. This method has an advantage of working in all TeX documents without you having to define the \mat command in the preamble, or having to include the style file.

However, it is ugly, TeXworks specific, and needs autocomplete (whereas with the \mat defined via \newcommand, you can type it on your own efficiently). Hence this method is probably not preferred in this case, but it still may be useful for other constructions.

To modify autocompletion rules to your liking, refer to this section of the manual.


I'm not sure what you mean by tabbing through the four entries, but the following is a slight modification to what Stefan Kottwitz gave.

  • I think this is exactly what I want! – BBischof Aug 17 '10 at 16:40

Do you mean just shortcuts? Here's one possibility defining commands instead of environments:

\pmat{a & b \\ c & d}
\smat{e & f \\ g & h}
  • I would prefer the commands to take 4 arguments. – BBischof Aug 17 '10 at 16:39
  • 1
    Though, one argument is easier to type and in my opinion more readable. With the braces it's harder to see where the row ends, all arguments look the same, rows cannot be distinguished. If complex matrix entries would have braces too, mistakes could happen easily. Errors because of missing or too much braces happen often and aren't always easy to locate. – Stefan Kottwitz Aug 17 '10 at 16:52

The LaTeX plug-in for gedit, as with most good LaTeX editors, has a macro for tables and matrices. It supports tabbing between the entries. Being a gnome application you can assign any menu item a short-cut just by selecting it then pressing the keys you want. gedit is available for most operating systems.

Texmaker has a spreadsheet-like wizard for creating matrices and tables and is also available for most platforms.

  • Thanks for trying to answer my poorly worded question, but I think TH gave what I was looking for. – BBischof Aug 17 '10 at 16:40

Your Answer

