59

Sorry to start a subjective question, but want to understand "own.sty" file.

Other than all \usepackage{} what sort of other commands can be added to the makeyourown.sty file. Can you include \let command, and \newcommands in it.

What sort of precaution / structure newbies should follow.

Stefan Kottwitz
  • 231,401
Aku
  • 11,026
  • @Stefan: Thanks for the retag. I'm not sure what I was thinking when I tagged this with {documentclass}... – Caramdir Jan 11 '11 at 22:28

2 Answers2

56

Here is a skeleton for an own package:

% this is my first package
% 
% (c) Buffalo Bill
%
%% This program can be redistributed and/or modified under the terms
%% of the LaTeX Project Public License Distributed from CTAN archives
%% in directory macros/latex/base/lppl.txt.
% 
\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{mypackage}
  [2011/01/11 v0.01 LaTeX package for my own purpose]

\RequirePackage{whateverwe need} \newcommand{\hi}{Hello, this is my own package} \let\myDate\date \newcommand\GoodBye[1][\bfseries]{{#1Good Bye}}

\endinput %% %% End of file `mypackage.sty'.

You can put mypackage.sty in the same directory as the .tex file, into ~/texmf, or somewhere else in latex's package search path—see $ less "$(kpsewhich texmf.cnf)"

  • 6
    And use \RequirePackage instead of \usepackage. – Juan A. Navarro Jan 12 '11 at 12:29
  • 3
    @Juan- I am just curious to know why you asked me to use \RequirePackage instead of \usepackage. Whats the difference. Sorry for coming back to the post this late. – Aku Jan 21 '11 at 01:14
  • The difference is that usepackage doesn't work and LaTeX provides the command RequirePackage, which loads all the required packages when the newly written style file is loaded in a document. – aignas Feb 23 '13 at 20:44
  • 4
    @gns-ank: why should \usepackage not work? –  Feb 25 '13 at 15:57
  • Maybe it does, I have not tried it, I just used RequirePackage always as it was suggested in Leslie Lamport's book LaTeX. I can not remember the real reason now. I found another question on stackexchange: http://tex.stackexchange.com/questions/19919/whats-the-difference-between-requirepackage-and-usepackage – aignas Feb 26 '13 at 20:03
  • So this shows, that actually, this only a convention and there is very little difference. Sorry for being sloppy previously. – aignas Feb 26 '13 at 20:10
  • 2
    (Commenting on this old thread for new people stumbling across it.) If your package imports something via \usepackage and the user then also tries to import the same thing, they will get an error. If you use \RequirePackage this will not happen. – Marc Schulder Oct 25 '21 at 08:00
17

Package files are just input literally, so you can use any command that you can use in document files. Most often it makes sense to include a small amount of identification metadata, to support options, etc.; see clsguide.pdf (texdoc clsguide) for a good introduction.

Philipp
  • 17,641