
我看到了幾個問題,例如這個要求解決方案分解 URL。
我想知道是否可以像普通文字中那樣對 URL 中的單字進行連字符(即,借助連字符引擎將單字分開不添加連字符而是一個特殊字元),請參見範例 1。
- 指示換行:為了避免對連字符 URL 產生誤導性解釋,我希望看到一個特殊字符,例如回車連字符位置的符號。
- 連字號與破折號:我不希望連字符引擎插入新的連字符,這可能會被誤解為 URL 的一部分。
如果連字引擎在某個位置中斷了 URL短跑(破折號是 URL 的一部分),必須插入特殊字符,請參閱範例 2。
- 如果連字引擎在某個位置中斷了 URL削減(斜線是 URL 的一部分),必須插入特殊字符,請參閱範例 3。
所需的連字符應適用於段落、註腳和參考書目。
例子:
(1) http://www.w3.org/hypertext-transport-protocol/secure/test/appli↩
cationformular.html
(2) http://www.w3.org/hypertext-transport-↩
protocol/secure/test/applicationformular.html
(3) http://www.w3.org/hypertext-transport-protocol/secure/↩
test/applicationformular.html
相關工作:
- 這Peter Grill 發佈的解決方案引入了一個新命令。我想使用現有的
\url
命令。此外,他的解決方案在每個字元上都會打斷單詞,而我想依賴連字符引擎使用正確連字符的決定。
答案1
這適用於 T1 和 OT1 編碼,需要修改其他編碼(基本上需要一些不可見的字元用作假連字字元)
可以看出,如果沒有添加中斷(第一個範例),則不會添加箭頭,或者如果在 URL 語法之後中斷/
或.
(第二個範例)或在連字符點(例如example-ple)處中斷,則會添加箭頭(第三個範例)
正如發布的那樣,箭頭粘在右邊距中,如果您希望它們位於文本塊內,請\rlap
從\discretionary
.
另外,正如發布的那樣,這定義了\brkurl
問題,要求在需要時\url
僅全域刪除命令。brk
\documentclass{article}
%\tracingonline1
%\showboxbreadth=200
%\showboxdepth=200
\begin{document}
\def\addurlspace#1{%
\ifx\relax#1%
\else
\ifx/#1\space\fi
\ifx.#1\space\fi
#1%
\ifx/#1\space\fi
\ifx.#1\space\fi
\expandafter\addurlspace
\fi}
\makeatletter
\@namedef{OT1-zwidthchar}{255}
\@namedef{T1-zwidthchar}{"17}
\def\brkurl#1{%
\edef\savedhchar{\the\hyphenchar\font}%
\global\setbox1\hbox{}%
\setbox0=\vbox{\hsize=2pt\rightskip=0pt plus 1fill
\hfuzz\maxdimen
\tracinglostchars0
\overfullrule0pt
\hyphenchar\font=\csname \f@encoding-zwidthchar\endcsname
\noindent \hskip0pt \addurlspace #1\relax
\par
\loop
\setbox4 \lastbox
\ifvoid4 \else
\global\setbox1\hbox{\unhbox4\unskip\unskip\discretionary{\hbox{\rlap{$\leftarrow$}}}{}{}\unhbox1}%
\unskip
\unskip
\unpenalty
\unskip
\repeat
}%
\unhbox1
\hyphenchar\font\savedhchar
\relax}
\makeatother
some text \brkurl{http://www.example.com/this/directory/here}
some text \brkurl{http://www.example.com/this/directory/here} some text
some text \brkurl{http://www.example.com/this/directory/here} some text
\end{document}