4

I want to create a package and use it.

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{test}[just a test]
\RequirePackage{calc}

\newcommand{\test}
{
 Lorem Ipsum
}

\endinput

the file is named test.sty. In my main.tex, I use \usepackage{test} to reference the package.

As soon as I build the file with MikTex / TeXworks, I get the following error:

(C:/.../test.sty)
! Missing number, treated as zero.
<to be read again> 
                   j
l.9 

?

If I press continue, I also get the following errors:

Missing number, treated as zero. []
Missing = inserted for \ifnum. []
Missing number, treated as zero. []
LaTeX Error: Missing \begin{document}. []

My main.tex file looks like this:

\documentclass[12pt]{article}
\usepackage{color}
\usepackage{calc}
\usepackage{listings}
\usepackage{test}
\title{test}
\author{me}
\date{\today}
\begin{document}
\maketitle
\test
\end{document}

What did I do wrong?

  • ProvidesPackage expects a date in the optional parameter – Bordaigorl Dec 1 '16 at 14:07
  • 2
    You should use the format \ProvidesPackage{<name>}[yyyy/mm/dd package <name>] – Bordaigorl Dec 1 '16 at 14:08
4

Trying to write your own package/class is a great way to learn LaTeX in more depth. However there is some black magic involved and you need to read the documentation to avoid common pitfalls. In your specific case, you are not following the expected format for the arguments of \ProvidesPackage. How do we know the correct format? You can run the command

texdoc clsguide

to get the standard guide for writing packages and classes. In section 3.1 you'll find:

The first thing a class or package file does is identify itself. Package files do this as follows:

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{⟨package⟩}[⟨date⟩ ⟨other information⟩]

For example:

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{latexsym}[1994/06/01 Standard LaTeX package]

You could have spotted the mistake in your MWE by reading carefully the log: it says it is expecting a number but found a j. The only j in your code is the one in the optional argument of \ProvidesPackage, [just a test].

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.