0

I would like to start a shell script from LaTeX. In the shell script I need to wait until the .pdf file is generated and afterwards I want to do some stuff with this file.

So I created a MWE Test.tex like this:

\documentclass{article}
\immediate\write18{/myPath/script.sh}
\begin{document}
  Test
\end{document}

The shell script script.sh looks like this:

#!/bin/bash
until [ -f Test.pdf ]
do
     sleep 5
done
echo "File found"
# Do SOMETHING

Unfortunately this seems not to work with TeXMaker. It seems to hang in an endless loop and probably the sleep 5 cmd seems also to let TeXMaker fall asleep.

BTW --shell-escape is enabled and chmod 755 script.sh is set.

EDIT Now I'm able to use arara like this in my MWE:

\documentclass{article}
% arara: pdflatex: {shell: yes,synctex: yes,interaction: nonstopmode}
\begin{document}
Test
\end{document}

But how to tell arara now to run this script \immediate\write18{/myPath/script.sh} after the pdf is generated?

PascalS
  • 826
  • 1
    no that won't work. Why don't you use an external script that first calls pdflatex and then your postprocessing? You could e.g. use arara to set this up. – Ulrike Fischer Feb 24 '23 at 11:09
  • Hmm that‘s a pity. I would like to combine this scripting with my normal workflow in TexMaker. Otherwise I have to execute the external script after every TexMaker build. Or do you know a possibility to have a post build script execution in TexMaker? – PascalS Feb 24 '23 at 12:09
  • See for example https://tex.stackexchange.com/questions/107989/integration-of-arara-in-texmaker and other questions. – cabohah Feb 24 '23 at 12:37
  • If texmaker is able to run builds combining pdflatex + bibtex +makeindex then it should also be able to run other tools and scripts. – Ulrike Fischer Feb 24 '23 at 12:40
  • I have edited my question, could you please have a look :) – PascalS Feb 24 '23 at 15:15

1 Answers1

0

Thanks for the comments, at the end the solution is much easier than expected.

I had to change my IDE from TexMaker to TexStudio. In TexStudio you just has to add one single expression in the Meta Commands in Preferences => Generate => Build and View.

Meta commands

In my case it's sh -c "/MyPath/script.sh argument1"

That's it!

PascalS
  • 826