The package easyeqn

Enrico Bertolazzi

Laboratorio di Matematica Applicata e Meccanica Computazionale

Dipartimento di Ingegneria Meccanica e Strutturale Università degli Studi di Trento Mesiano, Trento, Italy

             mailto:enrico.bertolazzi@ing.unitn.it

Abstract—The package easyeqn introduces some equation environments that simplify writing of equations. It uses a syntax similar to the array environment to define the column alignment. The label field is fully customizable. A package option permits to number only those equations that were labeled and referenced. Some additional macros are also included to facilitate typing of formulae. The option “showkeys” modifies the \eqlabel, \eqref and \refeq commands so that the ‘internal’ key is printed.

Contents

1 Some examples with easyeqn 2 2 Use of the EQ environment 2 3 Use of EQS environment 3 4 The \yesnumber command 4 5 Use of EQA environment 5 6 The \eqlabel command 5 7 Sub-numbering 6 8 Use of fleqn and leqno option 7 9 Cosmetic changes 8 10 Additional macros 9

1 Some examples with easyeqn

Load the package using the usual syntax:

      \documentclass{article}
      .
      .
      \usepackage[allnumber,warning,fleqn,leqno,
                  math,showkeys]{easyeqn}
      .
      .

The package introduces the EQ, EQS and EQA environments. The package options are:

allnumber Means that all of the EQ, EQS and EQA environments are numbered. Without that option, only those EQ, EQS and EQA environment that are labeled and referenced are numbered.

warning Causes equations that are labeled but not referenced to be flagged.

fleqn Flushes equation on the left margin.

leqno Writes equation number on the left.

math Define additional macros for mathematics.

showkeys Modifies the \eqlabel, \eqref and \refeq commands so that the ‘internal’ key is printed.

2 Use of the EQ environment

The following input:

   \begin{EQ}\eqlabel{eq:1}
       \frac{x}{y} = z
   \end{EQ}
   \begin{EQ}\eqlabel{eq:2}
       \frac{x}{y} = z
   \end{EQ}
   I will refer only to \eqref{eq:1} or,
   in the old style, \refeq{eq:1}.

produces the following output:

\frac{x}{y} = z  (1)

\frac{x}{y} = z

I will refer only to (1) or, in the old style, 1.

Note that the command \eqlabel is used instead of \label and the reference is done by \eqref or \refeq. The command \refeq produces the same output as \ref, while \eqref uses ( ) for the output.

Remark: Due to the algorithm, in order to obtain the right cross reference, you need to recompile the file 3 times. The use \label is not permitted inside EQx environments and if you use \ref for referencing equations the results are unpredictable.

3 Use of EQS environment

The following commands:

   \begin{EQS}[rcll]
      \nabla\cdot(\rho\nabla u)&=&f \qquad
         &\mbox{on $\Omega$} \\
      u&=&u_{0}&\mbox{on $A\subset\partial\Omega$} \\
      (\rho\nabla u)\cdot n&=&u_{1}
         &\mbox{on $B\subset\partial\Omega$}
   \end{EQS}

produces

∇ · (ρ∇u) = f  on Ω
u = u_{0}  on A ⊂ ∂Ω
(ρ∇u) · n = u_{1}  on B ⊂ ∂Ω

Note that between [...] you can specify the column alignment in the same way as in the array or tabular environment. The permitted alignment are l for left alignment, r for right alignment and c for centering. There is also the character “.” that used between definition of two columns disable the spacing between columns as in the following example taken from the documentation of eqnarray of Roland Winkler;

   \begin{EQS}[rcl.l]
       \phi & = & \sum \bigg( & \frac{xxxxxxxxxx}{\phi} \\
           & & & + \frac{yyyyyyyyyy}{\phi} \bigg) \\
           & = & \eqmulticol{2}{l}{\frac{zzzzzzzzzz}{\phi}}
   \end{EQS}

