3

Context:

I am a Newbee on Emacs and AucTex. I just get started several days ago and installed some packages as some tutorials go along.

I installed some packages: company, swiper, auctec, auto-complete-auctex, and counsel. In particular, auctex has version 12.2.0.

My Problem:

I installed it yesterday, and I could do C-c C-a to preview it entirely. However, I cannot do preview-latex (C-c C-p C-p). It gives me error with lots of "under construction triangles":

What I see

TeX Output exited as expected with code 1 at Thu Apr 23 00:21:29
Running `Preview-PDF2DSC' with ``pdf2dsc _region_.pdf _region_.prv/tmpQ3JlTM/preview.dsc''
/bin/sh: pdf2dsc: command not found

Preview-PDF2DSC exited abnormally with code 127 at Thu Apr 23 00:21:29
PDF2DSC sentinel: Opening input file: No such file or directory, /myworkingdirectory/_region_.prv/tmpQ3JlTM/preview.dsc

It generates several files in my working directory: My working directory

The directory it referring has no file in it. And this is the corresponding elisp code, and yes, I checked latex is in that folder path. My elisp code

Update 1:

I did not install ghostscript. After I installed, the problem is still exist.

Update 2:

I found this answer really helpful How to use Auctex in MacOS El Capitan? At least for Mac OS Catalina, one shall use

;; Auctex configurations
(setenv "PATH" "/usr/local/bin:/Library/TeX/texbin/:$PATH" t)
(setq exec-path (append exec-path '("/Library/TeX/texbin")))

to set the environment path.

Shout out to @frougon for his patience on me! His code also works

(setenv "PATH" (concat (getenv "PATH") ":/usr/local/bin:/Library/TeX/texbin"))
(setq exec-path (append exec-path '("/usr/local/bin" "/Library/TeX/texbin")))
  • 1
    Log says it can't find pdf2sc. Did you made TeX installation? If so, check, whether this pdf2sc binary is installed. Remember your TeX AucTeX doesn't ship with TeX, you need to install *TeX binaries on your own, using a TeX distro (texlive, mictex, protext… can't remember the name of the Mac devoted one). – sztruks Apr 23 '20 at 07:48
  • @sztruks I’ve installed LaTeX (MacTex) and maybe MikTex already. I used to use TexStudio and rmarkdown before emacs. I’ve checked I do have LaTeX installed.. – Yuchen Zhang Apr 23 '20 at 07:55
  • 2
    But do you have pdf2dsc installed? Look in your distribution for this peculiar binary. – sztruks Apr 23 '20 at 09:08
  • 1
    On my Debian system, pdf2dsc comes from the ghostscript package. – frougon Apr 23 '20 at 10:25
  • @frougon I found out I did not install ghostscript. I installed it from homebrew, yet still not working. Also, there is nothing inside /myworkingdirectory/_region_.prv/tmpQ3JlTM/ folder. – Yuchen Zhang Apr 23 '20 at 10:54
  • @sztruks I did not. Where can I find pdf2dsc? I did not find it on homebrew and melpa. I installed ghostscript from homebrew, but it does not help. – Yuchen Zhang Apr 23 '20 at 10:59
  • @YuchenZhang Do you see a pdf2dsc executable on your filesystem and do you still have the pdf2dsc: command not found error message? If so, it might be a PATH issue or AUCTeX configuration, however I fear don't know MacOS enough to be of much help. – frougon Apr 23 '20 at 11:00
  • @sztruks Ok it is a command from ghostscript. I will try to restart my computer see if it works. – Yuchen Zhang Apr 23 '20 at 11:01
  • @frougon I have pdf2dsc on terminal! It recognizes it belongs to ghostscript – Yuchen Zhang Apr 23 '20 at 11:17
  • @frougon pdf2dsc belongs to /usr/local/bin/ while I set Auctex's path to /Library/TeX/texbin/, which is where my latex distributions are. – Yuchen Zhang Apr 23 '20 at 11:19
  • @YuchenZhang 1) Do you still have the error message I quoted? 2) You can add the directory you need to the PATH, just use the : separator, e.g. (setenv "PATH" (concat (getenv "PATH") "/usr/local/bin:/Library/TeX/texbin")). Test the result with M-: (getenv "PATH"). – frougon Apr 23 '20 at 11:20
  • (or the other way around, if you want /Library/TeX/texbin to take precedence) – frougon Apr 23 '20 at 11:26
  • @frougon 1) I do not have error messages. pdf2dsc is in /usr/local/bin/ and it works via terminal. 2) I got you. – Yuchen Zhang Apr 23 '20 at 11:28
  • 1
  • I know it works in terminal. My question is, do you still have this error message when generating previews under AUCTeX, as your question shows? 2) M-: is Meta-:. If you don't know your Meta key (?!), try Alt, but you can also do Esc then :. I was just suggesting to add /usr/local/bin to the PATH setting from your question (although I find it strange that /usr/local/bin is not already in Emacs's PATH; maybe you should first print the PATH from within Emacs). In order not to have paths duplicated due to the concat, this would require an Emacs restart, to keep things simple.
  • – frougon Apr 23 '20 at 11:33
  • @frougon I tried your idea, and it kind of works. However, now it is saying /bin/sh: pdflatex: command not found, but pdflatex is in /Library/TeX/texbin. And yeah, it is still generating errors.... – Yuchen Zhang Apr 23 '20 at 11:35
  • Please give the output of M-: (getenv "PATH"). You can copy it from the *Messages* buffer after it has been echoed, or you can do C-j immediately after (getenv "PATH") in the *scratch* buffer; then you'll have the output in the same buffer. – frougon Apr 23 '20 at 11:35
  • @frougon I am sorry. I am new to this. I tried M-:/usr/local/bin:/Library/TeX/texbin and the other way around. One gives me this Debugger entered--Lisp error: (void-variable /usr/local/bin:/Library/TeX/texbin) and blabla, one gives me eval-expression: Symbol’s value as variable is void: /Library/TeX/texbin:/usr/local/bin – Yuchen Zhang Apr 23 '20 at 11:39
  • Don't be sorry, but where did I suggest to do M-:/usr/local/bin:/Library/TeX/texbin? Of course this is invalid... Do what I said in the *scratch* buffer. You noticed the Buffer menu? :-) Also C-x C-b and C-x b... C-j is Control-j, maybe Control is the Command key for you? – frougon Apr 23 '20 at 11:40
  • @frougon Ohhhh I got you... here is the path "/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Emacs.app/Contents/MacOS/bin-x86_64-10_10:/Applications/Emacs.app/Contents/MacOS/libexec-x86_64-10_10/Library/TeX/texbin:/usr/local/bin" – Yuchen Zhang Apr 23 '20 at 11:43
  • You see the .../libexec-x86_64-10_10/Library/TeX/. You are apparently just missing the : separator before /Library/TeX/texbin. In your config, where you did the above changes. Maybe restart Emacs after adding the :. – frougon Apr 23 '20 at 11:44
  • Do I need to add /usr/local/bin again? This gets me to where I began. (setenv "PATH" (concat (getenv "PATH") ":/Library/TeX/texbin/")) (setq exec-path (append exec-path '("/Library/TeX/texbin/"))) – Yuchen Zhang Apr 23 '20 at 11:54
  • @frougon Thank you for your help! I found this answer really useful: https://tex.stackexchange.com/questions/270490/how-to-use-auctex-in-macos-el-capitan – Yuchen Zhang Apr 23 '20 at 12:06
  • @frougon Thank you for your patience. I appreciate it! – Yuchen Zhang Apr 23 '20 at 12:06
  • 1
    I was reading about exec-path. This seems helpful. According to your output, I would do: (setenv "PATH" (concat (getenv "PATH") ":/usr/local/bin:/Library/TeX/texbin")) and (setq exec-path (append exec-path '("/usr/local/bin" "/Library/TeX/texbin"))). – frougon Apr 23 '20 at 12:09
  • @frougon Yours works for me! Thank you for your help! – Yuchen Zhang Apr 23 '20 at 12:13
  • Glad to hear that, you're welcome. – frougon Apr 23 '20 at 12:13
  • I'd suggest to remove the trailing / in (setq exec-path (append exec-path '("/usr/local/bin" "/Library/TeX/texbin/"))) in your edit of the question, it's a bit ugly. :-) – frougon Apr 23 '20 at 12:15
  • @frougon Haha for sure – Yuchen Zhang Apr 23 '20 at 12:28
  • One more thing: with this config, /usr/local/bin takes precedence over /Library/TeX/texbin. This is somewhat consistent with the fact that your PATH starts with /usr/bin:/bin:/usr/sbin:/sbin (system paths). Should you have the same executable in /usr/local/bin and /Library/TeX/texbin, and wish that the latter takes precedence (because maybe it would provide a newer version of the program(s) than what you have in /usr/local/bin), you might want to swap the paths (in both of the relevant Emacs config lines). – frougon Apr 23 '20 at 13:03