I'm working on a Python script that will try to find the packages really used in a (La)TeX file or a piece of a (La)TeX file. I can't just keep the packages indicated via \usepackage because if I am interesting in a part of a (La)TeX file, only some packages will be used.

I am not looking for an exact solution. In other words, my script will try to do the best, and trying to do the best will be good enough as Radiohead could say in an Optimistic day.

If there is only one part of packages founded, typically if a new LaTeX file is built with only the packages found by my script and the compilation failed, then my script will try brutally to add the packages unkept that are imported via \usepackage in the original file. I will try do clever things later but not right now.

Method used

In a (La)TeX file or a piece of a (La)TeX file, I look for macros used and then I search in a kind of BDD, maybe a NoSQL one, build by my script.

So I need to associate a name of macro to packages, one name can be associated to several packages.

For the moment, I am not concerned with user's packages (that will be done later).

What am I looking for ?

  1. Can I know the packages really used by a LaTeX compiler ? It seems that in the log file all packages imported by the LaTeX file are used by the compiler. That looks normal but if the compiler can know which packages are really used, I will happy to use that (because my script will have no reason to birth).
  2. Where can I find the source codes where the macros are defined in packages available in the TeX Live Utility ?

PS: I know the use of \csname that complexifies the search but for the moment I will try to work without this hoping that searching for hard coding names of macros will be enough.

  • 3
    Not clear what the question is. If you have the package, you have the source. There is no concept of a 'compiled' package in TeX. – Alan Munn May 26 '18 at 21:38
  • 1
    If you've installed TeX Live then you have all the source code ... To find a specific file you can use kpsewhich, e.g. kpsewhich book.cls will give you the path to the book class file. But I'm not sure if that is what you're asking for. – Torbjørn T. May 26 '18 at 21:38
  • 1
    @projetmbc If I issue ls /usr/local/texlive/2018/texmf-dist/source/latex | wc -l, the shell returns 1199. Good luck. Do you really would like to classify thousands of macros? And what about when you discover that the definition of \section in article.cls is “interestingly cryptic”? – egreg May 26 '18 at 22:11
  • 1
    even after the edit this question is completely unclear. what do you mean by It seems that in the log file all packages imported by the LaTeX file are used by the compiler. ? For any document the files tha are input are listed in the log, it is not just that seems to be the case, it is the case. Similarly Where can I find the source codes has already been answered in comments where the installed packages may be found. the final comment about \csname does not seem related to package names at all???? – David Carlisle May 27 '18 at 10:28
  • 1
    @projetmbc what do you mean by The compiler does the job but it does not communicate this to the user it seems that you have an idea of what is happening that does not match what actually happens, what "job" do you have in mind that latex does that is not logged here? – David Carlisle May 27 '18 at 10:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.