%% ----------------------------------------------------------------------
%% Demo latex file for 
%% 
%% latex-spread.el V0.9 -- Simple spreadsheet minor mode for LaTeX:
%% allows including formulas in LaTeX files and using emacs to update them 
%% 
%% M. Hermenegildo (23-10-95) 
%% http://www.clip.dia.fi.upm.es/~herme
%% herme@fi.upm.es 
%% based on spread.el mode by Benjamin C. Pierce
%% ----------------------------------------------------------------------

\documentclass{article}

\topmargin-1.0cm
\oddsidemargin0cm
\evensidemargin0cm
\textwidth17cm
\textheight22cm

%% Included to make LaTeX print the values and ignore the rest
\newcommand{\eva}[1]{  }
\newcommand{\val}[2]{#1}
\newcommand{\var}[3]{#1}

\begin{document}
\title{Example Document for {\tt latex-spread.el} }
\author{M.\ Hermenegildo
  \thanks{Computer Science Department, Technical University of Madrid 
    (UPM), Spain, {\tt http://www.clip.dia.fi.upm.es/\~{}herme}, {\tt
      herme@fi.upm.es}.}} 
\date{October 1995}
\maketitle

This document is a test file for the {\tt latex-spread.el} package.
This package implements an emacs minor mode which allows providing a
simple calculation capability inside a LaTeX document.  The idea is
that one includes variables, and expressions in the LaTeX document and
uses emacs to compute the values. The variables and expressions are
hidden inside LaTeX commands so that only the values are printed by
LaTeX. 

A simple use is to include computations in-line, i.e., it allows to
say that if the value of $A$ is \var{0}{23}{A}, then the value of
$A+3$ is \var{0}{(+ A 3)}{B} and recompute the second value
automatically if the first one is changed. Values such as this one
\var{0.00}{1234567890.12}{C} can be printed in ``comma format,'' which
is easier to read for large numbers: \val{1,0.00}{C}

The most typical use is to compute parts of tables, such as this one:\\ 

\begin{tabular}{|r|r|r|r|}
\hline
Nagents       &   Time               &  Speedup               \\
\hline
  Seq.        & \var{0.0}{33.0}{ts} &  \val{0.000}{1.0      }\\
\var{0}{1}{n} & \var{0.0}{33.4}{tp} &  \val{0.000}{(/ ts tp)}\\
\var{0}{2}{n} & \var{0.0}{17.5}{tp} &  \val{0.000}{(/ ts tp)}\\
\var{0}{3}{n} & \var{0.0}{11.9}{tp} &  \val{0.000}{(/ ts tp)}\\
\hline
\end{tabular}

\ \\ Note that imperative assignments are performed, scanning the file
top-down, left-to-right, and that a variable occurrence in an
expression refers to the last value of the variable.  You can also
include the fact that this table was last recalculated on 
\val{10/04/1996-16:09}{ (date-and-time) }). Here is a slightly more
complicated table:\\ 

\begin{tabular}{|r|r|r|r|}
\hline
Number of Agents       &   Time               
            &  Speedup                & Efficiency (\%)  \\
\hline
  Seq.        & \var{0.0}{33.0}{ts} 
            &  \val{0.000}{1.0      } & \val{0.0}{100} \\
\var{0}{1}{n} & \var{0.0}{33.4}{tp} 
            &  \val{0.000}{(/ ts tp)} & \val{0.0}{(* 100 (/ (/ ts  tp) n))}\\
\var{0}{2}{n} & \var{0.0}{17.5}{tp} 
            &  \val{0.000}{(/ ts tp)} & \val{0.0}{(* 100 (/ (/ ts  tp) n))}\\
\var{0}{3}{n} & \var{0.0}{11.9}{tp} 
            &  \val{0.000}{(/ ts tp)} & \val{0.0}{(* 100 (/ (/ ts  tp) n))}\\
\var{0}{4}{n} & \var{0.0}{ 9.0}{tp} 
            &  \val{0.000}{(/ ts tp)} & \val{0.0}{(* 100 (/ (/ ts  tp) n))}\\
\var{0}{5}{n} & \var{0.0}{ 7.3}{tp} 
            &  \val{0.000}{(/ ts tp)} & \val{0.0}{(* 100 (/ (/ ts  tp) n))}\\
\var{0}{6}{n} & \var{0.0}{ 6.1}{tp} 
            &  \val{0.000}{(/ ts tp)} & \val{0.0}{(* 100 (/ (/ ts  tp) n))}\\
\var{0}{7}{n} & \var{0.0}{ 5.3}{tp} 
            &  \val{0.000}{(/ ts tp)} & \val{0.0}{(* 100 (/ (/ ts  tp) n))}\\
\var{0}{8}{n} & \var{0.0}{ 4.9}{tp} 
            &  \val{0.000}{(/ ts tp)} & \val{0.0}{(* 100 (/ (/ ts  tp) n))}\\
\var{0}{9}{n} & \var{0.0}{ 4.4}{tp} 
            &  \val{0.000}{(/ ts tp)} & \val{0.0}{(* 100 (/ (/ ts  tp) n))}\\
\hline
\end{tabular}

\ \\ Cummulative values are kept for each variable. This allows
computing column totals, averages, etc., as in the following table:\\ 

%% This clears the value histories of tp and sp
%% \eva{(ch 'tp)}
%% \eva{(ch 'sp)}
 
\begin{tabular}{|r|r|r|r|}
\hline
Number of Agents       &   Time   &  Speedup   \\
\hline
  Seq.        & \var{0.0}{33.0}{ts}  &  \val{0.000}{1.0      } \\
\var{0}{1}{n} & \var{0.0}{33.4}{tp}  &  \var{0.000}{(/ ts tp)}{sp} \\
\var{0}{2}{n} & \var{0.0}{17.5}{tp}  &  \var{0.000}{(/ ts tp)}{sp} \\
\var{0}{3}{n} & \var{0.0}{11.9}{tp}  &  \var{0.000}{(/ ts tp)}{sp} \\
\hline
{\bf Speedup Average} &        &  \val{0.000}{(mean 'sp)}\\
{\bf Total time}      & \val{0.00}{(sumh 'tp)} & \\
\hline
\end{tabular}

Also, it is possible to use the eva/val constructs to perform other
operations. Here is an example (by Niels Langager):

\eva{(defun greet (friend) (concat "Hi " friend))}
\val{}{(greet "Bob")}

\end{document}

