3

I wrote an include file to allow me to draw certain diagrams (that have various different parameters) conveniently, by just calling macros within a tikzpicture. This file is now at about 1500 lines, although a fair amount of that is notes I wrote (in the form of TeX comments) on the various macros in case I come back later and need to remember quickly how they work. Or I suppose, in case someone else wants to use it.

Anyway, I include this file in the preamble of my document just using the \input control sequence. But I know that the "standard" way of making reusable code is to create something called a "package". What extra work (if any) is involved in making this include file into a package, and how will I benefit (if at all)?

  • Please see tex.stackexchange.com/a/48881/963 it requires minimum effort. – Yiannis Lazarides Dec 21 '13 at 15:19
  • no work at all, just rename the file from .tex to .sty – David Carlisle Dec 21 '13 at 17:05
  • @DavidCarlisle What is the purpose of \ProvidesPackage etc. then? – marczellm Dec 21 '13 at 19:03
  • 1
    It's a useful, but optional declaration, so when someone posts here and something doesn't work you can ask tex to reveal what version of the package you have but you don't have to use \ProvidesPackage with \usepackage any more than you have to use \ProvidesFile with \input. The two issues are totally separate. – David Carlisle Dec 21 '13 at 19:24
  • There are some advantages, too, if you choose to use them. You can use warning/informational/checking commands available to package authors. You can easily set the package up to give you information in the output and log. You can also use @ etc. without needing to say \makeatletter...\makeatother. – cfr Dec 22 '13 at 4:17
3

The only thing that you need to do to change a file that you \input into a package is change the extension to .sty (actually LaTeX doesn't require even that, the association of an extension with the package system is part of the system dependent part of latex, but all currently active latex distributions do use that).

It is common to add \ProvidesPackage so that you can declare a file date and version, however that is an optional extra step, and TeX files that you \input may use the similar \ProvidesFile command (although that gets used a lot less than \ProvidesPackage in practice).

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.