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 am on an Ubuntu system with TeXLive as my TeX-distribution. I would like to write a common style file and include this file in every document. What should the extension of such a file be?

And, another question is: Where should I put this file?

On my computer there is a directory called /etc/texmf/ and there are some relevant files such as:

  1. tex
  2. texdoc

Also, how do I configure Kile with Okular for SyncTeX? That is, I'd like to view the relevant part of my source file on click in the Okular window.

share|improve this question
1  
As for the 'where', use this command kpsewhich --var-value=TEXINPUTS: it will return a list of where 'latex' searches for files, etc. It will probably mention one like /home/<user>/texmf, which means you could put personal .sty files in a place like /home/<user>/texmf/tex/latex/, and it will be found. You can do kpsewhich --var-value=BIBINPUTS to do similar things for .bib files, probably ending up with putting your .bib in /home/<user>/texmf/bibtex/bib. The one thing you want to do is make the 'local' tree mimic the system tree in terms of directory structure. –  jon Aug 23 '12 at 21:13

1 Answer 1

up vote 1 down vote accepted

Maybe this is a little much for one question. Especially the part about SyncTeX should probably be put in a separate question. Also I can only answer the rest.

To put common commands into a dedicated file, you could either just create a simple mypreamble.tex file and execute \input{mypreamble} to use it. A more sophisticated approach is to write a custom package, i.e. a .sty file. As I described before essentially you only need these two lines:

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{mypreamble}[2012/08/23]

at the beginning of the .sty file, which give the name of your package (in this case the file should be names mypreamble.sty) and the date of the last changes. It can be loaded with \usepackage{mypreamble}.

In any case you should put the file in a directory where it can be found by tex. Of course you don't want to always copy it to the projects directory. Although there may be other ways, I think the best approach for this kind of style file is to put it in a special directory, like e.g. /home/myname/tex/ and add that directory to the TEXINPUTS environment variable. Where you can do that depends on the window manager or shell you are using. The command line should look something like this:

export TEXINPUTS="$TEXINPUTS:.:/home/myname/tex:"

I had to put this line into ~/.zshrc, but it could also belong into ~/.xinitrc, ~/.bashrc, ~/.profile or others depending on your setup.

share|improve this answer
    
\input rather than \include for .tex files of commands although .sty (and \usepackage)is better. (\include is really for files with text in like including chapters of a book, and executes \clearpage and checkpoints all counters etc.) –  David Carlisle Aug 23 '12 at 20:01
    
@DavidCarlisle: Oh, seems I mixed that up. Thanks for the hint. –  canaaerus Aug 23 '12 at 20:22
    
@canaaerus: Thanks a lot –  user31526 Aug 24 '12 at 11:07
    
@David Carlisle: Thanks a lot –  user31526 Aug 24 '12 at 11:08
    
@canaaerus: I got some LaTeX Warning: "You have requested package but the package provides mypreamble"---How do I rectify this? –  user31526 Aug 24 '12 at 13:20

Your Answer

 
discard

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.