2

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}
Caramdir
  • 89,023
  • 26
  • 255
  • 291
  • Welcome to TeX.SE. Can you include a full minimum working example including \documentclass. – Peter Grill Sep 14 '11 at 02: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 02: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 02:34
  • And you declare the environment with one optional argument, but never use it. – Gonzalo Medina Sep 14 '11 at 02: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 02:46
  • \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}} \end{hangpars}

    continued in next comment

    – Mark Banghart Sep 14 '11 at 02:47
  • \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}

    – Mark Banghart Sep 14 '11 at 02:52
  • It would be better to edit your original question to include the complete minimal working example. – Gonzalo Medina Sep 14 '11 at 02:53
  • Peter, The file was large and I pulled a lot of it out to show the problem I was having. I am looking for a why to access the depth of the item indent from the newly created environment. – Mark Banghart Sep 14 '11 at 02:55
  • Gonzalo, I thought @itemdepth was a reference to the varriable kept by the generalized list environment and as such would be indexed by the use of \item in the new environment. Also, I ripped much of the logic out of the environment to show the part I was having trouble with. – Mark Banghart Sep 14 '11 at 02:58
  • What exactly are you trying to do? – Peter Grill Sep 14 '11 at 03:23

1 Answers1

3

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 Grill
  • 223,288
  • 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 03:22
  • Peter, Is there a way for me to indicate that your reply answered my question? – Mark Banghart Sep 14 '11 at 03: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 03:28
  • 1
    @Mark: See http://tex.stackexchange.com/questions/8351/what-do-makeatletter-and-makeatother-do 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 03:29