pdflatex command not working in Emacs terminal mode - macos

I have some problem with the Emacs terminal mode.
I'm a mac user and I use Emacs downloaded from emacsformacosx.com; I installed also ESS and AucTex.
I work with R, LaTex, Sweve and, I menage all with Emacs. When I want to compile the Sweave file I open the terminal and I use the "R CMD Sweave myfile.Rnw" command to generate a myfile.tex file. After this I use "pdflatex myfile.tex" command, to compile the LaTex file.
All these command work well if used in the terminal application of osx but, the pdflatex command doesn't work if I use the Emacs teminal mode:
bash: pdflatex: command not found
Do you have any suggestion?
EDIT
Thanks for your suggestion, I resolved my problem adding to my .emacs this:
(defun set-exec-path-from-shell-PATH ()
(let ((path-from-shell
(replace-regexp-in-string "[[:space:]\n]*$" ""
(shell-command-to-string "$SHELL -l -c 'echo $PATH'"))))
(setenv "PATH" path-from-shell)
(setq exec-path (split-string path-from-shell path-separator))))
(when (equal system-type 'darwin) (set-exec-path-from-shell-PATH))
I found it at link text
Best
Riccardo

On OS X, environment variables for GUI programs are set in ~/.MacOSX/environment.plist. There are many Emacs specific work arounds like using (setenv "PATH" (shell-command-to-string "echo -n $PATH")) which you can find scattered across Stack Overflow and the internet in general.

Related

tuareg mode emacs ocaml not found

I am running emacs 24.3 on mac os x 10.9. I have installed the tuareg-mode for ocaml programming but am unable to compile using the command C-c C-b. On pressing the same, the minibuffer asks me about 'Caml toplevel to run: ocaml'. When I press enter it shows the error "Searching for program: No such file or directory, ocaml". What am I missing?
you need to setup PATH environment variable & the Emacs's exec-path variable to correct values. One possibility is to use something like (in your ~/.emacs):
(defun set-exec-path-from-shell-PATH ()
(let ((path-from-shell (shell-command-to-string "$SHELL -c 'echo $PATH'")))
(setenv "PATH" path-from-shell)
(setq exec-path (split-string path-from-shell path-separator))))
(when window-system (set-exec-path-from-shell-PATH))
to get the PATH from shell and both variables correctly. One advantage of this is that you will setup PATH only in one place - in your shell init script.
So I found this cool mode that autoloads the shell variables into emacs environment for mac users. Very handy:
https://github.com/purcell/exec-path-from-shell
Just install it and update your .emacs file and you are set.

Problems with pdflatex in emacs org-export-as-pdf

I have some problems with the emacs org-mode. When I use the command org-export-as-pdf in org-mode, I got the error:
/bin/bash: pdflatex: command not found [3 times]
I am a Mac OS X(10.7) user and the version of emacs is 24.2. I downloaded the Tex Live from the official website and it was installed at /usr/local/texlive. I knew the env variables of emacs shell is different from user's terminal, so I tried this command:
M-! $PATH
it printed:
/bin/bash: /usr/bin:/bin:/usr/sbin:/sbin: No such file or directory
then I typed some commands below:
$which pdflatex
/usr/texbin
$ln -s /usr/texbin/pdflatex /usr/bin
and then I turned back to emacs, and tried org-export-as-pdf again, the same problem still existed.
I am confused and I need your help ;-)
Add the pdflatex directory to the Emacs PATH environment variable, instead of the symbolic link, e.g. add this to ~/.emacs:
(setenv "PATH" (concat (getenv "PATH") ":/usr/texbin"))
and source it again with M-x load-file and type ~/.emacs. And now C-c C-e lp in Org-mode works:
PDF file produced.
(Cross-posted on Unix.StackExchange.)

Garbage characters in my Windows Emacs shell. . . not sure what's wrong

I'm running GNU Emacs (23.1.1) on Windows and when I run a cygwin shell inside emacs I get garbage like the following, after each command:
^[]0;/cygdrive/c/emacs-23.1/bin
^[[32user#HOST [33m/cygdrive/c/emacs-23.1/bin[0m
Note: I've replaced my real user and host name with user/HOST.
I've found a few links that describe how to set up emacs with cygwin on Windows including this one on SO:
How can I run Cygwin Bash Shell from within Emacs?
That hasn't helped. As of right now, I don't have anything referencing shells in my .emacs file except for this:
;; For the interactive shell
(setq explicit-shell-file-name "bash")
So I'm not even sure how emacs is finding my cygwin shell. Any help is appreciated. Thanks.
Try adding these lines to your .emacs file
(autoload 'ansi-color-for-comint-mode-on "ansi-color" nil t)
(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
I'm not sure if these are the correct ones but let me know (as my .emacs file has gotten quite large over the years)

Emacs and cygwin [duplicate]

I am running GNU Emacs on Windows so entering:
M-x shell
launches the Windows command-line DOS shell. However, I would like to instead be able to run the Cygwin Bash Shell (or any other non-Windows shell) from within Emacs. How can this be easily done?
shell-file-name is the variable that controls which shell Emacs uses when it wants to run a shell command.
explicit-shell-file-name is the variable that controls which shell M-x shell starts up.
Ken's answer changes both of those, which you may or may not want.
You can also have a function that starts a different shell by temporarily changing explicit-shell-file-name:
(defun cygwin-shell ()
"Run cygwin bash in shell mode."
(interactive)
(let ((explicit-shell-file-name "C:/cygwin/bin/bash"))
(call-interactively 'shell)))
You will probably also want to pass the --login argument to bash, because you're starting a new Cygwin session. You can do that by setting explicit-bash-args. (Note that M-x shell uses explicit-PROGRAM-args, where PROGRAM is the filename part of the shell's pathname. This is why you should not include the .exe when setting the shell.
The best solution I've found to this is the following:
;; When running in Windows, we want to use an alternate shell so we
;; can be more unixy.
(setq shell-file-name "C:/MinGW/msys/1.0/bin/bash")
(setq explicit-shell-file-name shell-file-name)
(setenv "PATH"
(concat ".:/usr/local/bin:/mingw/bin:/bin:"
(replace-regexp-in-string " " "\\\\ "
(replace-regexp-in-string "\\\\" "/"
(replace-regexp-in-string "\\([A-Za-z]\\):" "/\\1"
(getenv "PATH"))))))
The problem with passing "--login" as cjm suggests is your shell will always start in your home directory. But if you're editing a file and you hit "M-x shell", you want your shell in that file's directory. Furthermore, I've tested this setup with "M-x grep" and "M-x compile". I'm suspicious that other examples here wouldn't work with those due to directory and PATH problems.
This elisp snippet belongs in your ~/.emacs file. If you want to use Cygwin instead of MinGW, change the first string to C:/cygwin/bin/bash. The second string is prepended to your Windows PATH (after converting that PATH to an appropriately unixy form); in Cygwin you probably want "~/bin:/usr/local/bin:/usr/bin:" or something similar.
I use XEmacs with Cygwin, and can run bash from XEmacs relatively easily.
Here's the relevant section from init.el
;; Let's use CYGWIN bash...
;;
(setq binary-process-input t)
(setq w32-quote-process-args ?\")
(setq shell-file-name "bash") ;; or sh if you rename your bash executable to sh.
(setenv "SHELL" shell-file-name)
(setq explicit-shell-file-name shell-file-name)
(setq explicit-sh-args '("-login" "-i"))
One more important hint on this subject.
If you use Emacs shell mode and want both bash and cmd sometimes, set it up to use bash by default, because you can type cmd at bash and the resulting dos shell works just fine.
If you setup Emacs to use cmd as the shell (which is the way NT emacs installs), then dos shell works fine, but if you type bash or bash -i to run a bash shell, the resulting shell doesn't work right - see answer 0.
But it works fine if bash is the "first" shell emacs invokes.
You can run bash directly from the default Windows command-line shell within your Emacs *shell* buffer:
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\temp>bash
bash
However, no command prompt is visible which can be disorienting resulting in your commands and their output results all blending together.
In addition, for some unknown reason, if you do enter a command and hit return, a return line character (\r) is appended to the end of your command statement causing a bash error:
ls
bash: line 1: $'ls\r': command not found
A workaround is to manually add a comment character (#) at the end of every command which effectively comments out the \r text:
ls #
myfile,txt
foo.bar
anotherfile.txt
This overall approach is far from ideal but might be useful if you want to drop into bash from Windows' native shell to do some quick operations and then exit out to continue working in Windows.
I'm using EmacsW32. C-h a shell$ gives a list of shell launching commands and the commands cmd-shell and cygwin-shell look interesting. Both commands need EmacsW32. They are also found in the menu: Tools > W&32 Shells.
If you run cygwin-shell for the first time, and if you have not setup cygwin path in Emacs, it leads you to the Customization page where you can setup the cygwin path by pressing Find button.
Since these approaches didn't work for me I got it the following way:
(I'm using NTEmacs which opens a dos shell by default, so perhaps your emacs behaves the same)
Create a windows environment variable named SHELL ('SHELL' not '$SHELL') and give it the path to bash.exe of your cygwin installation (for example c:\programs\cygwin\bin\bash.exe)
Now when doing M-x shell it opens a bash.
Regards,
Inno
In addition to #Chris Jones' answer about avoiding the --login argument to bash, I set the following command line arguments:
(setq explicit-bash-args '("--noediting" "-i"))
The --noediting option prevents interference with the GNU readline library and the -i option specifies that the shell is interactive. I also use the .emacs_bash file in my home directory for any emacs specific bash customizations.

How can I run Cygwin Bash Shell from within Emacs?

I am running GNU Emacs on Windows so entering:
M-x shell
launches the Windows command-line DOS shell. However, I would like to instead be able to run the Cygwin Bash Shell (or any other non-Windows shell) from within Emacs. How can this be easily done?
shell-file-name is the variable that controls which shell Emacs uses when it wants to run a shell command.
explicit-shell-file-name is the variable that controls which shell M-x shell starts up.
Ken's answer changes both of those, which you may or may not want.
You can also have a function that starts a different shell by temporarily changing explicit-shell-file-name:
(defun cygwin-shell ()
"Run cygwin bash in shell mode."
(interactive)
(let ((explicit-shell-file-name "C:/cygwin/bin/bash"))
(call-interactively 'shell)))
You will probably also want to pass the --login argument to bash, because you're starting a new Cygwin session. You can do that by setting explicit-bash-args. (Note that M-x shell uses explicit-PROGRAM-args, where PROGRAM is the filename part of the shell's pathname. This is why you should not include the .exe when setting the shell.
The best solution I've found to this is the following:
;; When running in Windows, we want to use an alternate shell so we
;; can be more unixy.
(setq shell-file-name "C:/MinGW/msys/1.0/bin/bash")
(setq explicit-shell-file-name shell-file-name)
(setenv "PATH"
(concat ".:/usr/local/bin:/mingw/bin:/bin:"
(replace-regexp-in-string " " "\\\\ "
(replace-regexp-in-string "\\\\" "/"
(replace-regexp-in-string "\\([A-Za-z]\\):" "/\\1"
(getenv "PATH"))))))
The problem with passing "--login" as cjm suggests is your shell will always start in your home directory. But if you're editing a file and you hit "M-x shell", you want your shell in that file's directory. Furthermore, I've tested this setup with "M-x grep" and "M-x compile". I'm suspicious that other examples here wouldn't work with those due to directory and PATH problems.
This elisp snippet belongs in your ~/.emacs file. If you want to use Cygwin instead of MinGW, change the first string to C:/cygwin/bin/bash. The second string is prepended to your Windows PATH (after converting that PATH to an appropriately unixy form); in Cygwin you probably want "~/bin:/usr/local/bin:/usr/bin:" or something similar.
I use XEmacs with Cygwin, and can run bash from XEmacs relatively easily.
Here's the relevant section from init.el
;; Let's use CYGWIN bash...
;;
(setq binary-process-input t)
(setq w32-quote-process-args ?\")
(setq shell-file-name "bash") ;; or sh if you rename your bash executable to sh.
(setenv "SHELL" shell-file-name)
(setq explicit-shell-file-name shell-file-name)
(setq explicit-sh-args '("-login" "-i"))
One more important hint on this subject.
If you use Emacs shell mode and want both bash and cmd sometimes, set it up to use bash by default, because you can type cmd at bash and the resulting dos shell works just fine.
If you setup Emacs to use cmd as the shell (which is the way NT emacs installs), then dos shell works fine, but if you type bash or bash -i to run a bash shell, the resulting shell doesn't work right - see answer 0.
But it works fine if bash is the "first" shell emacs invokes.
You can run bash directly from the default Windows command-line shell within your Emacs *shell* buffer:
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\temp>bash
bash
However, no command prompt is visible which can be disorienting resulting in your commands and their output results all blending together.
In addition, for some unknown reason, if you do enter a command and hit return, a return line character (\r) is appended to the end of your command statement causing a bash error:
ls
bash: line 1: $'ls\r': command not found
A workaround is to manually add a comment character (#) at the end of every command which effectively comments out the \r text:
ls #
myfile,txt
foo.bar
anotherfile.txt
This overall approach is far from ideal but might be useful if you want to drop into bash from Windows' native shell to do some quick operations and then exit out to continue working in Windows.
I'm using EmacsW32. C-h a shell$ gives a list of shell launching commands and the commands cmd-shell and cygwin-shell look interesting. Both commands need EmacsW32. They are also found in the menu: Tools > W&32 Shells.
If you run cygwin-shell for the first time, and if you have not setup cygwin path in Emacs, it leads you to the Customization page where you can setup the cygwin path by pressing Find button.
Since these approaches didn't work for me I got it the following way:
(I'm using NTEmacs which opens a dos shell by default, so perhaps your emacs behaves the same)
Create a windows environment variable named SHELL ('SHELL' not '$SHELL') and give it the path to bash.exe of your cygwin installation (for example c:\programs\cygwin\bin\bash.exe)
Now when doing M-x shell it opens a bash.
Regards,
Inno
In addition to #Chris Jones' answer about avoiding the --login argument to bash, I set the following command line arguments:
(setq explicit-bash-args '("--noediting" "-i"))
The --noediting option prevents interference with the GNU readline library and the -i option specifies that the shell is interactive. I also use the .emacs_bash file in my home directory for any emacs specific bash customizations.

Resources