Python Forum

Full Version: List all installed TeX packages in Linux
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Been doing some Latex lately, so I wrote this little script to list all the tex packages on my system
#!/usr/bin/env python3
# name: list-tex-packages.py
# author: Gribouillis  https://python-forum.io
# inspired by: https://tex.stackexchange.com/questions/125058
# requirement: plumbum, more_itertools
# LICENSE: MIT
from more_itertools import unique_everseen
from pathlib import Path
from plumbum import cli, local

__version__ = '2020.07.21'

def kpsepath():
    """List of potential directories where to find tex modules
    
    Usually contains the current directory '.'
    """
    L =  local["kpsepath"]('tex').strip().split(':')
    L = [x.lstrip('!').rstrip('/') for x in L]
    return L

def istyle_file(ipath=None):
    """Iterable of tex style files contained under one of the directories
    
    Arguments:
       ipath: iterable of directories where to find style files
       
    The search recurses the directories
    """
    def istyle_file():
        for p in (ipath or kpsepath()):
            if Path(p).is_dir():
                r = local['find'](p, '-name', '*.sty').strip().split('\n')
                yield from r
    return unique_everseen(istyle_file())

def itex_package(ipath=None):
    """Sorted list of the tex packages installed under the directories
    
    Arguments:
        ipath: iterable of directories where to find packages
    """
    def ipackage(ipath):
        for f in istyle_file(ipath):
            yield f.rsplit('/', 1)[-1].rsplit('.', 1)[0]
    return sorted(unique_everseen(ipackage(ipath)))

class App(cli.Application):
    """Print a list of installed tex packages on this computer"""
    VERSION = __version__
    def main(self):
        for x in itex_package():
            print(x)

if __name__ == '__main__':
    App().run()
Haven't used it since creating https://github.com/Larz60p/MusicScales (in combination with Lisp)
Used to do all my documentation (1980's) in LaTex.
Very powerful.
The biggest power of latex is that it can be generated by other programs...