# Problem reading the value of \@itemdepth

I am a new LaTeX user. I am trying to format a generalized list. I have mush of it working. I am trying to get the value of the \@itemdepth so I can determine the amount of indenting being used at the current depth. I am getting an error that references the \@itemdepth variable when I try to use the \@itemdepth counter. I replace the variable reference with a number like 1 or 0 and the script will run. So it seems I am doing something wrong in this reference. I would appreciate any help that you can offer.

The relevant part of the script is as follows: It runs as it is shown. When the #1 is replaced with \@itemdepth. It does not work. (thanks Peter and Gonzalo for the instructions on including this.)

\documentclass{article}
\usepackage{amssymb, amsmath}
\usepackage{ifthen}

\newlength{\hangparsindent}
\newcounter{hangparsindentedlevel}

\newenvironment{hangpars}[1][1]{
\ifthenelse {#1 = 1} {
\setlength {\hangparsindent}{0in}
}
{
\setlength {\hangparsindent}{-\leftmargini}
}

\begin{list}{}{
\setlength{\itemindent}{\hangparsindent}
\setlength{\listparindent}{\hangparsindent}
\setlength{\partopsep}{0in} \setlength{\parskip}{0in} \setlength{\topsep}{0in}
}
\item{}
}
{\end{list}}

\begin{document}

\begin{hangpars}[2]
test text 1.  test text 1. test text 1.  test text 1. test text 1.  test text 1. test text 1.  test text 1. test text 1.  test text 1.

\begin{hangpars}[1]
test text 2.  test text 2. test text 2.  test text 2. test text 2.  test text 2. test text 2.  test text 2. test text 2.  test text 2.
\end{hangpars}

test text 3.  test text 3. test text 3.  test text 3. test text 3.  test text 3. test text 3.  test text 3. test text 3.  test text 3.

\end{hangpars}

\end{document}

-
Welcome to TeX.SE. Can you include a full minimum working example including \documentclass. –  Peter Grill Sep 14 '11 at 2:03
Are you enclosing your code inside \makeatletter, \makeatother? As a side note, I don't see any stepping of \@itemdepth in your code. –  Gonzalo Medina Sep 14 '11 at 2:24
Also, it appears that you set hangparsindent in the tru part of the \ifthenelse and then set it again once you come out of the \ifthenelse so the true part has no effect. –  Peter Grill Sep 14 '11 at 2:34
And you declare the environment with one optional argument, but never use it. –  Gonzalo Medina Sep 14 '11 at 2:42
Peter,I probably should have thought to do that the first time. follows below. I ripped out most of the logic to show where I was trying to put the reference to \@itemdepth. The file below runs fine as it is. When I replace the #1 with \@itemdepth it does not run and I get the error. –  Mark Banghart Sep 14 '11 at 2:46

Got this to compile, but not sure if this accomplished what you want. The \makeatletter is not really needed here, but will be if you attempt to access \@itemdepth. See What do \makeatletter and \makeatother do? for more details on this.

I added trailing % suppresses additional spaces. Not all may be necessary but I learned this the hard way so it is safer to include them. See this question for an example of what can happen without ending lines with a percent.

\documentclass{article}

\usepackage{amssymb, amsmath}
\usepackage{ifthen}

\makeatletter% Only needed to access \@itemdepth in here
\newlength{\hangparsindent}
\newcounter{hangparsindentedlevel}
%
\newenvironment{hangpars}[1][1]{\ifthenelse {#1 = 1} {%
\setlength{\hangparsindent}{0in}} {%
\setlength {\hangparsindent}{-\leftmargini}%
} \list{}{%
\setlength{\itemindent}{\hangparsindent}%
\setlength{\listparindent}{\hangparsindent}%
\setlength{\partopsep}{0in} \setlength{\parskip}{0in}%
\setlength{\topsep}{0in} } \item{}}%
{\endlist}%
\makeatother

\begin{document}
\begin{hangpars}[2]
test text 1. test text 1. test text 1. test text 1. test text 1. test text 1. test text 1. test text 1. test text 1. test text 1.
\begin{hangpars}[1]
test text 2. test text 2. test text 2. test text 2. test text 2. test text 2. test text 2. test text 2. test text 2. test text 2.
\end{hangpars}
test text 3. test text 3. test text 3. test text 3. test text 3. test text 3. test text 3. test text 3. test text 3. test text 3.
\end{hangpars}
\end{document}

-
Peter, Thanks for showing me the \makeatletter and \makeatother commands. It looks like they allow me to access the \@itemdepth variable. By the way, it looks like you added a % to the end of all lines of the \newenvironment. Mine compiled with out them. What are they for? Thanks again –  Mark Banghart Sep 14 '11 at 3:22
Peter, Is there a way for me to indicate that your reply answered my question? –  Mark Banghart Sep 14 '11 at 3:25
@Mark: Some of those % are probably not necessary. Try taking them out and you'll see why they are needed as you'll end up with extra spaces where you did not intend them. If this answered your question you can upvote it and select the check mark as the accepted answer. –  Peter Grill Sep 14 '11 at 3:28
@Mark: See tex.stackexchange.com/questions/8351/… for a description of what \makeatletter does. The % comments out the rest of the line and thus inhibits the potential inclusion of the line break as a superfluous space in the document (try a<line break>b and a%<line break>b). Also, you can use backticks ` to mark your inline code‌​. –  Caramdir Sep 14 '11 at 3:29