
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つの関連している(かもしれない)が異なる質問があります
これが私の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}