Math & Sciencehow to use eqnarray in savenewbox

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
matthewwang
Posts: 2
Joined: Thu Jun 28, 2012 9:23 am

how to use eqnarray in savenewbox

Post by matthewwang »

Hi, I am trying to use \savenewbox to get the baseline when I use latex to generate png images from latex equation, but I always get failure when the equation are wrapped with \begin{eqnarray} and \end{eqnarray}, the follow is content one of the failed sample tex file:

Code: Select all

\documentclass[10pt]{article}
\usepackage{geometry}
\usepackage{empheq}
\usepackage{amssymb,amsmath,bm,color} 
\usepackage[latin1]{inputenc} 
\pagestyle{empty}
				
\newsavebox{\mybox}
\newlength{\mywidth}
\newlength{\myheight}
\newlength{\mydepth}
				
\setlength{\topskip}{0pt}
\setlength{\parindent}{0pt}
\setlength{\abovedisplayskip}{0pt}
\setlength{\belowdisplayskip}{0pt}
				
\begin{lrbox}{\mybox}
$\displaystyle
\begin{eqnarray}
5 + 0 &=& 5\\4 + 1 &=& 5\\3 + 2 &=& 5\\2 + 3 &=& 5\\1 + 4 &=& 5\\5 + 0 &=& 5
\end{eqnarray}
$
\end{lrbox}
				
\settowidth {\mywidth}  {\usebox{\mybox}}
\settoheight{\myheight} {\usebox{\mybox}}
\settodepth {\mydepth}  {\usebox{\mybox}}
				
\newwrite\foo
\immediate\openout\foo=\jobname.sizes
\immediate\write\foo{Depth=\the\mydepth}
\immediate\write\foo{Height=\the\myheight}
\addtolength{\myheight} {\mydepth}
\immediate\write\foo{TotalHeight=\the\myheight}
\immediate\write\foo{Width=\the\mywidth}
\closeout\foo
				
% set the paper-size and do everything in one pdflatex run
\geometry{paperwidth=\mywidth,
paperheight=\myheight,margin=0pt}
				    
\begin{document}
\usebox{\mybox}
\end{document}
my method of getting png image is using latex generate .dvi and .sizes file, then use dvipng command to generate png from .dvi file.
first step command :

Code: Select all

/usr/texbin/latex -output-directory=/Users/matthew/Desktop/latex/dvi -jobname=mytex mytex.tex
second step command :

Code: Select all

/usr/texbin/dvipng -o /Users/matthew/Desktop/latex/png/mytex.png -T tight -D 300 mytex.dvi
this approach is working well on most latex equations but always failed when the equation wrapped with \begin{eqnarray} and \end{eqnarray}, the error message is :

Code: Select all

Missing \endgroup inserted.
<inserted text> 
                \endgroup 
l.21 				\begin{eqnarray}
does anyone have the idea or solution to get rid of this error and make it working? My LaTex version is MacTeX-2011.

Thanks
matthew
Last edited by Stefan Kottwitz on Fri Jun 29, 2012 8:10 am, edited 1 time in total.

Recommended reading 2024:

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

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

josephwright
Site Moderator
Posts: 814
Joined: Tue Jul 01, 2008 2:19 pm

how to use eqnarray in savenewbox

Post by josephwright »

The eqnarray structure is no 'left-right' material (it's display math), and so it cannot go inside a lrbox. You should look at the standalone class to do what you want. (Side note: do not use eqnarray at all! It is defective in many ways, and is only really there for backward-compatibility.)
Joseph Wright
matthewwang
Posts: 2
Joined: Thu Jun 28, 2012 9:23 am

Re: how to use eqnarray in savenewbox

Post by matthewwang »

Hi, Joseph

Thanks for you relay, in my use case, I do really need the box to get some parameters like baseline offset, so is there any alternative to replace the eqnarray or lrbox and generate the png as expect?

cheers
Matthew
Post Reply