Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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!

share|improve this question
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

4 Answers 4

up vote 2 down vote accepted

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

\newcommand{\mat}[4]{\left(
\begin{array}{cc}
#1 & #2 \\
#3 & #4 \\  
\end{array}
\right)
}

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:

\mat{#INS#}{•}{•}{•}#RET#

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.

share|improve this answer

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

\documentclass{article}
\usepackage{amsmath}
\newcommand*{\pmat}[1]{\begin{pmatrix}#1\end{pmatrix}}
\newcommand*{\smat}[1]{\begin{smallmatrix}#1\end{smallmatrix}}
\begin{document}
\[
\pmat{a & b \\ c & d}
\smat{e & f \\ g & h}
\]
\end{document}
share|improve this answer
    
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

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.

\documentclass{article}
\usepackage{amsmath}
\newcommand*\pmat[4]{\begin{pmatrix}#1&#2\\#3&#4\end{pmatrix}}
\newcommand*\smat[4]{\begin{smallmatrix}#1&#2\\#3&#4\end{smallmatrix}}
\begin{document}
\[
\pmat{a}{b}{c}{d}
\smat{e}{f}{g}{h}
\]
\end{document}
share|improve this answer
    
I think this is exactly what I want! –  BBischof Aug 17 '10 at 16:40
1  
then you should mark it as the accepted answer –  Will Robertson Aug 18 '10 at 10:14

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.

share|improve this answer
    
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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.