Skip to content

Custom Packages

TeX makes it easy to create custom packages. Custom packages can be anything from a simple collection of commands, document templates/themes, or even a full-fledged package that provides a new functionality.

Creating a Custom Package

To create a custom package, you need to create a .sty file. The .sty file is a LaTeX package file that contains commands and environments that you want to use in your document.

Here is an example of a simple custom package that defines a new command \hello:

% hello.sty
\ProvidesPackage{hello}
\newcommand{\hello}{Hello, World!}

To use the custom package in your document, you need to load it using the \usepackage command:

\documentclass{article}

\usepackage{hello}

\begin{document}

\hello

\end{document}

Installing a Custom Package

Note

If you plan to use the custom package in multiple documents, it is recommended to install the package in your TeX texmf directory.

To install a custom package, you can place the .sty file in the same directory as your document, or you can install it in your TeX distribution so that it is available to all your documents.

For custom packages it is generally recommended to install them in your user texmf directory. This directory is usually located at ~/texmf/tex/latex/ on Unix-like systems and C:\Users\<username>\texmf\tex\latex\ on Windows.

After placing the .sty file in your texmf directory, you can begin using the package in your documents immediately.

Sharing a Custom Package

If you want to share your custom package with others, you can create a .zip file containing the .sty file and any other necessary files (such as documentation) and distribute it to others.

You can also upload your custom package to a public repository like CTAN (Comprehensive TeX Archive Network) so that others can find and use it easily.