# TeXstudio + Latexmk won't compile (with OS X): “Error: Could not start command: …”

UPDATE: John reported the bug in the TeXstudio forum, and they fixed it. The development version TeXstudio 2.10.9 (hg 5929:7315f2e5eed3) works, when you change the Latexmk command to "latexmk -pdf -silent -synctex=1 %"

I recently switched from Texmaker to TeXstudio (version 2.10.8). In Texmaker, I used to compile my document with Latexmk. In TeXstudio, however, the default Latexmk command returns an error message. I work with OS X Yosemite (version 10.10.5) and TeX Live. Here is an example:

\documentclass[10pt, a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage{hyperref}

\begin{document}
Some text.
\end{document}


My build settings in TeXstudio (Default compiler = Latexmk):

And the corresponding command settings (latexmk -dvi -silent %):

And this is the error I get:

The document compiles normally when I choose PdfLaTeX instead of Latexmk. I have seen related posts on stackoverflow, but none these included a solution for Latexmk. Does anybody know a solution to this problem?

EDIT: As ig0774 suggested, I changed the path to /usr/texbin/latexmk -dvi -silent % and pressed OK. When reopening the settings of TeXstudio, the path was set back to latexmk -dvi -silent %. Is this a bug or am I missing something?

You need to change the latexmk command to start with /usr/texbin/latexmk. By default, /usr/texbin is not part of the PATH from GUI applications.

Edit

Alright, a better suggestion:

1. Quit TeXStudio completely
2. Open the file "~/.config/texstudio/texstudio.ini" in a text editor (you can use open -a TextEdit ~/.config/texstudio/texstudio.ini from the terminal or any other text editor you like).
3. Find the line that starts "Tools\Commands\latexmk=", replace everything to the right of the equals sign with /usr/texbin/latexmk -dvi %
4. Launch TeXStudio

This should make the necessary change and persist it across restarts (hopefully... at least it works for me...)

• see my edit above – piptoma Mar 7 '16 at 8:12
• @pipomas: Definitely looks like a bug to me. I get the same behaviour. This isn't... great, but as long as you're on Yosemite (not El Capitan) and you can run sudo, you could try running this command from the terminal: sudo ln -s /usr/texbin/latexmk /usr/bin/latexmk. This creates a link that adds latexmk to a folder available on the $PATH that TeXStudio sees, so it will be able to find latexmk despite the setting not saving. – ig0774 Mar 7 '16 at 9:24 • I ran the command from the terminal, deleted all auxiliary files and try to compile with Latexmk. I got this error message Process started: latexmk -dvi -silent "test" Latexmk: Run number 1 of rule 'latex' sh: latex: command not found Collected error summary (may duplicate other messages): latex: (Pdf)LaTeX failed to generate the expected log file 'test.log' Latexmk: Did not finish processing file 'test': (Pdf)LaTeX failed to generate the expected log file 'test.log' Latexmk: Use the -f option to force complete processing, unless error was exceeding maximum runs of latex/pdflatex. – piptoma Mar 7 '16 at 9:34 • @pipomas: See my edit above. May as well delete the link, sudo rm /usr/bin/latexmk. – ig0774 Mar 7 '16 at 10:11 • I changed the line to Tools\Commands\latexmk=/usr/texbin/latexmk -dvi %, saved it, reopened TeXstudio, deleted all auxiliary files, selected Latexmk as default compiler, tried to compile it and still it returns the same error. – piptoma Mar 7 '16 at 11:12 The problem is actually a bug in the way TeXStudio 2.10.8 under OS-X sets the PATH environment variable used for finding executables. # Work around In your ~/.profile file add the following line at the end export PATH=DUMMY1:$PATH:DUMMY2


(If you don't have a ~/.profile file, create one containing the above line.)

Then restart TeXStudio, and you should find that it will run latexmk properly with the default settings of TeXStudio.

# Bug and its diagnosis

The bug is that the TeXStudio (in v. 2.10.8 under OS-X) sets its PATH variable as the concatenation of the following:

1. Any output produced by your ~/.profile file.
2. The actual intended PATH variable.
3. A new line.
4. Any customizations done by TeXStudio.

It's the new line that's the killer. If, as on my system, the location of TeXLive executables, /Library/TeX/texbin is the last item in the PATH, then that element is replaced by the same string followed by a new line character. The result is that the TeXLive executables are no longer found. The work around I suggested above insulates you from this problem.

A useful way of diagnosing these problems is to put the following line in one of latexmk's configuration files, e.g., latexmkrc in the document directory:

warn "PATH = '$ENV{PATH}'\n";  Then after you run latexmk from TeXStudio, the Messages window will show the value of the PATH variable. • I don't have a ~/.profile file. Can you please explain how to create one and where to save it exactly? – piptoma Mar 15 '16 at 7:30 • It's .profile in your home directory. You can use any editor that can save plain text files with any name. TeXstudio will do it: In the Save or Save As menu, you need to set the file type to "All files (*)". To open such a file with a name beginning with a period from the File Open menu you need to do shift/cmd . to be able to see such files, which are normally hidden. – John Collins Mar 17 '16 at 0:18 • Here ist what I did: (1) created a .profile file containing export PATH=DUMMY1:$PATH:DUMMY2 (2) saved it in the same folder where my test.tex file is. (3) opened TeXStudio, changed default compiler to Latexmk. (4) compiled the file. (5) still returns Error: Could not start the command: latexmk -dvi -silent "test" – piptoma Mar 17 '16 at 7:58
• The .profile file should be in your home directory. – John Collins Mar 17 '16 at 14:11
• I used kpsewhich -var-value TEXMFHOME so find my home directory and put it here: ~/Library/texmf/tex/.profile, but still no luck. – piptoma Mar 17 '16 at 16:08