1

Here is my LaTeX code.

\documentclass{article}
\usepackage{hyperref}
\urlstyle{same}
\begin{document}
Example: \url{http://www.example.com/}
\end{document}

My question is about \urlstyle{same}.

I have two questions.

  1. Give a man a fish: I have put \urlstyle{same} in preamble. But putting it in the document body also works fine. What is the right place to put it?
  2. Teach a man to fish: In future, how can I understand (from documentation or by other means) whether a command should go into the preamble or document body?
  • I don't think there's a general rule, but I'd say that commands that can change a certain behavior only once, do not produce any text, or are specified to belong to the preamble have to go to the preamble. \urlstyle is a command that switches the current typesetting style, and I'd expect it to do its job both in the preamble and document body. Note that the command comes from the package url that is missing in your minimal example. – PhilipPirrip Aug 30 '16 at 4:24
  • @PhilipPirrip I thought the \url command comes from the hyperref package which I have included in my example. Or is it that the hyperref package internally includes the url package? – Lone Learner Aug 30 '16 at 5:16
  • @LoneLearner hyperref requires url, but url can be used without hyperref – daleif Aug 30 '16 at 7:40
2

You can use the command in both places. Put it in the preamble if you want to change the general style for (allmost) all url's. Use it in the document (or inside definition of commands like \path, \email etc) if you want to change the style locally for some url's only:

\documentclass{article}
\usepackage{url}
\urlstyle{same}
\begin{document}
Example: \url{http://www.example.com/}

a specially formatted url {\urlstyle{tt}\url{learner@example.com}}
\end{document}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.