ϕ = ∑ (\frac{xxxxxxxxxx}{ϕ}

+\frac{yyyyyyyyyy}{ϕ} )

= \frac{zzzzzzzzzz}{ϕ}

in this example we have used also the command \eqmulticol the sintax is the following

   \eqmulticol{ncol}{align}{body}

where

ncol is the number of column to fuse.

aling is the alignment, it can be l, r, c.

body is the thing to put across the column.

4 The \yesnumber command

If you want to number an equation without reference it, use the \yesnumber command as this example shows:

   \begin{EQS}[rcl]\yesnumber
        a & = & \frac{1}{23} \\
        b & = & \sqrt{\frac{1}{23}}
   \end{EQS}

produces

\begin{aligned}a & = & \frac{1}{23} \\ b & = & \sqrt{\frac{1}{23}} \end{aligned} (2)

5 Use of EQA environment

The following commands:

   \begin{EQA}[rcll]
      \nabla\!\cdot\!(\rho\nabla u)&=&f \qquad
         &\mbox{on $\Omega$}
      \yesnumber \\
      u&=&u_{0}&\mbox{on $A\subset\partial\Omega$}
             \eqlabel{eq:3} \\
      (\rho\nabla u)\!\cdot\!n&=&u_{1}
          &\mbox{on $B\subset\partial\Omega$}
             \eqlabel{eq:4}
   \end{EQA}
   it is referenced only \eqref{eq:4}!!

produce

∇·(ρ∇u) = f  on Ω  (3)
u = u_{0}  on A ⊂ ∂Ω
(ρ∇u)·n = u_{1}  on B ⊂ ∂Ω  (4)

it is referenced only (4)!!

Note that only the referenced lines or the lines with \yesnumber are numbered.

6 The \eqlabel command

It is possible to use custom label by \eqlabel command. The syntax is the following

     \eqlabel`[*]'{labelname}
     or
     \eqlabel`(*)'{labelname}

where `[*]' is an optional argument. If `[*]' is defined, equation displays `*' instead of `(equation number”)’”. The equation counter is not advanced and `labelname' will refer to `*'. If we use `[*]' the result is similar but the equation number is substituted by `(*)' instead of `*'. Look at this example:

   \begin{EQA}[c]
      \nabla\cdot(\rho\nabla u) = 0
          \eqlabel(eq.1){eq:custom:a} \\
      \nabla\cdot(\rho\nabla u) = 0
          \eqlabel[eq.2]{eq:custom:b} \\
      \nabla\cdot(\rho\nabla u) = 0
          \eqlabel[(((1)))]{eq:custom:c}
   \end{EQA}
   I will refer to \eqref{eq:custom:a} and \eqref{eq:custom:b}

produces

∇ · (ρ∇u) = 0  (eq.1)
∇ · (ρ∇u) = 0  eq.2
∇ · (ρ∇u) = 0  (((1)))

I will refer to (eq.1) and (eq.2)

Notice that custom label are always displayed also if not referenced.

7 Sub-numbering

To sub-number equation instead of use something like

    \begin{subequations}
    \begin{EQS}...
    \end{EQS}
    \end{subequations}

I prefer to use \eqlabel command with the character ~ as a shortcut for \theequation. The following exmaple shows the use

\begin{EQA}[c]\yesnumber
\nabla\cdot(\rho\nabla u) = 0 \eqlabel(~.A){eq:sub:a} \\
\nabla\cdot(\rho\nabla u) = 0 \eqlabel(~.B){eq:sub:b} \\
\nabla\cdot(\rho\nabla u) = 0 \eqlabel(~.C){eq:sub:c}
\end{EQA}

∇ · (ρ∇u) = 0  (5.A)
∇ · (ρ∇u) = 0  (5.B)
∇ · (ρ∇u) = 0  (5.C)

the \yesnumber command is necessary to enforce advancing of equation counter.

8 Use of fleqn and leqno option

You can use fleqn to flux left the equations or leqno to number equations on the left. If for example we have used

