1

I want use \def to simplify the \begin{array}. Here is the code

\def\ba#1{\begin{array}#1}
\def\ea{\end{array}}

$$ \ba{ccc} a11 & a12 & a13\\ a21 & a22 & a23 \ea $$

I got error. I try to use:

\renewcommand {\begin{array}} {\ba}
\renewcommand {\end{array}} {\ea}

and this:

\newcommand(\ba)[]{\begin{array}}
\newcommand(\ea)[]{\end{array}}

get error too. So which command I should use?

It is different with programming language I think. Here I want just text substitute \ba instead \begin{array}. It don't need evaluate in macro define.

Update: So I using the same tips to continue simpling:

\bea
 y &=& x^4 + 4      \nonumber \\
   &=& (x^2+2)^2 -4x^2 \nonumber \\
   &\le&(x^2+2)^2
\eea

It work fine. while combine them all:

\newcommand{\sev}[1]{\left| {#1} \right|}
\def\ba#1{\begin{array}{#1}}
\def\ea{\end{array}}
\def\bea{\begin{eqnarray}}
\def\eea{\end{eqnarray}}

Q: $$D=\sev{\ba{cccccc}
 s_0&s_1&s_2&\cdots&s_{n-1}&1\\ 
 s_1&s_2&s_3&\cdots&s_n&x\\ 
 s_2&s_3&s_4&\cdots&s_{n+1}&x^2\\ 
 \vdots&\vdots&\vdots&\ddots&\vdots\\ 
 s_n&s_{n+1}&s_{n+2}&\cdots&s_{2n-1}&x^n \ea}$$ 
 and $s_k=x_1^k+x_2^k+\cdots+x_n^k$.

A: $$ \bea D &=& \sev{\ba{ccccc} 
 1&1&\cdots&1&1\\
 x_1&x_2&\cdots&x_n&x\\ 
 \vdots&\vdots&\ddots&\vdots&\vdots\\ 
 x_1^{n-1}&x_2^{n-1}&\cdots&x_n^{n-1}&x^{n-1}\\ 
 x_1^n&x_2^n&\cdots&x_n^n&x^n \ea} \eea $$

The Q is right, But the A is wrong and tell "Missing \endgroup"

jiamo
  • 113
  • 4
  • Welcome to TeX.SE. – Mico Nov 26 '15 at 08:16
  • Already done. :-) – Mico Nov 26 '15 at 08:23
  • Update the problem. \sev, \ba, '\bea' work fine alone. But combine them together got error. – jiamo Nov 26 '15 at 09:31
  • 1
    You cannot do this with math delimiting environments like eqnarray! You actually shouldn't do this at all. I have never understood why people consider the 20 extra strokes for environments a problem. It takes hours to think out the contents, and then a couple seconds is a problem? And if it is, you should really rather get a TeX editor capable of good auto-complete. Last but not least, note that you hide the document's structure in the code. As a copy editor, I can tell you that dealing with a code like that is then really painful. – yo' Nov 26 '15 at 09:36
  • The problem you describe in your update under "A" has nothing to do with the abbreviations you've. Instead, it occurs because you're trying to initiate an eqnarray after an opening $$ directive. Remove the $$ directives in the "A" portion of the code and it will compile fine. – Mico Nov 26 '15 at 09:47
  • @Mico If I want keep $$. what can I do? – jiamo Nov 26 '15 at 09:52
  • Another comment: Why on earth are you trying to use an eqnarray environment?! This environment is severely deprecated -- there is simply no excuse for using it these days. See the posting eqnarray vs align for more information on this subject. – Mico Nov 26 '15 at 09:52
  • @jiamo - You should not use $$ in a LaTeX document; use \[ and \] instead. No exceptions. By all means, do learn how to use the align environment. – Mico Nov 26 '15 at 09:53
  • Ok. By the way. After remove $$ , and using \def\bea{\begin{align}} it can work like \def\bea{\begin{eqnarray}} – jiamo Nov 26 '15 at 10:14
  • @jiamo - No it won't -- at least not the way you say you're going. More specifically, \bea will work, but \def\eea{\end{align}} will not. See the posting [What is wrong with defining \bal as \begin{align}?](http://tex.stackexchange.com/q/100138/5001), and especially egreg's answer, for information on why\eea`, as defined by you in the preceding comment, will not work. – Mico Nov 26 '15 at 10:26

1 Answers1

2

You need to change

\def\ba#1{\begin{array}#1}

to

\def\ba#1{\begin{array}{#1}}

Observe the pair of curly braces around #1 in the second line of code.

Incidentally, you shouldn't use $$ directly in a LaTeX document to initiate and terminate displaymath mode; use \[ and \] instead. For more information on this subject, see the postings Why is [ ... ] preferable to $$ ... $$? and What are the differences between $$, [, align, equation and displaymath?

Mico
  • 506,678