Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I understand that "the convention is to use \RequirePackage in a package or class and \usepackage in a document", but apart from that, is there any practical difference between the two commands?

(I am thinking for example that it could be the case that \RequirePackage is a "stronger" command and you wouldn't run into problems with hyperref not being at the end)

share|improve this question
    
You're question has been answered for the most part, so this is just a comment. What hasn't been answered was the final question about problems caused by hyperref not being at the end. RequirePackage isn't going to help with that problem. In fact, it may well make it worse. (What if you want to use two packages, both of which RequirePackage{hyperref} ?) Take great care if you RequirePackage{hyperref} in some package. It had better be the last package you need. –  David Hammen Jun 5 '11 at 19:42
    
Well, yeah, I meant your, not you are. Yet another example of the necessity of editors. –  David Hammen Jun 6 '11 at 1:06

5 Answers 5

up vote 30 down vote accepted

Sorry but there is a difference, you can write :

\RequirePackage{atbegshi}      
\documentclass ....

and not

\usepackage{atbegshi}      
\documentclass ...
share|improve this answer
    
@xport: I don't see the answer of Herbert when I wrote my personal answer. Herbert is very speed and a great texpert ! –  Alain Matthes Jun 5 '11 at 7:05
    
@xport: Altermundus' answer was posted before Herbert's answer. –  Philipp Jun 5 '11 at 7:50
    
@Philipp: I am sorry. I misinterpreted the counter. :-) –  xport Jun 5 '11 at 7:53
    
Changed the accepted answer to this one (given that it was posted before the other 2 correct ones) –  Vivi Jun 5 '11 at 8:35

Both expand to \@fileswithoptions \@pkgextension. I.e., no difference.

share|improve this answer
11  
no, that's not correct ... –  Herbert Jun 5 '11 at 6:56
4  
\usepackage is first defined to an error message but than \let\usepackage\RequirePackage is executed by \documentclass. –  Martin Scharrer Jun 5 '11 at 9:23
    
@Herbert: Sure. I can think of exactly one situation where one needs to include a package before a documentclass. Maybe there are others, but for most purposes, they are functionally identical and certainly one is not "stronger" than another. –  TH. Jun 6 '11 at 8:34
1  
@TH what is that situation? –  rogerl Mar 26 at 22:20

you can use \RequirePackage before the \documentclass statement, which has some advantages in some special cases.

share|improve this answer

The only difference is that \usepackage cannot be used before \documentclass. Otherwise there is no functional difference. The LaTeX kernel defines \usepackage to issue an error message initially, and \documentclass is defined as

\def\documentclass{%
  \let\documentclass\@twoclasseserror % a second \documentclass command produces an error
  \if@compatibility\else\let\usepackage\RequirePackage\fi % define \usepackage to be the same as \RequirePackage
  \@fileswithoptions\@clsextension}
share|improve this answer
    
Thanks. Your answer added a lot to my understanding, but I will accept @Altermundus' answer since it was given first. –  Vivi Jun 5 '11 at 8:36

From a technical point \usepackage is first defined to the error message \usepackage before \documentclass but than set to the definition of \RequirePackage by the \documentclass before the class file is loaded. You can use \RequirePackage before \documentclass, which might be sometimes required.

However, the true difference is the logical usage: \usepackage is an user macro intended for the document file while \RequirePackage is intended for package and class files to describe dependencies. Using \usepackage inside a package will also work, as long it isn't loaded with \RequirePackage before \documentclass. :-)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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