How do I check if the PDF file produced by LaTeX is currently opened by an application or not?
I assume that your question is related to the fact that PDFLaTeX cannot write to a file if it is open in Acrobat Reader. The older versions of Acrobat Reader could be closed and reopend with external DDE commands but not versions 9 and X as far as I know.
Acrobat Reader can also not support the new synctex technology, so the best here is Sumatra PDF for the windows environment. You do not need to close it when compiling your document and it supports the inverse search via synctex. Some of the editors such as WinEdt on windows supports it directly and the inverse search works very well. WinShell and TexStudio (formerly known as TexMakerX) for windows can be configured to use it with synctex support. Alternatively use one of the editors with buildin viewers with synctex support such as TexWorks, TexMaker or TexStudio.
Since you mentioned that you're using linux in one of the comments, the standard way to determine if a programme is currently accesing a file is the
lsof command. Example:
user@host:~$ lsof /path/to/filename.pdf COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME okular 3961 user 26r REG 0,21 5357342 12608996 /path/to/filename.pdf
Reading over the comments, you said you wanted to kill that process, here's a one-liner for it.
kill $(lsof -Fp /path/to/filename | egrep -o "[0-9]+")
Explanation: lsof finds the filename & -Fp option pulls the PID , egrep (grep with extended regex syntax that I'm more comfortable with) grabs only the numbers since it prints pXXXX. This is wrapped in $() and evaluated first, then the kill is run. Thanks to kahen for knowing the command line option for getting the PID
Since you are using linux, I can tell you that you probably should not need to check if the file is open.
When I compile the
.tex file (usually with
pdflatex), I'm also viewing the
- xpdf: simply press r and it will refresh the document.
- evince: it refreshes automatically.