# Setting variable with gdef does not work

by A Diyanat   Last Updated July 25, 2019 03:23 AM - source

\documentclass{report}
\usepackage{amsthm}

\makeatletter
%Define variable
\gdef\@depRe{chapter}
\def\depRe#1{\gdef\@depRe{#1}}

%Usie variable
\theoremstyle{plain}
\newtheorem{theorem}{Theorem}[\@depRe]
\makeatother

%Set variable
\depRe{section}

\begin{document}
\chapter{Network}
\section{Cellular}
\begin{theorem}
This is an example.
\end{theorem}
\end{document}


As you can see, I defined 'depRe' variable and use it as theorem counter. But it does not worked for me and the value of 'depRe' (i.e. section) does not applied! Now put \depRe{section} before \newtheorem ..., so it works. Does any solution exist, which I can set 'depRe' after \newtheorem command?

It is worth noting that I have TexLive 2019.

Tags :