3

I can't make use of todonotes (or marginnote but this isn't in the MWE because I don't think I have the prerequisites setup for this correctly) in an inline enumerated list.

I think I am getting the margin par error because I am in an align environment (maybe I am wrong here) I tried to augment my function with a check for the align environment so that I could provide an alternative to switch to marginnote but this didn't work.

Actually, this align check won't even compile so I have had to comment it out.

I don't know if this makes any difference, but in my non-MWE example this new command is in a cls file, and as you can see below I have tried with and without the \makeatletter/

\documentclass{article}

\usepackage{expl3}
\usepackage{xparse}
\usepackage{xpatch} 
\usepackage{letltxmacro}
\usepackage{amsmath}
\usepackage{todonotes}
\usepackage{marginnote}
\usepackage{enumerate}
\usepackage[shortlabels,inline]{enumitem}

%\makeatletter
\DeclareDocumentCommand{\TODOblock}{ O{@general} +m }
{
    \ifdefined\HCode    
        \textbf{\textbf{(NOTE: #2)}}
    \else
        %\IfNoValueF {#2} { lightslategray }
        \todo[inline,color=#1]{\unexpanded{\unexpanded{\textbf{#1:\\}#2}}}
    \fi
}

\DeclareDocumentCommand{\TODOnote}{ O{@general} +m }
{
    \ifdefined\HCode    
        \textbf{\textbf{(NOTE: #2)}}
    \else
        %\ifinalign@
        %   TEXT%\marginnote[size=\scriptsize,color=#1]{\unexpanded{\unexpanded{\textbf{#1:\\}#2}}}
        %\else
            \todo[size=\scriptsize,color=orange]{\unexpanded{\unexpanded{\textbf{#1:\\}#2}}}
        %\fi
    \fi
}
%\makeatother

\begin{document}
    Hi heres a list \TODOnote{Of course I can do this}
    \begin{enumerate}
        \item an item \TODOnote{I can do this}
        \item next item
    \end{enumerate}

    Hi heres a list that is inline
    \begin{enumerate*}
        \item an item
        \item next item %\TODOnote{I can't do this}
    \end{enumerate*}
\end{document}

UPDATE In response to an answer that seems to have been removed, I tried nesting my custom TODO in a marginpar i.e.: \marginnote{\todo[inline,size=\scriptsize,color=orange]{\unexpanded{\unexpanded{\textbf{#1:\\}#2}}}} but this doesn't align the boxes well when there are a lot of comments virtually stacked upon each other. This did get around the align problem, but the align detection still doesn't work, so I can't make use of this possibility even specifically for the limited occurrences of the align environments.

UPDATE 2 This answer that was removed also proposed a work around of using an inline version. I would be fine with this as a limited work around in the few align environments I have, but this still hinges on the \ifinalign@ structure working...

1
  • \ifinalign@ is true in amsmath display environments and has nothing to do with enumerate*. The problem is, apparently, that enumerate* is typeset in a box and \todo wants to be at the outer level.
    – egreg
    Apr 25, 2016 at 16:52

1 Answer 1

1

\ifinalign@ has nothing to do with enumerate*. This environment uses boxes for avoiding untimely line breaks, so the \todo command ends up in a forbidden planet (it must be at the outer level).

A possible solution is to check whether the \todo note is in a bad place with \ifinner and delay its working when the box ends. One needs to jump up two levels, though.

\documentclass{article}

\usepackage{expl3}
\usepackage{xparse}
\usepackage{xpatch} 
\usepackage{letltxmacro}
\usepackage{amsmath}
\usepackage{todonotes}
\usepackage{marginnote}
\usepackage{enumerate}
\usepackage[shortlabels,inline]{enumitem}

\NewDocumentCommand{\TODOblock}{ O{@general} +m }{%
  \ifdefined\HCode    
    \textbf{\textbf{(NOTE: #2)}}
  \else
    \todo[inline,color=#1]{\unexpanded{\unexpanded{\textbf{#1:\\}#2}}}
  \fi
}

\NewDocumentCommand{\TODOnote}{ O{@general} +m }{%
  \ifdefined\HCode    
    \textbf{\textbf{(NOTE: #2)}}
  \else
    \ifinner
      \gdef\thisnote{%
        \todo[size=\scriptsize,color=orange]{\unexpanded{\unexpanded{\textbf{#1:\\}#2}}}%
      }\aftergroup\aftergroup\aftergroup\thisnote
    \else
      \todo[size=\scriptsize,color=orange]{\unexpanded{\unexpanded{\textbf{#1:\\}#2}}}%
    \fi
  \fi
}

\begin{document}
Hi heres a list \TODOnote{Of course I can do this}
\begin{enumerate}

\item an item \TODOnote{I can do this}
\item next item

\end{enumerate}

Hi heres a list that is inline
\begin{enumerate*}

\item an item

\item next item\TODOnote{I can't do this}

\end{enumerate*}
\end{document}

enter image description here

2
  • Thanks, informative as always! This integrates to my complete document perfectly. I don't fully understand jump up two levels. My inference is that boxes have a different level of priority during compiling, perhaps similar in concept to cross references or floats which iterate to optimize position placement... But since bypassing when it is processed seems to have no adverse effects my logic is definitely faulty. Could you point me to a resource that I could read to improve my understand of this level breakdown so I can learn more about how structures like boxes are handled? Thanks!
    – EngBIRD
    Apr 25, 2016 at 18:19
  • @EngBIRD I'm afraid that what you're asking is “The TeXbook”.
    – egreg
    Apr 25, 2016 at 19:26

You must log in to answer this question.

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