[Tex/LaTex] How to programmatically detect if a LaTeX package is installed

automationcompilingpackages

I am writing a program, and I want it to do different things depending on which LaTeX packages have been installed. My current solution is to automatically generate simple .tex files that \usepackage the packages I care about and then automatically check if pdflatex can compile them or not. This solution seems slow and fragile. What is a better solution?

Edit: The program I am writing is in Python.

Best Answer

Do you want to detect from inside LaTeX? If so, there is

\IfFileExists{foobar.sty}{true}{false}

If you're external, there is kpsewhich foobar.sty, which gives you the path to the foobar.sty that latex would use.