Math & ScienceArrays in plain TeX

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
tex_eugene
Posts: 4
Joined: Sat Apr 14, 2012 11:29 am

Arrays in plain TeX

Post by tex_eugene »

I don't think the environment {array} is being defined in TeX, can someone help me to translate the following LaTeX to TeX please?

Code: Select all

\[
  f(n) = \left\{ 
  \begin{array}{l l}
    n/2 & \quad \text{if $n$ is even}\\
    -(n+1)/2 & \quad \text{if $n$ is odd}\\
  \end{array} \right.
\]
Thank you!
Last edited by localghost on Mon Apr 16, 2012 9:08 am, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Arrays in plain TeX

Post by Stefan Kottwitz »

You could use \halign for producing tables, such as

Code: Select all

\halign{#&#\cr
  one   & two \cr
  three & four \cr}
\end
Stefan
LaTeX.org admin
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Arrays in plain TeX

Post by cgnieder »

You might want to take a look in the texbook, especially chapters 17--20.

The following MWE

Code: Select all

$$
 f(n) = \cases{
   n/2      &\quad if $n$ is even \cr
   -(n+1)/2 &\quad if $n$ is odd \cr
 }
$$
\bye
gives
tex_cases.png
tex_cases.png (5.13 KiB) Viewed 4811 times
Regards
site moderator & package author
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Re: Arrays in plain TeX

Post by Stefan Kottwitz »

Very good point! In the specific case it's the shortest way. I just wonder why plain TeX is required, which can be difficult if LaTeX's and amsmath's capabilties were desired.

Stefan
LaTeX.org admin
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Arrays in plain TeX

Post by cgnieder »

I wonder that, too. The only time I use plain TeX is when I'm intrigued to learn basic concepts of TeX or when I'm trying to understand underlying concepts of some LaTeX (kernel) code. This means: very seldomly... :(
site moderator & package author
Post Reply