TeXstudio + Latexmk won't compile (with OS X): "Error: Could not start command: ..."

3,632

Solution 1

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.

Solution 2

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...)

Share:
3,632

Related videos on Youtube

piptoma
Author by

piptoma

Updated on August 01, 2022

Comments

  • piptoma
    piptoma over 1 year

    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): my build settings in TeXstudio: Default compiler = Latexmk

    And the corresponding command settings (latexmk -dvi -silent %): my command settings in TeXstudio: Latexmk = latexmk -dvi -silent %

    And this is the error I get: enter image description here

    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?

  • piptoma
    piptoma over 7 years
    see my edit above
  • ig0774
    ig0774 over 7 years
    @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.
  • piptoma
    piptoma over 7 years
    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.
  • ig0774
    ig0774 over 7 years
    @pipomas: See my edit above. May as well delete the link, sudo rm /usr/bin/latexmk.
  • piptoma
    piptoma over 7 years
    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.
  • ig0774
    ig0774 over 7 years
    @pipomas: This may be the time to rethink using latexmk with TeXStudio on OS X. That said, you could try modifying the command in the ini file to /usr/texbin/latexmk -dvi -latex="/usr/texbin/latex %O %S" %, but you'll have to make analogous changes for any other executable you use, e.g. biber, bibtex, etc.
  • piptoma
    piptoma over 7 years
    I don't have a ~/.profile file. Can you please explain how to create one and where to save it exactly?
  • John Collins
    John Collins over 7 years
    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.
  • piptoma
    piptoma over 7 years
    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"
  • John Collins
    John Collins over 7 years
    The .profile file should be in your home directory.
  • piptoma
    piptoma over 7 years
    I used kpsewhich -var-value TEXMFHOME so find my home directory and put it here: ~/Library/texmf/tex/.profile, but still no luck.
  • piptoma
    piptoma over 7 years
    Thanks John for reporting the bug on sourceforge.net/p/texstudio/bugs/1700. With the developer version of TeXstudio (2.10.9 (hg 5929:7315f2e5eed3)), Latemk compiles with no trouble.
  • piptoma
    piptoma over 7 years
    I just noticed: Latexmk produces no pdf file. I get a .aux, .dvi, .fdb_latexmk, .fls, and .log file. But no pdf.
  • piptoma
    piptoma over 7 years
    SOLVED: I had to use the pdf-variant of the command: "latexmk -pdf -silent -synctex=1 %"