# LaTeX Command line in OS X

I need to run latex from command line for a project on OS X. LaTeX is installed in:

/usr/local/texlive/2010

in the bin folder there are three folders:

/usr/local/texlive/2010/bin/universal-darwin
/usr/local/texlive/2010/bin/win32
/usr/local/texlive/2010/bin/x86_64-darwin

both "universal-darwin" and "x86_64-darwin" have the executable file "latex". I ran this line in both of these directories and received the same error.

./latex /Users/fluid/Desktop/sample.tex

Here is the error

fluid:x86_64-darwin fluid$./latex /Users/fluid/Desktop/sample.tex This is pdfTeX, Version 3.1415926-1.40.11 (TeX Live 2010) restricted \write18 enabled. entering extended mode ! I can't write on file sample.log'. (Press Enter to retry, or Control-D to exit; default file extension is .log') Please type another transcript file name: and here is the file sample.tex \documentclass[12pt]{article} \begin{document} \begin{center} Sample \LaTeX{} file \end{center} Here is an equation $$f(x) = e^x$$ \end{document}  How can I make this work? - @Fluid, There is however an alternative to run the file with TeXworks that comes with MacTeX. It's been running fine on my MBP. Your code works there. I just tried it. I never try on terminal. – Khaaba Sep 28 '12 at 4:31 – Peter Grill Sep 28 '12 at 4:54 What does the terminal answer after you issue "echo$PATH"? (Without the quotes) –  egreg Sep 28 '12 at 6:26
@Mico: I think your comment should be an answer. –  mpg Sep 28 '12 at 6:28

You shouldn't invoke latex (or pdflatex) from the folder that contains the executables, because that folder is (or at least should be...) writeable only by root. Thus, latex has to crash because it can't create the .log, .aux, and .pdf (or .dvi) files to the executables folder. You may verify this by typing

sudo ./latex /Users/fluid/Desktop/sample.tex


from within the executables folder, viz., /usr/local/texlive/2010/bin/x86_64-darwin: you'll be prompted for the superuser password, and thereafter latex should run without further complaints of the type you report in your posting. BTW, I really don't recommend doing this (i.e., running latex with superuser privileges) on a regular basis.

Assuming MacTeX was installed correctly, the TeX executables should be in the search path, and you should simply be running latex from the folder that contains the .tex file -- in the case you report, the Desktop folder.

By the way, you may want to think about updating your TeX distribution to MacTeX 2012.

-