Dual compatibility of TeX sources

Consider the following situation. You enjoy TeXing on your local machine, having fun with the latest versions of various packages. For example, exploiting the benefits of TikZ/externalize... or biblatex.

Alas... Your university's TeX installation is old, or your collaborator cannot use your cutting edge packages. Then, a checked out copy on the other system won't compile!

One solution, which I have just used, is to remove all the fancy stuff from the source and make it compatible with the old-style system. This, however, has huge disadvantages; for example now compiling your source (on you local box) takes longer because you cannot take advantage of your latest installed version of TikZ.

Let me focus on the TikZ issue. Is there a way to automize a solution? That is, run a test at the beginning of the compilation, and enable or disable the usage of the externalize package depending on the system the document is currently compiled on?

Does this kind of approach make sense at all?

Edit:

I'm taking the risk of becoming too localized, but I do want to find a solution and to accept an answer here. I tired to use @JosephWright idea as follows:

\makeatletter
\IfFileExists{tikzexternal.sty}
{%
\usetikzlibrary{external}%
\tikzexternalize%
\tikzsetexternalprefix{figures/cache/}%
\renewcommand{\todo}[2][]{%
\tikzexternaldisable\@todo[#1]{#2}\tikzexternalenable}%
}%
{%
}%
\makeatother


When compiling this I get the following error: Illegal parameter number in definition of \reserved@a. which I don't know how to fix... Any ideas?

-
Are you after something as simple as \@ifpackagelater? – Joseph Wright Oct 23 '12 at 20:12
@JosephWright: I'm not sure. If the system doesn't support the externalize library of TikZ, then I trying to load it will yield an error, and I won't get a chance to check whether it was loaded or not. – Dror Oct 23 '12 at 20:16
Then perhaps \IfFileExists first (for the .code.tex file) – Joseph Wright Oct 23 '12 at 20:19
@JosephWright: Sounds in the right direction. Can you point to some reference or expand this to an answer? :) A quick look around yielded nothing. – Dror Oct 23 '12 at 20:23
Your edit would probably be better as a second linked question. Brief answer: double the #. – Joseph Wright Nov 1 '12 at 8:02

LaTeX provides two tools that will be useful here: \IfFileExists and \@ifpackagelater. If we take the case outlined in the question, we cannot be sure the file is even available. I'll generalise to a package foo, which might give something like

\makeatletter
\IfFileExists{foo.sty}
{%
% True branch
\usepackage{foo}
\@ifpackagelater{foo}{2012/10/23}
{%
% All good: use latest code
}
{%
% Code older: fall back on something?
}%
}
{%
% False branch: backup plan
}%
\makeatother


Note that \@ifpackagelater actually gives TRUE if the dates match, and requires a date from a LaTeX package (\ProvidesPackage line). Also notice that \IfFileExists looks for files in general, so we need the full name including the extension.

-
This seems to be what I was after. Unfortunately, before I can test it, I have to solve another issue... tex.stackexchange.com/q/78882/412 – Dror Oct 24 '12 at 7:56
When you write "looks for files in general..." you mean in the search path of TeX? – Dror Oct 24 '12 at 7:58
This is in the right direction! But, when I try to use the redefinition of my \todo (see tex.stackexchange.com/q/78882/412) in the "True branch" I get an error, saying: "Illegal parameter number in definition of \reserved@a" Any idea what can be done? – Dror Oct 24 '12 at 10:15
Here is the complete code I'm trying to use: \makeatletter \IfFileExists{tikzexternal.sty} {% \usetikzlibrary{external} \tikzexternalize \tikzsetexternalprefix{figures/cache/}% \renewcommand{\todo}[2][]{\tikzexternaldisable\@todo[#1]{#2}\tikzexternalenable}‌​% } { }% \makeatother – Dror Oct 24 '12 at 10:17
I would love to accept this answer, as it seems to be exactly what I'm after - but I'm still missing a part of the puzzle. Can someone help me here an bridge the gap? – Dror Oct 24 '12 at 18:25