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'm new to this forum and a recent LaTeX user. I state that, before posting here, I searched all the web through, but I was not succeeded to solve a doubt.

I'm writing my own class (myclass.cls), part of which implements a small list parser. Since I need to keep the code organized, I want to put the relative portion of code in a separate file and then include it in myclass.cls. The code provides a set of newcommands for processing a list, it does not have anything to do with document style.

My doubt is just about the extension of that file: .sty, .def or any other? Besides, is there a rule of thumb for choosing the more appropriate extension (between .sty and .def I mean)?

share|improve this question
Welcome to TeX.sx! Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Upvoting is the preferred way here to say "thank you" to users who helped you. –  Marco Daniel Apr 14 '12 at 16:22
Welcome! Actually this is not a forum, but a question and answer site. This means there is only one question per thread which possible solutions (and only such) are added as answers. Have a look at the about page which explains this further. Nice question, btw! –  Martin Scharrer Apr 14 '12 at 16:34
@andrea: This isn't a mistake. You are getting started;-) –  Marco Daniel Apr 14 '12 at 17:18
Indeed, don't take your comments as complaints. They are not meant as such, but instead as info and help. –  Martin Scharrer Apr 14 '12 at 17:31
offtopic: Wow the TeX community is really welcoming and helpful! –  jli Apr 14 '12 at 23:38
show 2 more comments

1 Answer

The .sty extension is used for packages, i.e. modules which are independent from the class and can be loaded using \usepackage[<options>]{<package name>}. It should not be used for organizing class code.

The .def extension is sometimes used to load additional definitions from within packages, e.g. like language, font or encoding specific things which are selected through package options.

If you simply want to organize your code into multiple files, which are not independent from each other, then I would recommend you to use .def and definitely not .sty. You can use .tex as well. This makes it look a little like a document, but as long these files are only in a package/class directory it is fine. Also, you can even use your own extension if you really want. (La)TeX doesn't care about that.

You can use \input{<filename>} to read these files inside your class file. If you use .tex then you don't need to mention the extension because it is the default.

Alternatively, you can keep your code organized in several files (with any extension), but then build a single class file from them. The docstrip utility allows for this. This way the files can also include code documentation, which is stripped for the released file, in order to make it load faster.

share|improve this answer
Is there any specific way of loading a .def compared to a .sty (and others)? What about .cfg? Could you expand your answer? –  Werner Apr 14 '12 at 16:43
@Werner: There is no technical difference between .def and .cfg. It's just a naming convention thing. Both are loaded using \input{<filename>}. Package instead are loaded using \usepackage and have the option interface and a protection of being loaded multiple times. Is the current form of the answer ok? I kept updating it right after the initial posting. –  Martin Scharrer Apr 14 '12 at 16:48
@Werner there are no specific loading commands for extensions other than cls/sty/tex however latex sometimes uses the convention that it looks first for cfg (ConFiGuration) and loats .ltx if it is not there. \InputIfFileExists{fonttext.cfg} {\typeout{====================================^^J% ^^J% Local config file fonttext.cfg used^^J% ^^J% ====================================}% \def\@addtofilelist##1{\xdef\@filelist{\@filelist,##1}}% } {\input{fonttext.ltx}} \fi –  David Carlisle Apr 14 '12 at 16:49
Thanks @Martin, you really helped me a lot. Actually, at the beginning I opted to use .tex extension for the file with code to be included in the class, but taking a look at the directory texmf/tex/latex/, I did not find any class doing that and so I got confused. –  andrea Apr 14 '12 at 17:24
@MartinScharrer: It's fine then. –  Werner Apr 14 '12 at 18:18
add comment

Your Answer


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.