1

For a package I'm writing, it would be very handy to use some programmed scripts, for example written in Python. Is there a way how I could add these to my .cls file?

And if not, what is the usual way to add scripts to a .cls?

TiMauzi
  • 841
  • Most people use Lua and Lua(La)TeX if they want to do that kind of scripting, but there are alternatives. Have you tried PythonTeX? – frabjous Mar 31 '22 at 15:33
  • @frabjous I usually use XeLaTeX. I still wonder, though: There must be some scripting for most packages, even if they just use simple (PDF)LaTeX, no? – TiMauzi Mar 31 '22 at 15:36
  • @TiMauzi Yes, they (painstakingly) did the programming in TeX. (TeX is a terrible programming language in my opinion, even though I can write it now...) – user202729 Mar 31 '22 at 15:46
  • If you can limit your .cls to Lua only, just use LuaLaTeX. Alternatively, if you can limit yourself to always enable shell-escape and doesn't need macros to be expandable then that one can be used as well. – user202729 Mar 31 '22 at 15:47
  • 1
    TeX itself is Turing complete, and you can "script" with it directly if you like; packages like expl3 make it easier. You can even call external programs with write18; see, e.g. here. But I can definitely see why someone might prefer Python, and that may include you. Should be do-able either way. Which do you prefer? – frabjous Mar 31 '22 at 15:48
  • @user202729 Interesting, I didn't know that TeX itself is a programming language by itself already. I assumed people just use it to call other programs in "normal" programming languages. Can you recommend some tutorials or starting points, if I want to learn more about TeX coding? – TiMauzi Mar 31 '22 at 15:49
  • 2
    There's https://tex.stackexchange.com/questions/12668/where-do-i-start-latex-programming/27589#27589 / https://tex.stackexchange.com/questions/4327/where-do-i-find-out-how-a-command-environment-is-defined/621577#621577 (disclaimer, the second one is my answer) I have to warn that TeX is a very inconvenient programming language though. – user202729 Mar 31 '22 at 15:50
  • 2
    @TiMauzi if your users use --shell-escape commandline option then you can run any command from within your class including deleting all their files. For good reason users are strongly advised not to use --shell-escape on random tex code they find on the internet, so you can do this if you really need it (eg the minted package uses the python pygments library for code syntax highlighting) but be aware that it severely limits the usability of your class. – David Carlisle Mar 31 '22 at 16:40
  • 3
    @user202729 that is not how you spell enjoyable – David Carlisle Mar 31 '22 at 16:42

0 Answers0