# todonotes: How to make literally inline notes without line breaks?

For the following MWE, I need the inline note to be in the same line without extra space or additional line breaks.

\documentclass{article}
\usepackage{todonotes}
\author{diaa}
\begin{document}
some text \todo[inline]{my note} another text
\end{document}


## Edit #1

How to make the inline note behave like a normal piece of its respective paragraph?

In other words, I don't need the inline note to behave like this

or like this

• Are the notes to be inserted as text, squeezing aside adjacent text? If so, you can just use a some text \colorbox{orange}{my text} another text. If they are to be inserted between lines without affecting the underlying spacing, perhaps an answer like this, tex.stackexchange.com/questions/142242/…, may help. – Steven B. Segletes Sep 15 '16 at 9:43
• @StevenB.Segletes Thanks for your suggestion, but I want to exploit the todonotes features. So, it is better for me to change the way inline notes are printed. – Diaa Sep 15 '16 at 9:45
• Please try to draw what you want the result to look like. What I think that you request is not possible with the todonotes package at the moment. – midtiby Sep 15 '16 at 10:12
• @midtiby Please take a look at my desired output. – Diaa Sep 15 '16 at 10:26
• – midtiby Sep 15 '16 at 10:52

You could do something like this (I assume that you are using pdflatex). There is imho no sensible way to get line breaks inside such todonotes, so I set a maximum size of 5cm. But as they will destroy the layout anyway I don't think that it matters much that you get large line spacing or bad line breaks with long notes.

The code naturally change all inline todos.

\documentclass{article}
\usepackage{todonotes,varwidth}
\makeatletter
\tikzstyle{diaanotestyle} = [
draw=\@todonotes@currentbordercolor,
fill=\@todonotes@currentbackgroundcolor,
line width=0.5pt,
inner sep = 0.8 ex,
rounded corners=4pt,align=left,
]

\renewcommand{\@todonotes@drawInlineNote}{%
{\begin{tikzpicture}[remember picture,baseline={(0,0)}]%
\draw node[diaanotestyle,font=\@todonotes@sizecommand,anchor=base west]{%
\begin{varwidth}[t]{5cm}
\if@todonotes@authorgiven%
{\@todonotes@sizecommand \@todonotes@author:\,\@todonotes@text}%
\else%
{\@todonotes@sizecommand \@todonotes@text}%
\fi
\end{varwidth}};%
\end{tikzpicture}}%
}%
\makeatother
\author{diaa}
\begin{document}
some text \todo[inline]{my note} another text  \todo[inline]{a long comment a long comment a long comment a long commenta long comment a long comment} abllclc blblb blblb blblb blblb blblbl blblb
\end{document}


## Edit

If you really need line breaks in the notes you can try to use this answer Cool Text Highlighting in LaTeX. Be aware that the soul code is rather fragile. Not everything can be put in the note text without protection. Read the documentation.

As an example (I don't have the time to adjust the style):

\documentclass{article}
\usepackage{todonotes}
\usepackage{soul}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.pathmorphing}

\makeatletter

