[Tex/LaTex] Automatic line breaks in path{} command

line-breakingpathsurls

i use the \path{} command to print out a path to a directory in my *.tex File. I searched a lot around the internet to solve the problem to automatically linebreak the path-url.

I found some hints and maybe solutions, like \usepackage[hyphens]{url}, \setlength{\emergencystretch}{2pt} or

%\def\UrlBreaks{
%\do\a\do\b\do\c\do\d\do\e\do\f\do\g\do\h\do\i\do\j%
%\do\k\do\l\do\m\do\n\do\o\do\p\do\q\do\r\do\s\do\t%
%\do\u\do\v\do\w\do\x\do\y\do\z\do\A\do\B\do\C\do\D%
%\do\F\do\G\do\H\do\I\do\J\do\K\do\L\do\M\do\N%
%\do\O\do\P\do\Q\do\R\do\S\do\T\do\U\do\V\do\W\do\X%
%\do\Z\do\_}%

But non of them the solution i want. it work's with this solutions but sometimes i get to much space between the words before and after the path-url of the next line in text will not correctly break. The text gos over my defined textwidth. So i want a solution where the path-url breaks the word correctly to my selected babel language; for my work in german.

Here two example of some of my path-urls:

  • HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\SystemCertificates\AuthRoot
  • \%APPDATA\%\Microsoft\Crypto

Is there such a way? Or how can i get a superb, clean and good working url line break with using the path{} command? thanks!

Best Answer

Whether TeX can break the lines without over or underfull boxes is as much related to the paragraph settings as the url setting.##This shows several widths set raggedright with no overfull boxes.

enter image description here

\documentclass{article}
\usepackage{url}
\parindent0pt

\begin{document}

{\raggedright
X\dotfill X

\path|HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\SystemCertificates\AuthRoot|

\path|\%APPDATA\%\Microsoft\Crypto|

X\dotfill X
}

\bigskip

\begin{minipage}{.5\textwidth}\raggedright

X\dotfill X

\path|HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\SystemCertificates\AuthRoot|

\path|\%APPDATA\%\Microsoft\Crypto|

X\dotfill X
\end{minipage}

\bigskip

\begin{minipage}{.25\textwidth}\raggedright

X\dotfill X

\path|HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\SystemCertificates\AuthRoot|

\path|\%APPDATA\%\Microsoft\Crypto|

X\dotfill X
\end{minipage}


\end{document}