# How can I make a single file of the packages I use? [duplicate]

Good morning, I would like to know whether someone can help me with this: I need to learn how can make style file archive.sty, because in the preamble of my source file I have to write all packages and options and this seems bad. I believe it is possible to have a .sty file and have latex compile this automatically, but I don't know how make this.

• If I understand the question then you might be interested in Creating a package of custom-made commands. – campa May 13 '20 at 16:43
• I insteresting in write a style.sty archive but I dont know and need to know how latex can read this archive.sty. – juliana perez ordoñez May 13 '20 at 17:21
• I have taken the liberty of trying to clean up a few typos and uncertainties in your question, and to give it a title that I think people here will understand more quickly. I hope I have reflected your meaning accurately. If I have misrepresented what you are asking, please feel free to change it back! – Paul Stanley May 13 '20 at 17:59

If I understand the question correctly, I think you are concerned that having a preamble which loads a lot of packages is (a) messy and (b) error-prone.

1. It is definitely a good idea to be selective about the packages you load. Especially when you have been given someone else's preamble, they often contain a lot that you don't need. On this site we see preambles which resemble junk shops, passed from hand to hand by graduate students. They often contain a bizarre selection of antique and sometimes incompatible packages. Load always and only what you know you need. This is good package hygiene.

2. It is possible to write a style file of your own which just contains a lot of package-loading commands. You would call it something like mystyle.sty. The canonical source for this will be found in the document LaTeX 2e for class and package writers which you can find by typing texdoc clsguide in a terminal, or on CTAN. You use \RequirePackage instead of \usepackage, but it's not complicated to do. There's also quite a good article on on Overleaf about it.

You need to place your new .sty somewhere TeX can find it, which is not completely simple. It will always be found if it is in the directory of your .tex file. Otherwise, consult this answer for a good explanation of where to put it.

This is a bad idea though, usually, because it makes your source impossible for anyone who does not have your style file to use. And bitter experience suggests that "anyone who does not have your style file" can very easily mean you in a few years time. I would not do this just to load other packages. I would only do it if you are defining critical personal commands that you often use, and I would load in that file only those packages on which those particular commands really depend. If you do use a personal style file simply as a convenience to load other packages, then I actually think that keeping the .sty file in the same directory (or symlinking it there) is a good plan: it's much less likely to get lost, and much easier to send with the critical source file if you are emailing it than if it's only to be found in some distant directory in a tex source tree.

3. If you just want to keep things neat and tidy, split your project into a number of files which you keep together in the same directory, and use \input or \include for the main source files (interested in when to use which: look at this answer about that very topic. But for all except a big project, where you will surely be doing that anyway, I'd really question whether it's worth doing. If you just want to keep a template file to remind you of the packages you often find useful, make such a file and simply use it as a template. Very simple, but sometimes simple is best.

• '... preambles which resemble junk shops' --- I like it. It's not always the students who are responsible for creating these, though. – Ian Thompson May 13 '20 at 18:19

If you are a sort of person who can't be bothered to read documentation even after wrong things have happened, just do the following.

First create a file ending with .sty, the contents might be as follows.

% =====================================================================*
% Copyright (c) 2020 Money Oriented Programmer. All rights reservered. |
% LPPL LaTeX Public Project License                                    |
% =====================================================================*
\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{myarchive}[2020/05/14 v0.01 LaTeX package for my own purpose]

\RequirePackage
[
a4paper,
vmargin=25mm,
outermargin=10mm,
outermargin=100mm,
innermargin=10mm,
marginparwidth=85mm,
marginparsep=5mm,
]{geometry}

\RequirePackage{multicol}

\RequirePackage{graphicx}
\graphicspath{{Images/}}
\RequirePackage{caption}
\RequirePackage{marginfix}

\RequirePackage{mathtools}
\RequirePackage{amssymb}
\RequirePackage{systeme}
\RequirePackage{esvect}
\RequirePackage{palatino}
%\RequirePackage{comicsans}

\RequirePackage{microtype}

\RequirePackage{empheq}
\RequirePackage{booktabs}
\RequirePackage{array}

\RequirePackage{enumitem}

\endinput
% myarchive.sty


Save the copy of it in C:\texlive\texmf-local\tex\latex\local. The original one must be kept in your different drive, so in the future if you reformat your c:\ drive, you can still restore it.

Then run texhash on the shell (command prompt, or whatever you call it) so the installed TeX knows your myarchive.sty.

\documentclass{article}