# Should \urlstyle go into preamble or document body?

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

\documentclass{article}