URLの\pathコマンドでカラーボックスを使用する

URLの\pathコマンドでカラーボックスを使用する

URL やその他のパスを灰色のボックス内に印刷しようとしています。しかし、できません。 を使用した瞬間に\colorbox、改行が機能しなくなります。 は改行を停止している\pathように見えますが、実際には停止していません。\colorbox\path\color

それを修正する方法はありますか?

読んでみましたが、LaTeX に関する私の限られた知識では解読できませんでした。とurl.styの定義を読んでみましたが、あまり理解できませんでした。\path\colorbox

\path:
macro:->\leavevmode \begingroup \urlstyle {tt}\Url 


\colorbox:
macro:#1{->\protect \color@box {#1}{

\color@box {#1}{:
undefined

ここに2つの関連している(かもしれない)が異なる質問があります

  1. \path の使用をスキャン中にファイルが終了しました
  2. コマンド自体を含むようにコマンドを再定義できますか?

これが私の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}

私は試した壊れやすいカラーボックスに対するヴェルナーの答えしかし、行はまだ分割されません。TiKz についてはまったく知識がないので、避けたいと思います。

さらに詳しい情報を提供できる場合はお知らせください。

答え1

\urlおよびなどのコマンド\path しない彼らの議論を吸収しますが、その間にいくつかの設定を行うためにそれを遅らせます。

フォント属性として色を追加します。

\documentclass{article}
\usepackage{xcolor}
\usepackage[obeyspaces]{url}
\usepackage{etoolbox}

\appto{\UrlFont}{\color{gray!70}}

\begin{document}

Some text for triggering a line break
\url{https://tex.stackexchange.com/questions/77877/line-break-inside-a-verb}
\url{https://tex.stackexchange.com/questions/77877/line-break-inside-a-verb}
and some text after the links

\end{document}

ここに画像の説明を入力してください

関連情報