[Tex/LaTex] todonotes: How to make literally inline notes without line breaks

todonotes

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}

Output

enter image description here

My Desired Output

enter image description here

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
enter image description here

or like this

enter image description here

Best Answer

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}

enter image description here

enter image description here