General ⇒ Weird Scoping problem
-
- Posts: 2
- Joined: Sat Sep 29, 2007 12:28 pm
Weird Scoping problem
I am using MikTex, most recent version.
===========================================================
\documentclass{article}
\usepackage{fp}
% Some command to add to a sum
\newcommand{\addstuff}[2]{#1 & #2 \\ \FPadd{\mysum}{\mysum}{#2}}
% This env doesn't works properly!
\newenvironment{myenv1}
{ \def\mysum{0.001} \begin{tabular}{l l} Item & Qnty \\ }
{ Total & \mysum \\ \end{tabular}}
% This works OK in the end environment statement
\newenvironment{myenv}
{ \def\mysum{0.001} \begin{tabular}{l l} Item & Qnty \\}
{ \mysum & Total \\ \end{tabular}}
\begin{document}
% sum is incorrect
\begin{myenv1}
\addstuff{Apples}{0.1}
\end{myenv1}
% sum is OK
\begin{myenv}
\addstuff{Apples}{0.1}
\end{myenv}
\end{document}
NEW: TikZ book now 40% off at Amazon.com for a short time.
And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p