Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have already emailed the author Alain Matthes regarding this question. But for the benefit of those who might be interested, and since Alain is also a very active member in this site, I am also posting the question here.

In my attempt to answer the question Definite Integral Animation Examples, I borrowed Alain's code in his answer in Tikz-PGF: Draw integral test plot. The code works fine but shows an unexpected behavior when passing the value 1 to the number option as can be seen in the figure.

enter image description here

Here, there should be no rectangle after x=8. However, the code works fine when number is set greater than 1.

Here is the complete code for the figure.

\documentclass[tikz]{standalone}
\usepackage{tkz-fct}   

\begin{document}
\begin{tikzpicture}[scale=1.25]
\tkzInit[xmax=8,ymax=4]
\tkzAxeXY[ticks=false]
\tkzGrid   
\tkzFct[color = red, domain =0.125:8]{4./x}
\tkzDrawRiemannSumInf[fill=green!60,
                     opacity=.2,
                     color=green,
                     line width=1pt,
                     interval=1:8,
                     number=1]
 %\foreach \x/\t in {1.5/$a_1$,2.5/$a_2$,3.5/$a_3$,7.5/$a_7$}
 %\node[green!50!black] at (\x,{4/(\x+1)-0.25}){\t};
\end{tikzpicture}
\end{document}

Can somebody verify this and give a workaround?

share|improve this question
add comment

1 Answer 1

up vote 8 down vote accepted

It looks like it's due to the \foreach list having {0,1,...,x} and hence forcing 1 to be processed even if x is zero, instead of having {0,...,x} hence spining only once. And I guess there is a small typo with \i where it is i in the code. I'm not sure about the second point.


EDIT: Indeed it's not a typo but a rather peculiar syntax. From fp readme file.

ATTENTION: Do not use macro names with \ for its own. Use only the name or the macro surrounded by (, and ) instead, i.e. do not write \value{} but value or (\value). This is needed to avoid problems with a prefix "-" of numbers.


Here is the fixed version.

\documentclass[tikz]{standalone}
\usepackage{tkz-fct}   
\makeatletter
\def\tkz@DrawRiemannSumInf[#1]{%
\begingroup
\pgfkeys{%
/tkzriemann/.cd,
interval        = 1:2,
number          = 10,
opacity         = 0.5,
line width      = 1pt}
\pgfqkeys{/tkzriemann}{#1}  
  \iftkz@init@NO%
     \FPdiv{\tkz@x@delta}{\tkz@init@xorigine}{\tkz@init@xstep}%
     \FPdiv{\tkz@y@delta}{\tkz@init@yorigine}{\tkz@init@ystep}%
  \else
     \FPset{\tkz@x@delta}{0}
     \FPset{\tkz@y@delta}{0}%
  \fi%
\FPadd\tkz@intwd{\tkz@max}{-\tkz@min}
\FPdiv\tkz@delta{\tkz@intwd}{\tkz@fct@nb}
\FPadd\tkz@fct@nb{\tkz@fct@nb}{-1}   

\begin{scope}
\foreach \i in {0,...,\tkz@fct@nb}{%
  \FPeval\x{(\tkz@min+\i*\tkz@delta)}
  \FPeval\tkz@fx{\tkzFcta}
   \let\tkz@firstimg\tkz@fx
    \let\tkz@firstx\x 
  \FPadd\tkz@next{\x}{\tkz@delta}
  \let\tkzFctTmp\tkzFcta
  \FPset\x{\tkz@next}
  \FPeval\tkz@fxnext{\tkzFcta}
\ifdim \tkz@fx pt < \tkz@fxnext pt\relax
 \draw[opacity=\tkz@fct@opacity,/tkzriemann/.cd,#1] (\tkz@firstx ,0 ) rectangle (\tkz@next , \tkz@firstimg/\tkz@init@ystep );
\else 
\draw[opacity=\tkz@fct@opacity,/tkzriemann/.cd,#1] (\tkz@firstx ,0 ) rectangle (\tkz@next , \tkz@fxnext/\tkz@init@ystep );
 \fi  
   }    
   \end{scope}  
\endgroup
} 

\makeatother



\begin{document}
\begin{tikzpicture}[scale=1.25]
\tkzInit[xmax=8,ymax=4]
\tkzAxeXY[ticks=false]
\tkzGrid   
\tkzFct[color = red, domain =0.125:8]{4./x}
\tkzDrawRiemannSumInf[fill=green!60,
                     opacity=.2,
                     color=green,
                     number=1,
                     line width=1pt,
                     interval=1:8,
                    ]
 %\foreach \x/\t in {1.5/$a_1$,2.5/$a_2$,3.5/$a_3$,7.5/$a_7$}
 %\node[green!50!black] at (\x,{4/(\x+1)-0.25}){\t};
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
Thanks, percusse. About the \i, I am not so sure, too. Even in the definitions of tkzDrawRiemannSum and tkzDrawRiemannSumSup there is only i instead of \i. But even if i is not replaced with \i, it works fine with this example. –  hpesoj626 Mar 31 '13 at 10:27
    
@hpesoj626 It seems that it's not a typo –  percusse Mar 31 '13 at 12:55
    
Yes fine correction I need to modify several macro with the same problem –  Alain Matthes Mar 31 '13 at 15:27
    
It's a bug. I forgot the case with only one rectangle –  Alain Matthes Mar 31 '13 at 15:42
    
@AlainMatthes But still a great family of packages. –  percusse Mar 31 '13 at 15:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.