[Tex/LaTex] Why typesetting file path not working

pathsurls

I know this How to typeset a file path?
I think that the PATH command works like making possible to use shorter PATH in URLs.
I have documents in my filesystem which I often include in my notes.
I would like to assign their folder location by the path -command.
However, I am not sure if I use the right function because of unexpected result below.

Code

\documentclass{article}
\usepackage[obeyspaces]{url}
\begin{document}

\path{/Users/masi/Dropbox/Internal Diseases}

\url{PubMed Central, Table 3_ Diabetes Care. 2010 Jan; 33(Suppl 1)_ S62–S69. doi_  10.pdf} 

\end{document}

Output:

/Users/masi/Dropbox/Internal Diseases

PubMed Central, Table 3_ Diabetes Care. 2010 Jan; 33(Suppl 1)_ S62–S69. doi_  10.pdf 

Expected output:

/Users/masi/Dropbox/Internal Diseases/PubMed Central, Table 3_ Diabetes Care. 2010 Jan; 33(Suppl 1)_ S62–S69. doi_  10.pdf

2nd example having pseudocode

\documentclass{article}
\usepackage[obeyspaces]{url}
\begin{document}

\somePathCommand{/Users/masi/Dropbox/Internal Diseases}

\someHrefCommand{PubMed Central, Table 3_ Diabetes Care. 2010 Jan; 33(Suppl 1)_ S62–S69. doi_  10.pdf}{Diabetes Guideline}

\end{document}

which should print the link Diabetes Guideline i.e. having redirection to:

/Users/masi/Dropbox/Internal Diseases/PubMed Central, Table 3_ Diabetes Care. 2010 Jan; 33(Suppl 1)_ S62–S69. doi_  10.pdf

How can you typeset correctly the file path?
I.e. use it with images, and do not print the actual path in the document as text.

Best Answer

I'm not sure if I fully understand your objective. I can offer the following observations:

  • The url package defines \path as an "alias" for \url. Using \path may be more mnemonic than using \url if the argument is the name of a "path" rather than an ordinary URL.

  • There's one important difference, though, between \url and \path: If the hyperref package is loaded, the argument of a \url instruction will be made into a hyperlink, whereas that's not the case with \path.

  • If the path/url is a long and unwieldy string, and if you wish to show just a short stub instead, be sure to load the hyperref package and to use that package's \href macro. This macro takes two arguments: (i) a URL-like string, and (ii) the "stub" that should be shown in the pdf file instead of the URL-like string.

enter image description here

% !TEX TS-program = xelatex
\documentclass{article}
\usepackage{fontspec}
\usepackage[spaces,obeyspaces]{url}
\usepackage[colorlinks=true,allcolors=blue]{hyperref}
\setlength\parindent{0pt} % just for this example
\begin{document}
output of \verb+\path+:

\path{/Users/masi/Dropbox/Internal Diseases/PubMed Central, Table 3_ Diabetes Care. 2010 Jan; 33(Suppl 1)_ S62–S69. doi_  10.pdf}

\bigskip
output of \verb+\url+:

\url{/Users/masi/Dropbox/Internal Diseases/PubMed Central, Table 3_ Diabetes Care. 2010 Jan; 33(Suppl 1)_ S62–S69. doi_  10.pdf}

\bigskip
output of \verb+\href+:

\href{/Users/masi/Dropbox/Internal Diseases/PubMed Central, Table 3_ Diabetes Care. 2010 Jan; 33(Suppl 1)_ S62–S69. doi_  10.pdf}{stub}
\end{document}
Related Question