Define numeric variable in terms of another variable

You can use xparse and xfp (the latter allows computations on the fly):

\documentclass{article}
\usepackage{xparse,xfp}

\ExplSyntaxOn
\NewDocumentCommand{\defineconstant}{mm}
 {
  \cs_new:Npx #1 { \fp_eval:n { #2 } }
 }
\ExplSyntaxOff

\begin{document}

\defineconstant{\constantA}{0.25}
\defineconstant{\constantB}{1-\constantA}
\defineconstant{\constantC}{round(sqrt(\constantA),2)+\constantB/2}

The value of \verb|\constantA| is \constantA

The value of \verb|\constantB| is \constantB

The value of \verb|\constantC| is \constantC

\fpeval{round(\constantA-\constantC+exp(2),4)}

\end{document}

enter image description here


You can use pgf package for this. Instead TeX primitive \def one need use \pgfmathsetmacro

\documentclass{article}
\usepackage{pgf}

\begin{document}
\pgfmathsetmacro{\first}{0.25}
\pgfmathsetmacro{\second}{1-\first}

The value of \verb|\first| is \first

The value of \verb|\second| is \second
\end{document}

enter image description here