I am setting a custom length to equal the value of \leftmargin
inside an enumitem
list. Once I exit the list though the value disappears and my custom length reverts to zero.
I have shown the behaviour below in a MWE:
\documentclass{article}
\usepackage{enumitem}
\newlength\Mylen
\setlength{\Mylen}{0em}
\begin{document}
Hello world. Value of Mylen is \the\Mylen.
\begin{enumerate}[leftmargin=40pt,labelsep=1em, label={P\arabic*}]
\item Test line 1.
\item Test line 2.
\item Test line 3. The value of leftmargin is \the\leftmargin. Value of Mylen is \the\Mylen. \addtolength{\Mylen}{\leftmargin} Value of Mylen is now the sum of leftmargin and original value = \the\Mylen.
\end{enumerate}
Value of Mylen is \the\Mylen ~again!
\end{document}
I cannot understand why this happens. Any help?