1

This is a follow-up to Missing Item number in enumerate. Similar issue is reported, but only under very specific circumstances. In the prior question, the macro DoIfNonEmptyText is defined which executes its second parameter if #1 is non-empty. It has worked fine for me for many cases, but there are a few specific cases where I get

Something's wrong--perhaps a missing \item.

In the MWE below, the first \DoIfNonEmptyText{\ExampleVar}{} is the problem and results in this error message. In actual use case #2 in this call executes other code, but does not produce any output. By disabling the above error message, I get the output shown:

enter image description here

Notice the double item numbers. even though there is only one \item in the enumerate environment. In this specific case, this problem does not show up if:

  • wrapfigure is not used, or

  • the display math in enumerate is replaced by inline math.

Question:

What changes do I need to make to the DoIfNonEmptyText resolve this issue?

References:

Code:

\documentclass{article}
\usepackage{wrapfig}
\usepackage[strict]{changepage}

\usepackage{xcolor}\pagecolor{white}

\makeatletter %% https://tex.stackexchange.com/questions/86547 \newcommand\IgnoreMissingItemError{\let@noitemerr\relax}

\newcommand{\DescriptionVar}{}% \newcommand{\SetDescription}[1]{\renewcommand{\DescriptionVar}{#1}}

\newcommand{\ExampleVar}{}% \newcommand{\SetExample}[1]{\renewcommand{\ExampleVar}{#1}}

\newsavebox{@NonEmptyTestBox} \newcommand{\DoIfNonEmptyText}[1]{% Actually takes two parameters %% https://tex.stackexchange.com/a/57358/4301 (replaced sbox0 with @NonEmptyTestBox) \begingroup \savebox{@NonEmptyTestBox}{% \vbox{\everypar{}#1}% }% \ifdim\wd@NonEmptyTestBox=\z@\relax \endgroup \expandafter@gobble \else \endgroup \expandafter@firstofone \fi } \makeatother

\newcommand{\PrintBody}{% \DescriptionVar% \IgnoreMissingItemError% \DoIfNonEmptyText{\ExampleVar}{}% <-- This is problem. Needs \IgnoreMissingItemError \DoIfNonEmptyText{\ExampleVar}{% \medskip\par \textbf{Example:} \smallskip\par \begin{adjustwidth}{1.0cm}{0.0pt} \ExampleVar \end{adjustwidth}% }% }%

\begin{document} \SetDescription{% \begin{wrapfigure}{r}{4.0cm}% \fbox{xxxxxx}% \end{wrapfigure}% Some Text }% \SetExample{%
\begin{enumerate} \item [ x + y ] \end{enumerate}% } \PrintBody \end{document}

Peter Grill
  • 223,288
  • Would you expect this to actually work or are you just asking why it fails in the particular way it fails? Because I don't think it's reasonable to expect sensible output, but it does seem weird the output is not sensible in this specific way. – cfr Oct 17 '23 at 01:50
  • @cfr: Yes, I want this to work. Why do you think it's not reasonable to expect sensible ouptut? Works fine if you don't use warpfigure in the first section or if you use inline math instead of display math. I want the examples typset only for the case where they produce output. – Peter Grill Oct 17 '23 at 02:02
  • Because wrapfig doesn't like being too close to a list (or a section). – cfr Oct 17 '23 at 02:05
  • @cfr: Seems to work fine if display math is used in the example. Do I need to add a \par after wrapfigure? And, how does wragfigure effect the \DoIfNonEmptyText macro? – Peter Grill Oct 17 '23 at 02:09
  • wrapfig 'subverts' \@setpar and \everypar. wrapfigure changes \par .... And you're using \everypar etc. I don't know it's a problem. It just rang alarm bells. And adjustwidth is implemented as a list? Though I'm not sure that itself would be problematic. – cfr Oct 17 '23 at 02:27
  • The everypar{} was needed as per egreg's solution at the earlier referenced question. There should be some reset I can do after I am done with the wrapfigure – Peter Grill Oct 17 '23 at 02:35
  • Right now, \savebox{\@NonEmptyTestBox}{% \vbox{\everypar{}#1}% }% happens when wrapfigure's definition of \everypar is in effect. It's reset by \medskip\par. At least, I think so. I don't understand this stuff anything like as well as virtually everybody else. But \show\everypar shows the toks register change. (If that's the term: \toks12, \toks17.) Or is that normal? – cfr Oct 17 '23 at 02:44

0 Answers0