jbezos / enumitem

Customize enumerate, itemize and description
MIT License
45 stars 5 forks source link

Manipulating series counters between environments? #25

Closed svlauer closed 3 years ago

svlauer commented 3 years ago

As per the documentation, when a cloned list foo is created with type enumerate, the counters fooi, fooii, fooiii ... are created.

Is there an equivalent for environments that use a series? I.e., if I create a series and use resume=foobar, I assume that there is some counter that keeps track of the value for the series. What is the name of that counter?

(My usecase: Making a list that uses a series work with beamer's overlay feature. This feature will lead to certain parts of a "frame" (roughy, page) to be typeset multiple times. beamer provides facilities to reset counters for each re-typeset, but for using those, I need to know the name of the counter, obviously.)

muzimuzhi commented 3 years ago

I.e., if I create a series and use resume=foobar, I assume that there is some counter that keeps track of the value for the series. What is the name of that counter?

The "value" is not stored in a counter, but in a macro \enit@resume@<env name> as part of a count assignment. For example, in the following example, after the first enumerate env, the two resume macros are defined by

\def \enit@resumekeys@enumerate {}%
\def \enit@resume@enumerate {\c@enumi 2}

By calling the second one at the beginning of the second enumerate env with option resume, the value of counter enumi is restored. See the definition of \enit@endlist.

\documentclass{article}
\usepackage{enumitem}

\begin{document}
\begin{enumerate}
  \item a
  \item a
\end{enumerate}

\begin{enumerate}[resume]
  \item a
  \item a
\end{enumerate}
\end{document}

To help answer your question at hand, I suggest to provide a complete example, perhaps to the general q&a forum tex.stackexchange.com rather than the bug tracker here.

svlauer commented 3 years ago

Thank you for the fast reply! Now I understand what is going on (I tried to figure it out from the source code, but ...).

(As for my beamer-problem, I think I'll be able to figure out how to solve it (or I will ask in an appropriate forum) - I just included it here for some context about why I was asking my question.)

ETA, in case someone with the same question finds this issue:

When using a series (series=<series name> and resume=<series name>), the macro is named \enit@resume@series@<series name>.

muzimuzhi commented 3 years ago

Now I understand what is going on (I tried to figure it out from the source code, but ...).

Directly reading the source code might be, though not impossible, challenging. "Debugging" utilities like the macro \tracingall macro and unravel package are helpful here. For example, I used

\documentclass{article}
\usepackage{enumitem}

\begin{document}
a{\tracingall
\begin{enumerate}
  \item a
  \item a
\end{enumerate}}

\begin{enumerate}[resume]
  \item a
  \item a
\end{enumerate}
\end{document}

and then read the output log file and enumitem.sty side by side to help find how the resuming info is stored.

PS: The beginning a before {\tracingall ... is used to avoid the paragraph-hooks staff (added in LaTeX2e 2021-06-01, see texdoc ltnews, issue 33 and texdoc ltpara-doc) from being traced, hence shorten the tracing output in log a bit.

svlauer commented 3 years ago

Thank you again! This is very helpful. I knew that these "debugging" commands exist, but so far, I've tended to try and figure out the source code by itself. In the future, I will play around with \tracingcall etc., instead of just staring at the source code, trying to execute it in my head ...