\documentclass{article}
.
.
\usepackage[fleqn,leqno]{easyeqn}
.
.

the effect with this example:

\begin{EQA}[rcll]
\nabla\cdot(\rho\nabla u)&=&f \qquad
   &\mbox{on $\Omega$}\yesnumber \\
u&=&u_{0}&\mbox{on $A\subset\partial\Omega$}
   \yesnumber\\
(\rho\nabla u)\!\cdot\!n&=&u_{1}
   &\mbox{on $B\subset\partial\Omega$}
     \eqlabel{eq:5}
\end{EQA}
it is referenced only \eqref{eq:5}!!

is the following

(6) ∇ · (ρ∇u) = f  on Ω
(7) u = u_{0} on A ⊂ ∂Ω
(8) (ρ∇u)·n = u_{1}  on B ⊂ ∂Ω

it is referenced only (8)!!

The same effect can be obtained everywhere using the commands \equationleft and \numberleft before defining the equation. To restore the default use \equationcenter and \numberright after the equation.

9 Cosmetic changes

It is possible to modify a little the appearance of the equations. There are three parameter that it is possible to change left indent When the equations are fluxed left, the left indent (default

\leftmargini) can be changed by the command

         \eqleftmargin{new indent}
         for example
         \eqleftmargin{1cm}

equation spacing The spacing around a formula, (default 7pt) can be changed

by the command

         \eqspacing{new spacing}
         for example
         \eqspacing{4pt}

column spacing The spacing between column in multicolumn equations (de-

fault 4pt) can be changed by the command

         \eqcolumnsep{new spacing}
         for example
         \eqcolumnsep{10pt}

row spacing The spacing between rows in multiple equations (default 7pt) can be changed by the command

     \eqrowsep{new spacing}
     for example
     \eqrowsep{10pt}

for example

\eqrowsep{20pt}
\eqcolumnsep{10pt}
\eqspacing{1cm}
bla bla bla bla bla bla bla bla bla bla bla bla
\begin{EQS}[rcll]
   \nabla\cdot(\rho\nabla u)&=&f \qquad
      &\mbox{on $\Omega$} \\
   u&=&u_{0}&\mbox{on $A\subset\partial\Omega$} \\
   (\rho\nabla u)\cdot n&=&u_{1}
      &\mbox{on $B\subset\partial\Omega$}
\end{EQS}
bla bla bla bla bla bla bla bla bla bla bla bla

produces

bla bla bla bla bla bla bla bla bla bla bla bla

∇ · (ρ∇u) = f  on Ω

u = u_{0}  on A ⊂ ∂Ω

(ρ∇u) · n = u_{1}  on B ⊂ ∂Ω

bla bla bla bla bla bla bla bla bla bla bla bla

10 Additional macros

Using the package as follow

\documentclass{article}
.
.
\usepackage[...,math]{easyeqn}
.
.

we can use additional macros for typesetting mathematics, the following macros are defined \frac, \dfrac, \tfrac, \binom and \boxed which use is decribed in the following example:

 \begin{EQS}[rclrcl]
     \frac[1pt]{\frac{1}{2}}{\frac{1}{2}}
     & = & \frac{\frac{1}{2}}{\frac{1}{2}} \qquad &
     \dfrac{\frac{1}{2}}{\frac{1}{2}}
     & = & \dfrac{\frac[0pt]{1}{2}}{\frac{1}{2}} \\
    \tfrac{1}{2} &=& \frac{1}{2}\qquad &
    \binom{n-1}{n-k} && \boxed{a+b}
 \end{EQS}

\begin{aligned}\frac{\frac{1}{2}}{\frac{1}{2}} & = & \frac{\frac{1}{2}}{\frac{1}{2}} & \frac{\frac{1}{2}}{\frac{1}{2}} & = & \frac{{1 \atop 2}}{\frac{1}{2}} \\ \frac{1}{2} & = & \frac{1}{2} & \binom{n − 1}{n − k} & & a + b \end{aligned}

