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}
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