1

It seems that using align* inside enumerate* results in PDFLaTeX hanging. Can anyone explain the reason and/or suggest a workaround

Minimal example

\documentclass[11pt]{extarticle}   
\usepackage[inline, shortlabels]{enumitem}

\usepackage{amssymb, amsmath}

\begin{document}

\begin{enumerate*}
\item
\begin{align*}
abc &= def
\end{align*}
\end{enumerate*}

\end{document}

To explain what I need this for. I use align* to create equations with annotated steps - for example for fill-in-the-blank equation solving. I use the following macro to do so

\newcommand\rightcomment[5][0.3]%
  {\begin{tikzpicture}[remember picture,overlay]
   \draw[-stealth]
     ($({pic cs:#4}|-{pic cs:#2})+(#1,0)$)
     .. controls +(0.2,-0.05) and +(0.2,0.1) ..
     node[right,align=left]{#5}
     ($({pic cs:#4}|-{pic cs:#3})+(#1,0.1)$);
   \end{tikzpicture}%
  }

\newcommand\leftcomment[5][-0.1]%
  {\begin{tikzpicture}[remember picture,overlay]
   \draw[-stealth]
     ($({pic cs:#4}|-{pic cs:#2})+(#1,0)$)
     .. controls +(-0.2,-0.05) and +(-0.2,0.1) ..
     node[left,align=right]{#5}
     ($({pic cs:#4}|-{pic cs:#3})+(#1,0.1)$);
   \end{tikzpicture}%
  }


\newcommand\twostep[9]{
\begin{align*}
\tikzmark{la#1} #2 &= #3 \tikzmark{ra#1}\\
\tikzmark{lb#1} #5 &= #6 \tikzmark{rb#1}\\
\tikzmark{lc#1} #8 &= #9 \tikzmark{rc#1}
\end{align*}
\leftcomment{la#1}{lb#1}{la#1}{$(#4)$}
\leftcomment{lb#1}{lc#1}{la#1}{$(#7)$}
\rightcomment{ra#1}{rb#1}{ra#1}{$(#4)$}
\rightcomment{rb#1}{rc#1}{ra#1}{$(#7)$}  
  }

Which is used like:

    \twostep{a}{5y + 1}{21}
    {-1}{5y}{20}
    {\div 5}{y}{4}

This renders output like:

enter image description here

I then use the following macro to layout enumerated questions in a grid in a row-major order

\usepackage{tabto}
\usepackage[inline, shortlabels]{enumitem}

\newenvironment{tabbedenum}[1]
{\noindent\NumTabs{#1}\begin{enumerate*}[itemjoin={\tab}]}{\end{enumerate*}}

Which gives me a nice grid-structure of questions in rows:

enter image description here

  • An align would necessarily set its content as a display, thereby disrupting the "nice grid-structure"; it seems counter-intuitive for your usage. – Werner Dec 09 '17 at 16:32
  • @Werner - I'm sorry I'm not a very advanced TeX user - I align* keeps the typeset math inline as opposed to align. Actually if I switch for align I get exactly the same problem. $x = y$ and $$ x = y$$ work fine. begin{equation} or \[ result in a "bad math environment deliminator" error. – maninalift Dec 09 '17 at 17:13
  • @maninalift: align is similar to align* - the former just adds equation numbers while the latter doesn't. $x = y$ is consider inline math, while \[...\] sets a single equation in display math mode, just like align/align*. My original comment merely states that you're switching from inline enumeration (enumerate*) to display math mode, which defeats the style of having an inline enumeration. – Werner Dec 09 '17 at 17:22
  • align* does not set math inline it is a display environment. $ is for inline math, – David Carlisle Dec 09 '17 at 17:32
  • 2
    a quick compile of the example you posted yields the error ! Missing \endgroup inserted. \endgroup l.12 \end{align*} only after that does it hang (loop). instead of `align*`, use `$\begin{aligned}[t] ... \end{aligned}$`. (if this gives the result you want, please provide a more informative example, and i'll write an answer.) – barbara beeton Dec 09 '17 at 18:04

3 Answers3

2

Try the unboxed mode:

\begin{enumerate*}[mode=unboxed]
\item
\begin{align*}
abc &= def
\end{align*}
\end{enumerate*}

It was very unfortunate I decided to make the boxed mode the default.

Javier Bezos
  • 10,003
1

I don't think you need TikZ for that: some arrows from MnSymbol and an alignedat environment will do the job.

As to the horizontal enumerate, the natural environment for that should be the tasks package and its eponymous environment. Unfortunately, it can't be nested. I propose another solution, based on the shortlst package, which defines a shortenumerate environment, that I tweaked in order to make the number of columns an optional argument (3 by default).

Note this package is not part of TeX Live nor MiKTeX for licensing reasons, I believe, so you'll have to download it from CTAN and install it by hand in your TeXMF-local directory.

Here is an example:

    \documentclass[11pt]{extarticle}
    \usepackage{geometry}
    \usepackage[inline, shortlabels]{enumitem}
    \usepackage{tasks}
    \usepackage{amssymb, mathtools}
    \usepackage{relsize}
    \DeclareFontFamily{U} {MnSymbolA}{}
    \DeclareSymbolFont{MnSyA} {U} {MnSymbolA}{m}{n}
    \SetSymbolFont{MnSyA} {bold}{U} {MnSymbolA}{b}{n}
    \DeclareFontShape{U}{MnSymbolA}{m}{n}{
    <-6> MnSymbolA5
   <6-7> MnSymbolA6
   <7-8> MnSymbolA7
   <8-9> MnSymbolA8
   <9-10> MnSymbolA9
  <10-12> MnSymbolA10
  <12-> MnSymbolA12}{}
    \DeclareFontShape{U}{MnSymbolA}{b}{n}{
    <-6> MnSymbolA-Bold5
   <6-7> MnSymbolA-Bold6
   <7-8> MnSymbolA-Bold7
   <8-9> MnSymbolA-Bold8
   <9-10> MnSymbolA-Bold9
  <10-12> MnSymbolA-Bold10
  <12-> MnSymbolA-Bold12}{}
        \DeclareMathSymbol{\rcurvearrowdown}{\mathrel}{MnSyA}{"C3}%{"FD}
        \DeclareMathSymbol{\lcurvearrowdown}{\mathrel}{MnSyA}{"BB}%

    \usepackage{shortlst}
    \newenvironment{tabenumerate}[1][3]{%
    \renewcommand{\theenumii}{$\alph{enumii}$}
    \settowidth{\labelwidth}{\labelenumii}%
    \setlength{\leftmarginii}{\dimexpr\parindent + \labelwidth + \labelsep\relax}%
    \setlength{\shortitemwidth}{\dimexpr\linewidth/#1-\labelwidth-2\labelsep\relax}%
    \begin{shortenumerate}}%
    {\end{shortenumerate}}%

    \newcommand{\leftcomment}[1]{\raisebox{1.2ex}[0pt]{$ (#1)$}\raisebox{0.9ex}[0pt]{$\scalebox{1.4}{$ \rcurvearrowdown $}\: $}}
    \newcommand{\rightcomment}[1]{\raisebox{0.9ex}[0pt]{$\scalebox{1.4}{$ \: \lcurvearrowdown $}$}\raisebox{1.2ex}[0pt]{$(#1)$}}
    \begin{document}

    \begin{enumerate}[labelsep = 1.3em]
    \item
    \begin{tabenumerate}[2]
    \item $ \begin{alignedat}[t]{3}
     & & 5y + 1 &= 21\\
    \leftcomment{-1}
     & & 5y & =20 & & \rightcomment{-1}\\
    \leftcomment{\div 5} & & y & =4 & & \rightcomment{\div5}
    \end{alignedat} $
    \item $ \begin{alignedat}[t]{3}
     & & 6y + 3 &= 21\\
    \leftcomment{-3}
     & & 6y & =18 & & \rightcomment{-3}\\
    \leftcomment{\div 6} & & y & =3 & & \rightcomment{\div6}
    \end{alignedat} $
    \end{tabenumerate}
    \end{enumerate}

    \end{document} 

enter image description here

Bernard
  • 271,350
  • With the non negligible consequence that all math symbols will change. – egreg Dec 10 '17 at 10:14
  • I have accepted the answer above as I have tested it and it answers my question directly. However, this may be a better approach in the long-run (accepting the fact I'd rather avoid an out-of-bundle package). I'm guessing also that if the lines of the equation change in height the arrows will not adapt as they do with the TiKz example. – maninalift Dec 10 '17 at 11:27
  • @egreg: I tried to load only the two symbols needed, but I didn't find their slot numbers (this doesn't seem to be documented) and it was late. This morning, I found out – counting in the documentation, and I've fixed the code (and slightly improved it: the ‘comments’ were not quite centred w.r.t. the arrows). – Bernard Dec 10 '17 at 11:50
  • @maninalift: Yes, you can't scale the MnSymbol arrows very much, as it also thickens them. Other than that, I usually prefer pstricks to TikZ for this kind of extensible arrows (it's often less verbose). If you do not stick to curved arrows, you should also take a look at the gauss package. – Bernard Dec 10 '17 at 11:56
1

align* is the wrong tool: you need aligned.

Also, you need to reserve enough space for the arrows and labels, because \tikzmark won't make their width known.

\documentclass[11pt]{article}
\usepackage[inline, shortlabels]{enumitem}

\usepackage{amssymb, amsmath}
\usepackage{tikz}
\usetikzlibrary{calc,tikzmark}

\newcommand\rightcomment[5][0.3]%
  {\begin{tikzpicture}[remember picture,overlay]
   \draw[-stealth]
     ($({pic cs:#4}|-{pic cs:#2})+(#1,0)$)
     .. controls +(0.2,-0.05) and +(0.2,0.1) ..
     node[right,align=left]{#5}
     ($({pic cs:#4}|-{pic cs:#3})+(#1,0.1)$);
   \end{tikzpicture}%
  }

\newcommand\leftcomment[5][-0.1]%
  {\begin{tikzpicture}[remember picture,overlay]
   \draw[-stealth]
     ($({pic cs:#4}|-{pic cs:#2})+(#1,0)$)
     .. controls +(-0.2,-0.05) and +(-0.2,0.1) ..
     node[left,align=right]{#5}
     ($({pic cs:#4}|-{pic cs:#3})+(#1,0.1)$);
   \end{tikzpicture}%
  }


\newcommand\twostep[9]{%
  $\qquad\qquad\begin{aligned}[t]
  \tikzmark{la#1} #2 &= #3 \tikzmark{ra#1}\\
  \tikzmark{lb#1} #5 &= #6 \tikzmark{rb#1}\\
  \tikzmark{lc#1} #8 &= #9 \tikzmark{rc#1}
  \end{aligned}\qquad\qquad$%
  \leftcomment{la#1}{lb#1}{la#1}{$(#4)$}%
  \leftcomment{lb#1}{lc#1}{la#1}{$(#7)$}%
  \rightcomment{ra#1}{rb#1}{ra#1}{$(#4)$}%
  \rightcomment{rb#1}{rc#1}{ra#1}{$(#7)$}%
}

\begin{document}

\begin{enumerate}
\item
\begin{enumerate*}
\item
\twostep{a}{5y + 1}{21}
        {-1}{5y}{20}
        {\div 5}{y}{4}
\item
\twostep{b}{5y + 1}{21}
        {-1}{5y}{20}
        {\div 5}{y}{4}
\end{enumerate*}
\end{enumerate}
\end{document}

enter image description here

egreg
  • 1,121,712
  • Thank you - this worked for me. Credit also to @barbara-beeton who posted the same suggestion in a comment on my question. – maninalift Dec 10 '17 at 11:15