The macro \eqbox is defined, the effect is the following

 \[ \eqbox{1+\dfrac{1}{2}} \qquad
    \eqbox(1pt,20pt){1+\dfrac{1}{2}} \qquad
    \eqbox(5pt,5pt){1+\dfrac{1}{2}} \]

1 + \frac{1}{2}  1 + \frac{1}{2}  1 + \frac{1}{2}

The macros \norm and \abs are defined, the effect is the following

\[ \norm{A}, \qquad \abs{A} \]

∥A∥ , |A|

The macro \ParDer is defined, the effect is the following

\[ \ParDer[xyyz]{f(x,y,z)} \]
\[ \ParDer[{x^{2}}{x^{2}}{x^{2}}y\alpha]{f(x,y,z)} \]

\frac{∂^{4}f(x, y, z)}{∂x∂y^{2}∂z}

\frac{∂^{5}f(x, y, z)}{∂x^{2}^{3}∂y∂α}

notice that single item of derivative must be a single letter (or a macro) or must be inside a group { ... }. If you use \ParDer with package easyvector remember to put macros in brace when use “[ ]” as follows:

\usepackage[definevectors]{easyvector}
.
.
.
\[ \ParDer[\xx\xx{\xx[i,j]}\yy]{f(x,y,z)} \]

x, x_{i,j} = \frac{∂^{4}f(x, y, z)}{∂x^{2}∂x_{i,j}∂y}

otherwise you obtain strange think like the following

\[ \ParDer[\xx\xx\xx[i,j]\yy]{f(x,y,z)} \]

\frac{∂^{7}y}{∂x^{3}∂[∂i∂,∂j}]f(x, y, z)

The macros \DIV, \GRAD and \LAPLA are defined, the effect is the following

\[ \DIV{A}, \qquad \GRAD{B}, \qquad \LAPLA{C} \]

∇ · A,  ∇B,  ΔC

The macro \SUM is defined, the effect is the following

\[ \SUM{i=1}{100}a_{i},\quad \SUM[10]{i=1}{100}a_{i}\]

∑_{i=1}^{100} a_{i}, ∑_{i=1}^{100}^{(10)}a_{i}

The macro \PROD is defined, the effect is the following

\[ \PROD{i=1}{100}a_{i},\quad \PROD[10]{i=1}{100}a_{i}\]

∏_{i=1}^{100} a_{i}, ∏_{i=1}^{100}^{(10)}a_{i}

The environment ARRAY is defined, is a simple subset of the environment array with a different spacing; look the following example

\[
\left(\begin{array}{cc}
  1        & \frac{1}{2} \\
\sqrt{3} & \frac{2}{\sqrt{3}}
\end{array}\right), \qquad
\left(\begin{ARRAY}{cc}
  1        & \frac{1}{2} \\
\sqrt{3} & \frac{2}{\sqrt{3}}
\end{ARRAY}\right),
\]

( \begin{matrix}1 & \frac{1}{2} \\ \sqrt{3} & \frac{2}{\sqrt{3}} \end{matrix} ) ,  (\begin{matrix}1 & \frac{1}{2} \\ \sqrt{3} & \frac{2}{\sqrt{3}} \end{matrix}) ,

The environment MATRIX is defined, is a simple replacement of matrix command with a different spacing; look the following example

\[
\matrix{
  1        & \frac{1}{2} \cr
  \sqrt{3} & \frac{2}{\sqrt{3}}
}, \qquad
\begin{MATRIX}
  1        & \frac{1}{2} \cr
  \sqrt{3} & \frac{2}{\sqrt{3}}
\end{MATRIX},
\]

\begin{matrix}1 & \frac{1}{2} \\ \sqrt{3} & \frac{2}{\sqrt{3}} \end{matrix} , \begin{matrix}1 & \frac{1}{2} \\ \sqrt{3} & \frac{2}{\sqrt{3}} \end{matrix} ,