I need to plot a function that presents some kind of removable singularity, but I cannot split the plot into two intervals, because I'm setting the domain programmatically and it can happen that the singularity falls out of the domain. I thought of using the ifthenelse function, but it's useless because both the expressions in the two branches are evaluated in any case. Look at the following code (it's just an example):
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture} [declare function={%
y(\x)= \x!=0 ? sin(\x)/\x : 1;}]
\draw plot [domain=0:1] (\x,{y(\x)});
\end{tikzpicture}
\end{document}
I expected that, as x=0, the first branch of the expression was skipped and only the second one was evaluated, but it's not so and I get a division by zero error. As a solution, I thought of declaring an intermediate function to set properly the independent variable, as in the following working example:
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture} [declare function={%
t(\x)= \x!=0 ? \x : 1;
y(\x)= \x!=0 ? sin(\x)/t(\x) : 1;}]
\draw plot [domain=0:1] (\x,{y(\x)});
\end{tikzpicture}
\end{document}
but I'm looking for a more elegant and compact solution.


\expandafters in javascript? I am shocked ;) – Jan 06 '15 at 15:34\ifabsgreaterbut rather, for example\IfAbsGreaterto signal it does not work as an\ifconditional requiring a\fi. – Jan 06 '15 at 16:48\xis small the TikZ math parsing ofsin(\x r)/\xwill lead to dimension too large error, I imagine. Is this the kind of error you see? you should ask a new question if this too long to explain in a comment. – Jan 07 '15 at 18:49