I've configured my xelatex for shell escape (to use tikzexternal), but can I use it to run an arbitrary shell command at the end of compilation? How do I pass it the command to run from inside my .tex document?

I'm trying to use imagemagick mogrify to batch convert figures to jpg (for some reason all the versions of doing that as part of the tikzexternal process like this have failed, they produce a bunch of pdf files, but never any jpg.) Using mogrify from the shell works fine, so I'm hoping to be able to do it as a custom shell escape to automate it.

Edit: \write18{blah} passes "blah" to the shell. Be careful that the PATH may be different there than from an actual shell started outside latex, resulting in possible errors.

  • 1
    Show how you used \write18, and the "weird messages" you got. Commented Nov 22, 2020 at 18:11
  • 5
    Does this answer your question? What are \immediate & \write18 and how does one use them?
    – user202729
    Commented Dec 21, 2021 at 3:14
  • Also it looks like that you already figure out how to use write18; but note that it's recommended to post an answer instead of editing the question to add the "solution".
    – user202729
    Commented Dec 21, 2021 at 3:15

1 Answer 1


If I understand correctly, you want to run a custom command from your editor. Your .tex file does no command calling, it has to be donde "externaly" as in, you can do it manually from the terminal, or you can do it from your editor (TeXMaker, TeXStudio, etc).

The way to define this custom command depends on what editor you are using.

For example, TeXMaker (what I use) lets you define personalized command orders, as if you were to run it from the command line, and all you have to do to run it is press Alt+Shift+F1,F2,F3,F4,F5, depends on which key you configure it.

What editor are you using?

  • Thanks, but that's actually not what I want. If you look at the link I provided, they edit the tikz style to run a custom convert command. That implies there's a way to pass a shell command from the .tex directly. For some reason doing it from tikz fails on my system, but there has to be a more general way to do it.
    – Alexbib
    Commented Nov 22, 2020 at 17:17

Not the answer you're looking for? Browse other questions tagged .