# In a command, is there a way to use argument \sqrt{2} in one place and evaluate it in another

I'm trying to use a command to plot points on a line:

\documentclass{standalone}

\usepackage{tkz-fct}

\newcommand{\markPoint}[1]{
\tkzDefPoint(#1,0){A}
\tkzDrawPoint(A)
\tkzLabelPoint[below](A){$$#1$$}}

\begin{document}

\begin{tikzpicture}
\tkzInit[xmin=-3, xmax=5]
\tkzDrawX[noticks]
\markPoint{\sqrt{2}}
\end{tikzpicture}
\end{document}


I have no problem with values like 1 but values like \sqrt{2} don't work and I'm wondering if there is a way of evaluating using \sqrt because if I have to remove the \ then I wouldn't be able to use the same argument for the label.

You can arrange the value of \sqrt to be whatever is needed in each context

\documentclass{standalone}

\usepackage{tkz-fct}

\newcommand{\markPoint}[1]{%
\let\savedsqrt\sqrt
\def\sqrt##1{sqrt(##1)}%
\let\savedfrac\frac
\def\frac##1##2{(##1)/(##2)}%
\tkzDefPoint(#1,0){A}%
\let\sqrt\savedsqrt
\let\frac\savedfrac
\tkzDrawPoint(A)
\tkzLabelPoint[below](A){$$#1$$}%
}

\begin{document}

\begin{tikzpicture}
\tkzInit[xmin=-3, xmax=5]
\tkzDrawX[noticks]
\markPoint{\sqrt{2}}
\end{tikzpicture}
\end{document}

• You will get my upvote if you make \sqrt[3]{2} translate to pow(2,1/3). (Note also that \tkzDefPoint... makes things global, so you could use \begingroup...\endgroup around it, so you won't need \savedsqrt.) – user194703 May 25 at 19:53
• I'm not sure what the two ## do. Could you explain that? And another question, using this solution, I would have to detect if the input is a square root or a cubic root or even a fraction, am I right? Is there a way of evaluating all of these inputs in a "simple" way? – Concept7 May 25 at 20:14
• @Concept7 its a nested definition so #1 refers to the argument passed in (\sqrt{2} here but ##1 is the argument of the command being defined (2 here) – David Carlisle May 25 at 20:27
• @Concept7 you wouldn't need to detect what the input was but you would need to add suitable definitions for all the forms that you might use. – David Carlisle May 25 at 20:28
• @Concept7 I'll ad the frac, what do you want in the expression form (#1) / (#2) ? – David Carlisle May 25 at 21:05