Jul-20-2020, 08:39 PM
(This post was last modified: Jul-21-2020, 07:35 AM by Gribouillis.)
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()