Many LaTeX users face small but frustrating problems when inserting web links, email addresses, or file paths into a document.
Sometimes a long link runs past the page margin, sometimes an email address does not become clickable, and sometimes directory paths break because of special characters like underscores.
Below, we will look at simple ways to write URLs, email addresses, and directory paths so that they appear clearly and correctly in your LaTeX document.
Table of Contents
Write URLs Correctly in LaTeX
When you insert a web link directly into LaTeX text, the document may produce errors or break the layout. To avoid this, you should use a dedicated command designed for web addresses.
\url{web_address}
\documentclass{article}
\usepackage{url}
\begin{document}
Visit this website: \url{https://www.physicsread.com}
\end{document}
Create Clickable Links with Custom Text
Sometimes a full web address looks too long in the document. In such cases, you may want a clean label like “Visit Website” while keeping the link clickable.
\usepackage{hyperref}}
\href{URL}{display_text}
-
URLThe first argument contains the web address.
-
display_textThe second argument is the text that appears in the document.
\documentclass{article}
\usepackage{hyperref}
\begin{document}
\href{https://www.physicsread.com}{Visit Example Website}
\end{document}
Handle Long URLs Without Layout Problems
Very long web addresses sometimes extend beyond the page margin. This happens because LaTeX cannot always determine safe break points automatically.
To solve this, you can use the xurl package.
\usepackage{xurl}
\documentclass{article}
\usepackage{xurl}
\begin{document}
\url{https://www.physicsread.com/very/long/path/to/a/page/with/many/sections}
\end{document}
This helps long links break properly so they do not go outside the page and keeps the document layout neat and readable.
Add Email Addresses in LaTeX
Email addresses appear frequently in research papers, reports, and author information sections. In many cases, it is useful to make them clickable.
\use{hyperref}
\href{mailto:email_address}{display_text}
The mailto: prefix tells LaTeX that the link should open an email client when someone clicks the email address.
\documentclass{article}
\usepackage{hyperref}
\begin{document}
\href{mailto:[email protected]}{Contact Me}
\end{document}
If you only want to display the address without creating a clickable link, you can write it using \texttt{}.
\texttt{[email protected]}
The monospaced style makes email addresses easier to notice and different from normal text.
Write Directory Paths Clearly
Directory paths often contain slashes, underscores, and other characters that can confuse LaTeX. To display them safely, you can use either \texttt{} or \path{}.
\path{directory_path}
\documentclass{article}
\usepackage{url}
\begin{document}
\path{/home/user/documents/project}
\end{document}
Alternatively, you can write the path with \texttt{}.
\texttt{C:\Users\John_Doe\Documents}
This approach ensures that underscores and slashes appear correctly and remain easy to read.
Conclusion
LaTeX provides simple commands to handle URLs, email addresses, and directory paths without formatting issues. With the right approach, you can keep your document organized and easy to read.
Jidan
LaTeX enthusiast and physics learner who enjoys explaining mathematical typesetting and scientific writing in a simple way. Writes tutorials to help students and beginners understand LaTeX more easily.