I have some paragraphs to highlight for later edit in my latex document. For that I use the following code
\newcommand{\hl}[1]{\noindent\colorbox{pink}{\parbox{\dimexpr\linewidth-2\fboxsep} {#1}}}
This does job perfectly when there is a paragraph. But when I need to highlight only a word in a paragraph, I should be able to switch back to just
\colorbox{pink}{#1}
How to implement this automation in the above \newcommand{\hl}.
Kindly note that I did not want to add any package for this purpose other than xcolor for some reason.
MWE:
\documentclass{article}
\usepackage{xcolor}
\usepackage{lipsum}
\newcommand{\hl}[1]{\noindent\colorbox{pink}{\parbox{\dimexpr\linewidth-2\fboxsep} {#1}}} %Highlighter.
\begin{document}
\hl{\lipsum[2]}
\lipsum[1]
Some inline \hl{ text} need to be highlighted.
\end{document}


ifstatement which measure the length of the text and decides what to use with\parboxor\hbox– David Jun 18 '18 at 13:45Theoremin thetheoremenvironment when we use\hl{\begin{theorem} \dots \end{theorem} }? – David Jun 18 '18 at 15:22theoremenvironment has its contents typeset in a\trivlist(similar to anitemize), then it cannot be easily boxed and measured. Even if you put the\hlinside thetheorem, things get weird because\trivlistdoes not allow paragraph breaks (then thePerhaps a missing \itemerror). You can, however, hack thetheoremenvironment and use:\begin{theorem}[Theorem of stuff]\item\hl{\lipsum[2]}\end{theorem}, but remember: it wasn't me who suggested you to do it ;) – Phelype Oleinik Jun 18 '18 at 17:55