[Tex/LaTex] Unable to display an url leading to a *.pdf document

pdftexstudio

Basically, I have an url in the form of "http://website.com/folder/this_is_a_pdf_document.pdf" which I want to display in my document in TeXStudio, however, an error pops up. It seemingly interprets the link as something to do with the math environment; i.e., what I get is this:

"Math command outside of math environment" whenever I hover, with my mouse, over the "_" symbols in the url, which TeXStudio have colored red.

In the "Errors" panel it says that a "$" is missing; which I take that it wants me to go into math mode, again. When the document is compiled and viewed by me, the link that I am trying to display has a crippling "this_is_a_pdf_document.pdf" part; namely, some of the letters are displayed as subscripts, which has, in all probability, have to do with those "_" that TeXStudio is not able to interpret in a non-math environment mode.

So, the question: How do I display the link without TeXStudio thinking that it has anything to do with math environment?

NB! It is not necessary for me to have the url linked a la hyperref usepackage; that is, I do not care that the url is not interactive and takes you to the actual website. Some of the urls that I've successfully displayed have no problems whatsoever (they do not have the "_" symbol in them). The working urls are displayed simply by:

\begin{center}http://www.website.com/setion\end{center}    

In respect to the hyperref usepackage, I've tried the following versions, none of which worked (TeXStudio interprets the "this_is_a_pdf_document.pdf" part of the url as containing math symbols):

\href{URL}{text}, \url{URL}, \nolinkurl{URL}, \hyperref{label}{text}, 
\hypertarget{name}{text}, and \hyperlink{name}{text} 

Thanks a lot!

Best Answer

\url, \href, and \hyperref support URLs, if package hyperref is loaded. Package url alone provides \url:

\documentclass{article}
\usepackage[colorlinks]{hyperref}

\begin{document}
\begin{itemize}
\item \verb|\url|:\\
  \url{http://example.com/folder/this_is_a_pdf_document.pdf}
\item \verb|\href+\nolinkurl|:\\
  \href{http://example.com/folder/this_is_a_pdf_document.pdf}{%
  \nolinkurl{http://example.com/folder/this_is_a_pdf_document.pdf}}
\item \verb|\hyperref+\nolinkurl|:\\
  \hyperref{http://example.com/folder/this_is_a_pdf_document.pdf}{}{}{%
  \nolinkurl{http://example.com/folder/this_is_a_pdf_document.pdf}}
\end{itemize}
\verb|\urlstyle{rm}|\urlstyle{rm}
\begin{itemize}
\item \verb|\url|:\\
  \url{http://example.com/folder/this_is_a_pdf_document.pdf}
\item \verb|\href+\nolinkurl|:\\
  \href{http://example.com/folder/this_is_a_pdf_document.pdf}{%
  \nolinkurl{http://example.com/folder/this_is_a_pdf_document.pdf}}
\item \verb|\hyperref+\nolinkurl|:\\
  \hyperref{http://example.com/folder/this_is_a_pdf_document.pdf}{}{}{%
  \nolinkurl{http://example.com/folder/this_is_a_pdf_document.pdf}}
\end{itemize}
\verb|\urlstyle{sf}|\urlstyle{sf}
\begin{itemize}
\item \verb|\url|:\\
  \url{http://example.com/folder/this_is_a_pdf_document.pdf}
\item \verb|\href+\nolinkurl|:\\
  \href{http://example.com/folder/this_is_a_pdf_document.pdf}{%
  \nolinkurl{http://example.com/folder/this_is_a_pdf_document.pdf}}
\item \verb|\hyperref+\nolinkurl|:\\
  \hyperref{http://example.com/folder/this_is_a_pdf_document.pdf}{}{}{%
  \nolinkurl{http://example.com/folder/this_is_a_pdf_document.pdf}}
\end{itemize}
Free text variants:
\begin{itemize}
\item \verb|\href|:\\
  \href{http://example.com/folder/this_is_a_pdf_document.pdf}{%
  free text}
\item \verb|\hyperref|:\\
  \hyperref{http://example.com/folder/this_is_a_pdf_document.pdf}{}{}{%
  free text}
\end{itemize}
\end{document}

Result

Related Question