I tried to define variables with the sqrt command but couldn't get the result printed .
\def \radius {sqrt(4^2+2^2)}
\draw (4,3) node [right] {$The radius is \radius for x=4, y=2$};
The \draw shows "Theradiusissqrt(4^2+2^2)forx=4,y=2" instead of "The radius is 4.47 for x=4, y=2".
Also, I tried to \def the variable with pass-ins like below:
\def \my_radius#1#2 {sqrt(#1^2+#2^2)} % r=4.47
\draw (4,0) node [right] {$My_radius is \my_radius{4}{2}\ for x=4, y=2$};
It didn't show the result. What would be the right code for these two examples? Btw, I am using the TeXnicCenter IDE, how do I debug/print by not using \draw?



_generally has a special character code, and shouldn't be in a command name. Also, once you start math with$, everything is math. So$The radius is...is the variable T, times h, times e, times r, times a, times d, .... Notice how in wipet's answer, only the math is in$, the text is not. – Teepeemm Nov 05 '23 at 03:14\def \radius {$(4^2+2^2)^(0.5)$)}without sqrt(), but the \draw is still missing the numerical result. It prints out \radius as the formula, no evaluation? I got the idea from here. – Leon Chang Nov 05 '23 at 05:23\pgfmathprint{\radius}but this won't have good precision. The result will never show on its own, if you just use\radius, it will always just expand to the replacement text you specified. – Qrrbrbirlbel Nov 05 '23 at 11:16