\newcommand{\defhighlighter}[3][]{%
\tikzset{every highlighter/.style={color=#2, fill opacity=#3, #1}}%
}

\defhighlighter{yellow}{.5}

\newcommand{\highlight@DoHighlight}{
\fill [ decoration = {random steps, amplitude=1pt, segment length=15pt}
, outer sep = -15pt, inner sep = 0pt, decorate
, every highlighter, this highlighter ]
($(begin highlight)+(0,8pt)$) rectangle ($(end highlight)+(0,-3pt)$) ;
}

\newcommand{\highlight@BeginHighlight}{
\coordinate (begin highlight) at (0,0) ;
}

\newcommand{\highlight@EndHighlight}{
\coordinate (end highlight) at (0,0) ;
}

\newdimen\highlight@previous
\newdimen\highlight@current

\DeclareRobustCommand*\highlight[1][]{%
\tikzset{this highlighter/.style={#1}}%
\SOUL@setup
%
\def\SOUL@preamble{%
\begin{tikzpicture}[overlay, remember picture]
\highlight@BeginHighlight
\highlight@EndHighlight
\end{tikzpicture}%
}%
%
\def\SOUL@postamble{%
\begin{tikzpicture}[overlay, remember picture]
\highlight@EndHighlight
\highlight@DoHighlight
\end{tikzpicture}%
}%
%
\def\SOUL@everyhyphen{%
\discretionary{%
\SOUL@setkern\SOUL@hyphkern
\SOUL@sethyphenchar
\tikz[overlay, remember picture] \highlight@EndHighlight ;%
}{%
}{%
\SOUL@setkern\SOUL@charkern
}%
}%
%
\def\SOUL@everyexhyphen##1{%
\SOUL@setkern\SOUL@hyphkern
\hbox{##1}%
\discretionary{%
\tikz[overlay, remember picture] \highlight@EndHighlight ;%
}{%
}{%
\SOUL@setkern\SOUL@charkern
}%
}%
%
\def\SOUL@everysyllable{%
\begin{tikzpicture}[overlay, remember picture]
\path let \p0 = (begin highlight), \p1 = (0,0) in \pgfextra
\global\highlight@previous=\y0
\global\highlight@current =\y1
\endpgfextra (0,0) ;
\ifdim\highlight@current < \highlight@previous
\highlight@DoHighlight
\highlight@BeginHighlight
\fi
\end{tikzpicture}%
\the\SOUL@syllable
\tikz[overlay, remember picture] \highlight@EndHighlight ;%
}%
\SOUL@
}

\renewcommand{\@todonotes@drawInlineNote}{%
{%
\expandafter\highlight\expandafter{\@todonotes@text }%
}}%

\makeatother

\author{diaa}
\begin{document}
some text \todo[inline]{my note} another text  \todo[inline]{a long comment a long comment a long comment a long commenta long comment a long comment} abllclc blblb blblb blblb blblb blblbl blblb
\end{document}


• Many thanks for your answer. Seemingly, my question is not quite clear. I intended to make this inline note part of its paragraph like its surrounding text. By doing so, I can refer to it in the list of todos as I need to, for example, submit an article with my changes highlighted by inline notes and listed in the list of todos. Anyway, your answer is helpful to me and I appreciate it. – Diaa Sep 15 '16 at 12:16
• I edited my question to clarify what I exactly need. – Diaa Sep 15 '16 at 12:33

You will have to change some internals of todonotes. There are a couple of things:

1. The drawing of the node with tikz, especially getting the baseline correct
2. Eliminating the \par's around it and the text width
3. Not gobbling the spaces around the node

The following code does that:

\makeatletter
\tikzstyle{inlinenotestyle} = [
draw=\@todonotes@currentbordercolor,
fill=\@todonotes@currentbackgroundcolor,
line width=0.5pt,
inner sep = 0.8 ex,
rounded corners=4pt]

\renewcommand{\@todonotes@drawInlineNote}{%
{\begin{tikzpicture}[remember picture,baseline=(current bounding box.base)]%
\draw node[inlinenotestyle,font=\@todonotes@sizecommand, anchor=base,baseline]{%
\if@todonotes@authorgiven%
{\noindent \@todonotes@sizecommand \@todonotes@author:\,\@todonotes@text}%
\else%
{\noindent \@todonotes@sizecommand \@todonotes@text}%
\fi};%
\end{tikzpicture}}}%
\newcommand{\mytodo}[1]{\@todo[inline]{#1}}%
\makeatother


Then use it:

Some text. \mytodo{my note} More text.


• When I try to make the note very long, it doesn't break and follow the linewidth. Is it possible to do so? – Diaa Sep 15 '16 at 12:22

I would suggest to do define the following command

\newcommand{\inline}[1]{{\color{red}{#1}} \addcontentsline{tdo}{todo}{#1}}


The comment is then highlighted and added to the list of todos. It is a very simple approach, but seems to work when the note covers multiple lines.

Right now I cannot change the background color of the text, so I have chosen to change the color of the text instead.

See the following example document.

\documentclass{article}
\usepackage{todonotes}