LaTeX/Creating Customized Packages

From QERM Wiki
(Difference between revisions)
Jump to: navigation, search
(Creating your own .sty file)
Line 7: Line 7:
 
* Refresh <nowiki>MikTeX</nowiki> by opening <nowiki>MikTeX</nowiki> options from the start menu, and clicking update now (under the general tab, in the box called "File name database") or by typing "texhash" in the command line.  (I think these do the same thing... any insights?).
 
* Refresh <nowiki>MikTeX</nowiki> by opening <nowiki>MikTeX</nowiki> options from the start menu, and clicking update now (under the general tab, in the box called "File name database") or by typing "texhash" in the command line.  (I think these do the same thing... any insights?).
 
* Call it from the beginning of any document as \usepackage{''packagename''}.
 
* Call it from the beginning of any document as \usepackage{''packagename''}.
 
==See Also==
 
: [[LaTeX tips]]
 
 
 
[[Category: LaTeX tips]]
 
  
 
==Installing custom classes ==
 
==Installing custom classes ==
Line 28: Line 22:
 
PS: sometimes journals (or schools) require a specific bibliography style as well.  These have ''*.bst'' extensions.  To install these you put the ''*.bst'' file into ''/texmf/bibtex/bst/'', and, again, make sure you run ''texhash''.
 
PS: sometimes journals (or schools) require a specific bibliography style as well.  These have ''*.bst'' extensions.  To install these you put the ''*.bst'' file into ''/texmf/bibtex/bst/'', and, again, make sure you run ''texhash''.
 
PPS: more detailed information can be found <a [[http://www.math.uiuc.edu/~hildebr/tex/customstyles.html here]].
 
PPS: more detailed information can be found <a [[http://www.math.uiuc.edu/~hildebr/tex/customstyles.html here]].
 +
 +
 +
==See Also==
 +
: [[LaTeX tips]]
 +
 +
[[Category: LaTeX tips]]

Revision as of 20:27, 22 April 2008

Creating your own .sty file

The header to a document can get quite messy, if you find yourself calling many new commands or packages. To simplify things, it is useful to create an .sty file which contains the basic commands which are called in every header. It has to be called as a package itself, but it reduces the clutter in the header.

  • Create the .sty file. The only requirement is that it starts with the command \ProvidesPackage{''packagename''}. See an example here or here and Pdf10.png documentation. You can create this file in any text editor, including TeXnicCenter.
  • Put the file in the root directory, which is c:/texmf/tex/latex, or wherever your directory is placed (sometimes it is not called texmf).
  • Refresh MikTeX by opening MikTeX options from the start menu, and clicking update now (under the general tab, in the box called "File name database") or by typing "texhash" in the command line. (I think these do the same thing... any insights?).
  • Call it from the beginning of any document as \usepackage{packagename}.

Installing custom classes

A "class" in LaTeX is a complete set of formatting and style rules that are specific to certain kinds of publication (article and book are both classes). They are called in the first line with: \begindocument{classname}. Sometimes you want to or need to use a different, specific class. Notably, many journals have a class they require LaTeX submissions to be in and many universities (including UW) have a thesis or dissertation class which neatly takes care of all your formatting woes for you. It seems that every time I need to install a new class I forget how to do it, so here's a quick reminder.

Class files have the *.cls extension (e.g. uwthesis.cls is the UW thesis class, downloadable here. So:

  • first, download the file and tuck it wherever the classes are located in your tex directory. Ha ha! Easily said, but where are they? On most installations it should be something like: c:/texmf/tex/latex/. This directory will have a WHOLE BUNCH of folders. Just make another folder (e.g. /texmf/tex/latex/uwthesis) and throw your *.cls file in there (along with any documentation or samples that often come with it).
  • second (and this is the totally nonintuitive part), in order for LaTeX to know that this new class has been tucked away, you have to get to a command prompt, enter latex world (cd\texmf) and run the command: texhash (i.e. simply type the word into the prompt and hit enter). This program updates all the internal indexes or something and then your compiler will know that it exists.

That's it. Now you should be able to use your new class.

PS: sometimes journals (or schools) require a specific bibliography style as well. These have *.bst extensions. To install these you put the *.bst file into /texmf/bibtex/bst/, and, again, make sure you run texhash. PPS: more detailed information can be found <a [here].


See Also

LaTeX tips
Personal tools