I wonder if I can run, say, a shell script before actually starting latexmk routine?

I've found compiling_cmd, but it doesn't seem to work for me.

I can write custom shell script to call anything I want in any order, of caurse, but I'd be pleased to find native latexmk solution.

Just in case there's another solution: I have several .dia files which are exported to png in order to insert them as figures. My script just forces Dia to update those png's.

The reason why I'm looking for latexmk solution is that I'm using texstudio which is configured to run latexmk by default, so I don't want to have unique build command for one of my documents.

  • It would be useful to give more details about what you want to do. The kind of solution that is appropriate depends enormously on what you are trying to achieve. Sometimes a script that does something and then calls latexmk can be best. Other times an optimal solution can be with a suitable latexmk configuration. Jan 14, 2016 at 16:42
  • 1
    You need what latexmk calls a "custom dependency". See latexmk's documentation for what to do to configure latexmk. If that works in your situation, I can convert this comment to an answer. One thing you need to know is that on an initial run of pdflatex (via latexmk) there will be error messages about the missing png files. If things are correctly set up, latexmk will use these error messages to trigger the conversion of your .dia files to .png files. Jan 14, 2016 at 17:47
  • Well, I didn't manage get custom dependency working. But your advice lead me to solution anyway: sub dia2png{ system("bash ./diaGen.sh"); } dia2png(); This makes defined function to be called before compilation. It doesn't work as dependency though. Create an answer please. I'll accept it.
    – Roman
    Jan 14, 2016 at 19:10

1 Answer 1


John Collins suggested to use "custom dependency" functionality. Despite the fact I wasn't able to make custom dependency working for my case, it lead me to solution. I've appended following code to my latexmkrc file:

sub dia2png{ 
    system("bash ./diaGen.sh"); 

So latexmk basically allows you to define and run anything before starting actual compilation process. But if you're trying to implement something more complicated, them your choice is custom dependencies.

  • 1
    Given your problem description, I would have expected a custom dependency to work, and to be the preferred solution. It might be useful to give more details about what didn't work with custom dependencies. (Contact me off-line if that the would be easier, at the e-mail in the latexmk documentation.) Jan 22, 2016 at 14:11

You must log in to answer this question.

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