I am trying to print URL and other paths within a gray-colored box. However, I cannot do so. The moment I use \colorbox with \path, the line breaking stops working. It appears as if \colorbox stops \path from breaking lines; \color doesn't.
Is there a way to rectify it?
I tried reading through url.sty but my limited understanding of LaTeX could not decipher it. I tried going through the definitions of \path and \colorbox. Didn't understand it much though.
\path:
macro:->\leavevmode \begingroup \urlstyle {tt}\Url
\colorbox:
macro:#1{->\protect \color@box {#1}{
\color@box {#1}{:
undefined
Here are two related (maybe) but different questions
Here's my MWE
\documentclass{article}
\usepackage{letltxmacro}
\usepackage[obeyspaces]{xcolor}
\usepackage[obeyspaces]{url}
\usepackage{etoolbox}
\LetLtxMacro{\oldpath}{\path}
\renewcommand{\path}[1]{{\colorbox{gray!8}{\oldpath{#1}}}}
\newrobustcmd\pathcb[1]{\colorbox{gray!8}{\path{#1}}}
\begin{document}
\colorbox{gray!7}{\parbox{\dimexpr\linewidth-2\fboxsep}{\strut \path{https://tex.stackexchange.com/questions/77877/line-break-inside-a-verbhttps://tex.stackexchange.com/questions/77877/line-break-inside-a-verb}\strut}}
\pathcb{https://tex.stackexchange.com/questions/77877/line-break-inside-a-verbhttps://tex.stackexchange.com/questions/77877/line-break-inside-a-verb}
\path{https://tex.stackexchange.com/questions/77877/line-break-inside-a-verbhttps://tex.stackexchange.com/questions/77877/line-break-inside-a-verb}
\end{document}
I tried Werner's answer to breakable colorbox but the lines still won't break. I'd rather avoid TiKz, having absolutely no knowledge about it.
Do let me know if I can provide more details.

~or%) in the argument of some other command is normally not a good idea, if the command is not specially meant for verbatim material. Imho your best bet to get something working is tikzmarks at the begin and the end. But before trying to get something working: background color is a rather brutal method to emphasize. Do you really think it is a good idea to use it in running text? – Ulrike Fischer Jun 29 '17 at 13:05I am a path. I was hoping to borrow this style – abyshukla Jun 30 '17 at 05:28