I have been told that there was a way to use text within eqnarray
; however, I have not been able to find or create any workable code. Any help is appreciated.
[Tex/LaTex] Using Text in `eqnarray`
equations
Related Solutions
eqnarray does not seem to be easily possible, but normal equations may be and the array environment makes it possible to include multi-line equations. here is an example. start with
\documentclass[border={5pt 5pt 5pt 5pt}]{standalone}
% left bottom right top . warning: does not understand ex or em
\RequirePackage[T1]{fontenc}
\RequirePackage{textcomp}
\RequirePackage{charter}
\RequirePackage[mdbch,ttscaled=true]{mathdesign}
\usepackage{microtype}
\usepackage[english]{babel}
\pagestyle{empty}
\begin{document}
\LARGE
$ \begin{array}{cccc}
y &=& \frac{\sqrt{x}}{z}\\
&& + \frac{\sqrt{z}}{x} \end{array} $
\end{document}
then
$ latex test.tex
$ dvisvgm -n test.dvi
will create an svg file. without the -n, the quality is lousy. with it, it is pretty good. (thx, martin). the array is a math-mode eqnarray substitute that is quite workable--and can align more than just two.
the example does not have the equation line numbering. presumably, one could easily do this with a float:right on a numbering.
this example produces an svg file of about 4KB. even with 100 equations, we are still looking at an html file that is an order of magnitude smaller than one with mathjax included. it should also work in epub, although I have not tested it yet. mathjax is advantageous if it has already been loaded and cached by the browser.
I am enclosing a basic perl hack that translates an html file with dependency on mathjax into one without it. it has baseline problems and probably a couple of other bugs. but it is a starting point.
#!/usr/bin/perl -w
use 5.010;
use strict;
use warnings FATAL => qw{ uninitialized };
=pod
=head1 Title
htmltexmath2svg.pl --- replaces mathjax-style eqns in html files with inline svg images
(to remove dependency on mathjax)
=head1 Requirements
texlive or equivalent (with latex and dvisvgm)
Perl6::slurp
Unix type OS (OSX or linux)
=head1 Output
the output will be a file with -svg before the file extension,
where all mathjax equations have been replaced with svg.
you should define a span class of mathsvg and mathsvgblock for \(..\) and \[..\]
the basic creation file is attached in the __DATA__ section and can be fixed up.
=head1 Bugs
this program still has baseline alignment problems.
this is a hack. probably many bugs. as I use this program, I will
probably update and fix various issues. It has worked on some simple
sample files. parsing could be more intelligent.
we overwrite temp.* files every time, and do not clean up after ourselves.
the program is slow, but one should run it only rarely anyway.
=head1 Versions
0.0: Sat Jan 18 15:32:02 2014, Ivo Welch. no copyright claim. free further distribution.
=cut
################################################################
use Perl6::Slurp; ## only dependency
################################################################
my $usage= "usage: $0 filename.*ml ... creates filename-svg.*ml";
(@ARGV) or die "$usage\n";
(-e $ARGV[0]) or die "$0: file $_[0] does not exist\n";
($ARGV[0] =~ /ml$/) or die "$0: file $_[0] must end with file extension *ml\n";
($ARGV[0] =~ /-svg\.$/) and die "$0: file $_[0] seems to already contain -svg.\n";
(my $ofname= $ARGV[0]) =~ s/(.*)\.(.*)/$1-svg.$2/;
(defined($ofname)) or die "$0: cannot parse output file anem!\n";
my $textemplate= slurp \*DATA;
my $file_contents = slurp $ARGV[0];
($file_contents =~ /mathjax\.org/) and warn "\n\n$0: your file still contains the string mathjax.org, which should no longer be necessary. consider deleting it.\n\n";
$file_contents =~ s/\<span class=\"math\"(\>.*?)<\/span\>/runme($1)/gmse; ## good enough parsing
open my $FOUT, ">", $ofname or die "cannot open '$ofname' for write: $!\n";
print $FOUT $file_contents;
close $FOUT;
print "$0: successfully converted $ARGV[0] to $ofname\n";
################################################################
sub runme {
(my $convert=$_[0]) =~ s/^\>//; ## we are going to extend the tag with an alt, so we needed to remove it
$convert=~ s/\&/\&/g; $convert=~ s/\</\</g; $convert=~ s/\>/\>/g; ## undo previous html mangling. coult be more unmangling;
$convert =~ s/^\s+//gms; $convert =~ s/\s+$//gms; ## remove leading and trailing spaces
print STDERR "[convert '$convert' ";
my $classname;
if ($convert =~ s/^\\\(//) {
$convert =~ s/\\\)$//;
$classname="mathsvg";
} elsif ($convert =~ s/^\\\[//) {
$convert =~ s/\\\]$//;
$classname="mathsvgblock";
} else {
die "$0: I do not understand equation type in '$convert'\n";
}
open(my $FOUT, ">", "temp.tex") or die "$0: I cannot open temp.tex for writing: $!\n";
my $texfile= $textemplate;
$texfile=~ s/\*\*\*\*MATHJAXHERE\*\*\*\*/$convert/;
print $FOUT $texfile;
close($FOUT);
system("rm -f temp.dvi temp.svg ; latex -halt-on-error temp.tex &> /dev/null ; dvisvgm -n temp.dvi &> /dev/null");
my $svgcontents= (-e "temp.svg") ? slurp "temp.svg" : "svg conversion failed";
$svgcontents =~ s/<!DOCTYPE .*?\>//; ## we are inlining this one, so no doctype
($svgcontents =~ /<\/svg>/) or $svgcontents="svg conversion failed (incomplete)";
print STDERR (($svgcontents =~ /svg conversion failed/) ? "failed" : "ok")."\n";
return "<span class=\"$classname\" alt=\"$convert\">$svgcontents\<\/span>";
}
__DATA__
\documentclass[border={1pt 1pt 1pt 1pt}]{standalone}
%%%% left bottom right top . standalone does not understand ex or em!
\RequirePackage[T1]{fontenc}
\RequirePackage{textcomp}
\RequirePackage{charter}
\RequirePackage[mdbch,ttscaled=true]{mathdesign}
\usepackage{microtype}
\usepackage[english]{babel}
\pagestyle{empty}
\begin{document}
$****MATHJAXHERE****$
\end{document}
);
Hoping you don't have too many such things to typeset.
The trick is to reduce a bit the intercolumn padding. The row above the first matrix is positioned by hand, adjust the spacing to suit.
I increased the value of \arraystretch
, feeling that a bit of vertical room is needed, due to the big subscripts.
The settings are local to the equation
environment, so you don't need to revert them.
\documentclass{article}
\usepackage{amsmath,calc,graphicx}
\newcommand{\equalto}[2]{%
\begin{tabular}[t]{@{}c@{}}
\makebox[\widthof{$#2$}]{$#1$}\\[-.5ex]
\rotatebox{90}{$=$}
\end{tabular}%
}
\begin{document}
\begin{equation}
\addtolength{\arraycolsep}{-3pt}
\renewcommand{\arraystretch}{1.2}
\begin{aligned}[b]
&\mspace{19mu}\begin{matrix}
\equalto{\mathbf{s^{i_0}}}{b^0_{i_0}} &
\equalto{\mathbf{s^{i_1}}}{b^0_{i_1}} &
\cdots &
\equalto{\mathbf{s^{i_{N - 1}}}}{b^0_{i_{N-1}}}
\end{matrix}
\\[-1ex]
&\begin{pmatrix}
b^0_{i_0} & b^0_{i_1} & \cdots & b^0_{i_{N - 1}} \\
b^1_{i_0} & b^1_{i_1} & \cdots & b^1_{i_{N - 1}} \\
\vdots & \vdots & \ddots & \vdots \\
b^L_{i_0} & b^L_{i_1} & \cdots & b^L_{i_{N - 1}}
\end{pmatrix}
\begin{matrix}
{\rightarrow}\vphantom{b^0_{i_{N - 1}}} \\
{\rightarrow}\vphantom{b^0_{i_{N - 1}}} \\
\vdots \\
{\rightarrow}\vphantom{b^0_{i_{N - 1}}}
\end{matrix}
\begin{pmatrix}
a^0_0 & a^0_1 & \cdots & a^0_{N - 1} \\
a^1_0 & a^1_1 & \cdots & a^1_{N - 1} \\
\vdots & \vdots & \ddots & \vdots \\
a^L_0 & a^L_1 & \cdots & a^L_{N - 1}
\end{pmatrix}
=
\begin{pmatrix}
s^{}_0 & s^{}_1 & \cdots & s^{}_{N - 1} \\
s^{}_N & s^{}_{N + 1} & \cdots & s^{}_{2N - 1} \\
\vdots & \vdots & \ddots & \vdots \\
s^{}_S & 0 & \cdots & 0
\end{pmatrix}
\end{aligned}
\end{equation}
\end{document}
Without the equation number, I found that
\addtolength{\arraycolsep}{-1.5pt}
suffices, but of course the setting depends on the (unknown) size of your document.
Best Answer
edit: (by bbeeton, without consulting Sigur)
Consider the following slightly extended example:
(There isn't any facility for adding extra alignment points in
eqnarray
; they are changed to "new line" breaks, after being reported as an error.)Now is it obvious what the (or at least one) problem is with
eqnarray
?