%!TEX pdflatex
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{settobox}
\newsavebox{\maboitecmd}
\newsavebox{\maboiteres}
\newlength{\hauteurboitecmd}
\newlength{\hauteurboiteres}
\newcommand\recuphauteurs[2]{%
\sbox{\maboitecmd}{#1}
\settoboxtotalheight{\hauteurboitecmd}{\maboitecmd}
\sbox{\maboiteres}{#2}
\settoboxtotalheight{\hauteurboiteres}{\maboiteres}
}
\begin{document}
\section{Commande en dehors d'un environnement tikz}
\recuphauteurs
{\sffamily g(x)=4/(1+e\textasciicircum(-k x))}
{$\rightarrow$ \: $\mathsf{g(x)=\dfrac{4}{e^{-kx}+1}}$}
\begin{tikzpicture}
\draw (0,0) node {\the\hauteurboitecmd} ;
\draw (0,-1) node {\the\hauteurboiteres} ;
\end{tikzpicture}
\section{Commande dans un environnement tikz}
\begin{tikzpicture}
\recuphauteurs
{\sffamily g(x)=4/(1+e\textasciicircum(-k x))}
{$\rightarrow$ \: $\mathsf{g(x)=\dfrac{4}{e^{-kx}+1}}$}
\draw (0,0) node {\the\hauteurboitecmd} ;
\draw (0,-1) node {\the\hauteurboiteres} ;
\end{tikzpicture}
\end{document}