Saturday, June 18, 2011

cases in latex, absolute value is a standard example

How to make cases in latex

\begin{equation*}
|x|= 
\begin{cases} x & \text{if $x≥0$,}
\\
-x &\text{if $x\le 0$.}
\end{cases}
\end{equation*}

latex stuff about the equal sign


$$
X = ^d Y
$$
This is not a good way to display equal in distribution.

Here is one hack (gotta be a better way). the b here says to put the equal sign on the bottom

$$
3 \begin{array}[b]{c}\alpha\\[-2ex]= \end{array} 5
$$
%b for bottom in \begin{array}[b] to mean the equal sign goes below
% could put it in \be \ee instead of the two dollar signs

latex stuff about the equal sign

$$
X = ^d Y
$$
This is not a good way to display equal in distribution.

Here is one hack (gotta be a better way). the b here says to put the equal sign on the bottom

$$
3 \begin{array}[b]{c}\alpha\\[-2ex]= \end{array} 5
$$
%b for bottom in \begin{array}[b] to mean the equal sign goes below
% could put it in \be \ee instead of the two dollar signs

Tuesday, June 14, 2011

line number correcting in math display - command form

I'd love to make this an environment so I could do begin and end, I couldn't figure this out.

But I do have these options (one acts like equation* the other like eqnarray*)

 %analog for this - begin Line Number; end Line Number
%--------------------------------
\newcommand{\bLN}{\begin{linenomath*} \begin{equation*}}
\newcommand{\eLN}{\end{equation*} \end{linenomath*}}
%--------------------------------






%analog for this - begin Array Line Number; end Array Line Number
%--------------------------------
\newcommand{\baLN}{\begin{linenomath*} \begin{eqnarray*}}
\newcommand{\eaLN}{\end{eqnarray*} \end{linenomath*}}
%--------------------------------
%usage:
%\bLN
%a = b
%\eLN

\baLN
3 &=& 4 \\
&=& 7
\eaLN

Defining your own Environments

You can do this with a hack by defining a new command, e.g. define
 \beq as a short cut for \begin{equation}
and
\eeq as a short cut for \end{equation}

But with a new environment foo you can simply use
\begin{foo}
\end{foo}

Two examples (one is a list so it needs to handle counters):

\newcounter{abc}
\newenvironment{abclist}
   {\begin{list}{(\alph{abc})} {\usecounter{abc}} \setlength{\itemsep}{0pt}
                             
  \setlength{\labelwidth}{4em} }
   {\end{list}}

\newenvironment{solution}{\mbox{}\vspace*{\parskip}\\\sf Solution:}{\rm}
 
Usage:
\begin{abclist}
\item
\item
\item
\end{abclist}

\begin{solution}
Put the solution here
\end{solution}

line numbers. Correction for math display

This problem is described in the style manual
the documentation is attached.
ctan.tug.org/tex-archive/macros/latex/contrib/lineno/ulineno.pdf
From the doc:
lineno.sty does not work well with display math. The parts of a paragraph
preceeding a display math will not get line numbers. The reason is that the
paragraph is not finished, but the part above the display is broken into lines
anyway.

quick answer:
preamble: \usepackage[mathlines]{lineno}
example use in text:
\begin{linenomath*}
$$
\mbox{eff}_i = \frac{X_i - Y_i}{X_i}.
$$
\end{linenomath*}

more complete answer:

\documentclass[11pt]{article}
\usepackage{amssymb,amsmath, amsthm, natbib, subfigure, color,
latexsym, ifthen,commath,setspace}
%\usepackage[draft]{graphicx}
\usepackage{graphicx}
\usepackage{rotating}
%line number has prolems in math mode
\usepackage[mathlines]{lineno}

\begin{document}
\linenumbers

 %example use in text

\begin{linenomath*}
$$
\mbox{eff}_i = \frac{X_i - Y_i}{X_i}.
$$
\end{linenomath*}