[Tex/LaTex] Using mathematical function in PGF/TikZ

pgfmathtikz-pgf

I want to use ProbXpos for example to position tic marks and to position line ends.
It seems to calculate as I intend, but how can I use the calculated value?
The example below prints a sample result value. If I un-comment the commented lines it won't even compile.

Also — minor point — some is there a ln 10 function? Doesn't work for me.

\documentclass{article} %maybe a better one?
\usepackage{tikz}
\newcommand{\ProbXpos}[1]{\pgfmathparse{ln(#1/(1-#1))/ln 10}\pgfmathresult }
\begin{document}
\begin{tikzpicture}
\draw (0,1) node {\ProbXpos{0.1} result prints ok} ;
%   \draw (\ProbXpos{.0001},0) -- (\ProbXpos{0.999},0) 
%                   node    {cannot use result numerically} ;
\end{tikzpicture}  
\end{document}

Best Answer

Maybe you are interested in making ProbXpos in a function that can be used inside a coordinate.

The extra pair of braces are needed as ProbXpos(…) contains parentheses itself.

You could also use a definition as in

\newcommand{\ProbXpos}[1]{{log10(#1/(1-#1))}}

which can be used inside a coordinate, too.
But it can not be modified, i.e. (2*\ProbXpos{…}, 0), because it already contains the braces.

Then again, we could leave out the extra pair of braces, but then we need to use { } in the coordinate.

Code (declare function variant)

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}[declare function={ProbXpos(\x)=log10(\x/(1-\x));}]% could be global …
    \draw (0,1) node {\pgfmathparse{ProbXpos(0.1)}\pgfmathresult\ result prints ok} ;
    \draw ({ProbXpos(.0001)},0) -- ({ProbXpos(0.9999)},0);
\end{tikzpicture}  
\end{document}

Code (PGF math function)

\documentclass[tikz]{standalone}
\makeatletter
\pgfmathdeclarefunction{ProbXpos}{1}{%
    \begingroup
        \pgfmathparse{log10(#1/(1-#1))}%
        \pgf@x=\pgfmathresult pt\relax
        \pgfmathreturn\pgf@x
    \endgroup
}
\makeatother
\begin{document}
\begin{tikzpicture}
    \draw (0,1) node {\pgfmathparse{ProbXpos(0.1)}\pgfmathresult\ result prints ok} ;
    \draw ({ProbXpos(.0001)},0) -- ({ProbXpos(0.9999)},0);
\end{tikzpicture}  
\end{document}

Output (declare function/PGF math function)

enter image description here

Code (LaTeX macro)

\documentclass[tikz]{standalone}
\newcommand{\ProbXpos}[1]{log10(#1/(1-#1))}
\begin{document}
\begin{tikzpicture}
    \draw (0,1) node {\ProbXpos{0.1} result prints ok} ;
    \draw ({\ProbXpos{.0001}},0) -- ({\ProbXpos{0.999}},0);
\end{tikzpicture}  
\end{document}

Output (LaTeX macro)

enter image description here