# How to use markdown in todonotes?

I use todonotes, especially in the coordination of bigger projects. Especially in the drafting and quick brainstorming phase I'd love to be able to just use markdown inside todonotes to not waste time with nesting itemize etc.

Sadly, i can't seem to make it work: my many attempts to put a markdown env inside a todonote like this

\todo[...]{\begin{markdown}...\end{markdown}}

have failed with many errors (mostly seems to be runaway arg) sounding something like this:

Argument of ^^M has an extra }.

Any ideas / help / pointers?

#### MCVE:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{markdown}
\usepackage{todonotes}

\begin{document}

% normal markdown works:
\begin{markdown}
* woah
* bullets
\end{markdown}

% todonotes work
\todo[inline,prepend,caption={WOAH}]{yay}

% todonotes with itemize work
\todo[inline,prepend,caption={WOAH}]{yay
\begin{itemize}
\item woah
\item complicated bullets
\end{itemize}
}

% todonotes with markdown break
\todo[inline,prepend,caption={WOAH}]{nay
\begin{markdown}
* woah
* bullets easy
* boom
\end{markdown}
}

\end{document}


• Are your todonotes also inline in your real document, or is that just for this example? And do you want to use other parts or markdown as well, or is it only for easy bullet lists? Dec 9, 2021 at 21:33
• Dec 10, 2021 at 2:31
• @user202729 while the question you linked would most probably work it does sort of fail the goal of the OP to make it easier to include lists, because now they would need extra commands/environments to store a box and use it later. Dec 10, 2021 at 10:20
• Also, it seems that you're using LuaLaTeX, in that case no need for inputenc and fontenc. (... see the warning...) Dec 10, 2021 at 10:49
• @Marijn yes, they're inline. We like to draft/outline in the todonotes, then use disable to hide the block keeping the outline in the source. Not super fancy markdown, but nested lists, links, code etc. would be nice. Dec 10, 2021 at 14:19

In this case, markdown is a verbatim environment so it cannot be used inside the argument of most commands.

See https://texfaq.org/FAQ-verbwithin for more details.

A fix that does not involve much code change uses cprotect. Note the extra brace group around \todo[inline,prepend,caption={WOAH}].

\documentclass{article}
\usepackage{markdown}
\usepackage{todonotes}
\usepackage{cprotect}

\begin{document}

\cprotect{\todo[inline,prepend,caption={WOAH}]}{nay
\begin{markdown}
* woah
* bullets easy
* boom
\end{markdown}
}

\end{document}


For explanation, see the documentation of cprotect package.

Note that \cprotect[om]\todo[inline, ...]{nay ...} does not work because the optional argument must not be protected (the details what protect means is quite complex, see my answer for more details.)

Alternatively it's possible to redefine \todo like this

\NewCommandCopy\oldtodo\todo
\outer\def\todo[#1]{\icprotect{\oldtodo[#1]}}

• See cprotect documentation for why icprotect should be used.
• \NewCommandCopy is required because internally \todo uses some mechanism to protect it (prevent it from being expanded in expand-only context).
• (remark: in the last method the argument wrapped in [...] is not optional. Just for demonstration purposes.) Dec 10, 2021 at 11:26
• i'm pretty happy with the alternative re-defining todo here and going to accept this as an answer... i however seem to be unable to define a \newcommand{\todoPersonA}[2][]{\icprotect{\oldtodo[inline, prepend, caption={A}, #1]}{#2}} on top of this (despite trying basically all bracketing combinations and \def based ones i could think of). Any obvious ideas on how to make something like \todoPersonA{...\begin{markdown}yay, markdown here\end{markdown}...} work too? Dec 10, 2021 at 15:40
• @JörnHees \newcommand{\todoPersonA}[1][]{\icprotect{\todo[inline, prepend, caption={A}, #1]}}. (by the way, I recommend learning TeX properly instead of "programming by permutation".) Dec 10, 2021 at 15:43
• kudos!!! and WAT?!? (and: fair point if i didn't try understanding first combining what the cprotect package docs offer with what you showed... seeing your solution i clearly don't seem to understand why i need to pretend that \todoPersonA only has one arg here, but then can use it like i want with an optional and a mandatory one afterwards (\todoPersonA[..., disable]{...\begin{markdown}...\end{markdown}...}). So yeah, maybe some (La)TeX basics missing there, but i seem to fail at even phrasing a single google query that returns anything helpful :-/) Dec 10, 2021 at 16:13
• @JörnHees Well yes, I know how hard it is to come across good resources. Searching "LaTeX tutorial" etc. just result in typesetting tutorials, because way too few people cares about the programming details – anyway there's tex core - What is the best way to learn TeX? - TeX - LaTeX Stack Exchange and my answer for the resource list. Dec 10, 2021 at 16:36

An alternative approach to avoid markdown. Not that markdown is anything to be avoided, and I would recommend the answer by user202729, but just to showcase some packages.

The following shows inline todonotes as a tcolorbox. Inside the tcolorbox is an easylist, which provides a simple syntax for (nested) lists similar to markdown. Also in the example is a raw link, a labeled link and some code.

The tcolorbox environments can be 'disabled' by redefining them as the comment environment from the verbatim package.

By copying the definition of the itemize style for easylist into the preamble as default the syntax for a list inside the document is simplified a bit (otherwise it would be \begin{easylist}[itemize]). Also the syntax for the other elements (links and code) should be relatively simple and fast to type.

MWE:

\documentclass{article}
\usepackage[at]{easylist}
% set itemize style as default
\ListProperties(Hang=true,Space=4pt,Space*=4pt,Hide=1000,%
Margin1=1.5em,Style1*=\textbullet\hskip .5em,%
Margin2=3.7em,Style2*=--\hskip .5em,%
Margin3=5.9em,Style3*=$\ast$\hskip .5em,%
Margin4=7.8em,Style4*=$\cdot$\hskip .5em)%
\usepackage{tcolorbox}
\usepackage{hyperref}
\usepackage{verbatim} % for switching off tcolorbox
\tcbset{
colback=red!5!white,
colframe=red!75!black,
}

% uncomment the next line to disable tcolorbox
%\renewenvironment{tcolorbox}{\comment}{\endcomment}
\begin{document}
Some text

\begin{tcolorbox}[title=WOAH]
\begin{easylist}
@ item 1
@ item2
@@ nested item
@ item3
\end{easylist}
\url{https://tex.stackexchange.com}\\
\href{https://tex.stackexchange.com}{TeX.SE}\\
\verb+return "@#\$%^&"+
\end{tcolorbox}

More text
\end{document}


Result: