Add support for graphicx package and fixed bug in automatic package detection code