I am attempting to use colorbox
from xcolor
to highlight changes to a revised manuscript I am submitting (my first LaTeX based manuscript). I have found that the method works well for single to multiple word changes but after ~5 words the colorbox either alters the spacing of the entire paragraph or, in the case of entire sentence changes, extends past the bounds of the page as a single like.
For example, my original paragraph might look like
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\newcommand{\highlight}[1] {\colorbox{yellow}{#1}}
\begin{document}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum vitae turpis nulla. Nam tincidunt fringilla elementum. Suspendisse et sem in velit bibendum pellentesque. Suspendisse luctus neque dignissim libero hendrerit mattis. Suspendisse arcu mi, dignissim eu porta nec, porta at ligula. Aliquam laoreet odio non consequat congue. Praesent non aliquam mauris, et convallis lectus. Donec id vulputate diam. Integer fringilla, libero quisvolutpat efficitur, augue massa vulputate enim, id hendrerit diam sapien vel lorem.
\end{document}
But highlight
ing a phrase near the edge of a paragraph I get
Even worse, when highlighting multiple words and even sentences like so
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\newcommand{\highlight}[1] {\colorbox{yellow}{#1}}
\begin{document}
\highlight{Lorem} ipsum dolor sit amet, \highlight{consectetur adipiscing} elit. Vestibulum vitae turpis nulla. Nam tincidunt fringilla \highlight{elementum}. Suspendisse et sem in velit bibendum pellentesque. Suspendisse luctus neque dignissim libero hendrerit mattis. \highlight{Suspendisse arcu mi, dignissim eu porta nec, porta at ligula. Aliquam laoreet odio non consequat congue.} Praesent non aliquam mauris, et convallis lectus. Donec id vulputate diam. Integer fringilla, libero quisvolutpat efficitur, augue massa vulputate enim, id hendrerit diam sapien vel lorem.
\end{document}
I get this ugly mess running off the edge of the page and adding spacing between lines when a highlight in the line above aligns with one in the line below.
Is there a way to fix my text highlighting implementation? Is there a better package to use that supports multi-line highlighting that works under Overleaf?
\mbox
so an unbreakable one line box, dont use it for in-paragraph highlights, see for example thesoul
package for highlight commands.