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.

If you've been working with LaTeX for any amount of time, I'm sure you've picked up several little tricks and snippets of code that you want to reuse. For example, a particular way to set up a package like listings or hyperref just the way you like it. Or a little trick for modifying some aspect of the formatting (One of my personal favourites is this trick). Now, you don't want to keep going back to an old .tex file to try to find how to do something.

The question is: how do you keep track of all these snippets?

share|improve this question
add comment

6 Answers

up vote 6 down vote accepted

i maintain such a collection not only for myself, but for an entire publishing production staff. when i come across a good solution to a frequent problem, i create a small self-documenting file with an "obvious" name, process it, and put all the resulting files into an area named howto. the "first" file in this area is called 00index, and into it i put a brief entry stating the purpose of the test file and its name.

the self-documenting feature is something i find particularly useful. it depends on the verbatim package, and the general idea is this:

\documentclass{...}
\usepackage{verbatim}
... % definitions here
\begin{document}
... % illustrative example here
\vspace{2\baselineskip}
\verbatiminput{\jobname.tex}
\end{document}

the output shows the example followed by the full content of the file so that the input can be studied along with the output. printed output is easily filed in a binder for reference off-line. the index can also be entered in a wiki with links to the pdf output.

share|improve this answer
1  
I like to use the listings package for that: \lstinputlisting{\jobname.tex}. –  TH. Apr 3 '11 at 8:51
add comment

For MacOS X I can highly recommend Notational Velocity. Conceptually it is a collection of index cards with incremental search. I keep TeX (and other) snippets there. Finding a snippet is as easy as starting to type anything that I remember about it. Notational Velocity is open source.

Screenshot of Notational Velocity

share|improve this answer
add comment

It depends a bit on what it is. If it's a bit of actual TeX code then I either make a new style file for it (which I keep in a BZR repository) or I add it to my "default" style file (which I load for almost every document I write, and which is also version controlled). If it's a way to do something, then I write a short note about it and put it on my webpage. I have an area called "How Did I Do That?". The intro reads:

Collected here are a load of hints, hacks, and howtos that I have used at some point to get my computers to behave the way I want them to (as opposed to me behaving the way they want me to). Often these only need to be done once, until I do something stupid like upgrading my system. By that time, however, I've usually forgotten the details of how I did whatever I did. So I've started keeping notes. I'm switching to keeping these notes in a blog as the most useful resource that I've found is other people's blogs explaining just how they got the text in their xterms to be mauve. So I've put these here just in case they are useful to someone else.

The LaTeX-specific section is here (though there's one or two others scattered about that site).

Often I find that the very act of writing it down commits it to memory, so I don't all that often look at the collection of notes! But if it weren't there, I'd need it.

share|improve this answer
    
s/style file/package (or document class) –  Caramdir Apr 1 '11 at 21:19
    
@Caramdir: Never really understood the difference between those two. –  Andrew Stacey Apr 1 '11 at 21:22
    
As far as I understand, the name style file has been depreciated in LaTeX2e (even though the extension is still .sty). I guess the reason is that anything to do with the style should usually be in the document class. –  Caramdir Apr 1 '11 at 21:26
add comment

My crude method (used for Java, but theoretically applicable to any code) is to insinuate the code into a public forum, or another 'code place' (hopefully either or both of stable and mirrored) on the net. Then use a search engine to find it later, when it is needed.

share|improve this answer
add comment

Most of these things I keep in my template, which is the starting point of pretty much every document I write. Besides, I have a folder containing manuals of interesting packages, and a lot of single tex-files named according to the interesting snippets they contain.

I guess I might have to come up with a more sophisticated system as things keep piling up, I'm still relatively new to LaTeX. (Which, in turn, means, I usually come across heaps of cool stuff I hadn't know yet :)

share|improve this answer
add comment

For what it's worth, I'll add my own solution to this problem. I use emacs, so I make use of the magical ORG mode. I have a file called snippets.org where I house my snippets. A version of it is available here (exported as HTML).

To add a new thing, I go to the relevant section, start a new subsection then type C-c ' to open up a temporary buffer into which I yank the relevant code. Then another C-c ' gets me back to the original .org file.

I guess I should be using org mode's #-begin_src thing, rather than abusing the picture environment. But it works for me...

share|improve this answer
add comment

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.