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.

Is there some way to get rid of the \begin and \end's? For example, I need to type a small matrix, but I should type \begin{matrix}...\end{matrix}. I tried to define a macro

\newcommand{\matx}[1]{\begin{matrix}{{#1}}\end{matrix}}

but it doesn't work. Do you know if there's a LaTeX way to do it? Thank you very much!

share|improve this question
1  
Welcome to TeX.SX! –  egreg Apr 10 at 12:32
    
Note the error is not because of the command definition \begin{matrix}{{1&2}}\end{matrix} would not work either. (But note you can not do this with AMS alignments such as \begin{align}) –  David Carlisle Apr 10 at 13:39
    
use a powerful editor, like vim, for example; it does a lot of the tedious work for you –  cmhughes Apr 10 at 16:32
add comment

3 Answers 3

Just delete the unnecessary braces in your definition.

\documentclass{article}
\usepackage{amsmath}
\newcommand{\matx}[1]{\begin{matrix}#1\end{matrix}}
\begin{document}
\[
\matx{ 1 & 2 \\ 3 & 4 }
\]
\end{document}
share|improve this answer
add comment

I use emacs with AUCTeX and Ctrl-c Ctrl-e will enter the matching pairs automatically. I'm sure vim will have a command that does likewise.

share|improve this answer
2  
Any 1/2-decent+ editor should do this is you really want it, as do many of the TeX-specific IDEs - perhaps the OP should tell us which editor they're using. –  Chris H Apr 10 at 12:45
add comment

I would suggest the following:

\def \bm {\begin{matrix}} 
\def \em {\end{matrix}}

So that you just need to type \bm instead of \begin{matrix}

minimal code

\documentclass{article}
\usepackage{amsmath}
\def \bm {\begin{matrix}} 
\def \em {\end{matrix}}
\begin{document}
\[
\bm
1 & 2 \\ 3 & 4 
\em
\]
\end{document}
share|improve this answer
4  
Overwriting standard commands is not recommended. In any case, it will not work in this case. Did you consider testing this before posting? There is a good reason that answers, as well as questions, should generally include Minimal Working Examples! –  cfr Apr 10 at 22:56
    
This works for me. I just posted the minimal code –  impact27 Apr 12 at 7:43
    
\emph{Emphasise this}. –  cfr Apr 12 at 12:34
add comment

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.