title: Compile Latex code using Swift
body: <p>I wanted to compile a <code>.tex</code> file using Swift. I have the following code:</p>
  
  <pre><code>class FileManager {
      class func compileLatex(#file: String) {
          let task = NSTask()
          task.launchPath = "/usr/texbin/latexmk"
          task.currentDirectoryPath = (NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as! String).stringByAppendingString("/roster")
          task.arguments = ["-xelatex", file]
          task.launch()
      }
  }
  </code></pre>
  
  <p>However, when calling <code>FileManager.compileLatex(file: "latex.tex")</code> I get the error 'launch path not accessible'. So apparently, the launch path is wrong, yet I don't know how to find out which it really is? How can I find out or is there a general path? Thanks for any help</p>
  
  <p>EDIT:</p>
  
  <p>updated code and getting this error:</p>
  
  <pre><code>Latexmk: This is Latexmk, John Collins, 10 January 2015, version: 4.42.
  Latexmk: applying rule 'pdflatex'...
  Rule 'pdflatex': Rules &amp; subrules not known to be previously run:
     pdflatex
  Rule 'pdflatex': The following rules &amp; subrules became out-of-date:
        'pdflatex'
  ------------
  Run number 1 of rule 'pdflatex'
  ------------
  ------------
  Running 'xelatex  -recorder  "Praktikumsbericht.tex"'
  ------------
  sh: xelatex: command not found
  Latexmk: Errors, so I did not complete making targets
  Collected error summary (may duplicate other messages):
    pdflatex: (Pdf)LaTeX failed to generate the expected log file 'Praktikumsbericht.log'
  Latexmk: Did not finish processing file 'Praktikumsbericht.tex':
     (Pdf)LaTeX failed to generate the expected log file 'Praktikumsbericht.log'
  Latexmk: Use the -f option to force complete processing,
   unless error was exceeding maximum runs of latex/pdflatex.
  </code></pre>