2

Currently, I have a system of automatically numbering several lists of tasks. It looks like this:

\documentclass{article}
\usepackage{enumitem}

\newcounter{taskmajor}
\newlist{tasklistimpl}{enumerate}{2}
\setlist[tasklistimpl]{label=\textbf{Task \arabic{taskmajor}.\arabic*},itemindent=4em}
\newenvironment{tasklist}{
    \stepcounter{taskmajor}
    \let\olditem\item
    \renewcommand{\item}{\olditem --}
    \begin{tasklistimpl}
}{
    \end{tasklistimpl}
    \let\item\olditem
}

\begin{document}

\begin{tasklist}
\item \label{itm:first} Test item, first
\item \label{itm:second} Test item, second
\end{tasklist}

\begin{tasklist}
\item \label{itm:twopointone} Test item, two point one.
\end{tasklist}

\ref{itm:twopointone}

\end{document}

When I \ref{itm:twopointone} I get "Task 2.1" but I'm not certain that having it bold in all of the places I reference it is a wise choice stylistically, so I'm seeking a way to disable the baked in bold somehow just for references. Is there an easy way to do this? Or do I need to somehow to restructure things? Additionally, is the construction of the multipart task list (which in the actual document will span across several sections) sane?

Additionally, I'm also searching for a way to move the -- into the item label again without having it be part of the reference, because due to justification spacing the beginning of the statement is no longer exactly lined up.

2
  • 2
    Welcome to TeX.se, and thanks for providing an example document. Unfortunately it doesn't compile. Have you changed names halfway through? enumitem has separate label and ref keys to change the formatting of the two elements of a list. See p. 5 of the documentation.
    – Alan Munn
    Jan 12, 2020 at 20:33
  • sorry, you are correct. I have adjusted it. Jan 12, 2020 at 20:47

2 Answers 2

5

I would do this with a single list type. You don't need a separate environment, since you can inject code to step the outside counter.

\documentclass{article}
\usepackage{enumitem}

\newcounter{taskmajor}

\newlist{tasklist}{enumerate}{1}
\setlist[tasklist]{label={Task \thetaskmajor.\arabic* --},
    itemindent=4em,font=\bfseries,ref={Task \thetaskmajor.\arabic*},
    first=\refstepcounter{taskmajor}}

\begin{document}

\begin{tasklist}
\item \label{itm:first} Test item, first
\item \label{itm:second} Test item, second
\end{tasklist}

\begin{tasklist}
\item \label{itm:twopointone} Test item, two point one.
\end{tasklist}

In \ref{itm:twopointone}

\end{document}

output of code

1
2

Per @Alan Munn's suggestion, the answer is quite simple. You can simply using the ref option of the enumitem's setlist command. This also solves the other problem I had with wanting to move the -- into the label.

My code becomes:

\documentclass{article}
\usepackage{enumitem}

\newcounter{taskmajor}
\newlist{tasklistimpl}{enumerate}{2}
\setlist[tasklistimpl]{label=\textbf{Task \arabic{taskmajor}.\arabic*} --,ref=Task \arabic{taskmajor}.\arabic*,itemindent=4em}
\newenvironment{tasklist}{
    \stepcounter{taskmajor}
    \begin{tasklistimpl}}{\end{tasklistimpl}}

\begin{document}

\begin{tasklist}
\item \label{itm:first} Test item, first
\item \label{itm:second} Test item, second
\end{tasklist}

\begin{tasklist}
\item \label{itm:twopointone} Test item, two point one.
\end{tasklist}

\ref{itm:twopointone}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .