macOS, emacs latex编译正常,emacs client编译则报错无法找到 latexmk

macOS 10.14.1

emacs使用homebrew的emacs-plus安装,并启动服务

使用zsh,$PATH的修改是在 $HOME/.zshenv 中,如果不使用 speacmacs,不用修改path,因为texlive在 /etc/path.d 中有添加路径。

使用 Automator 做了emacs client 的app /usr/local/bin/emacsclient -n -c -a "" -- "$@"

spacemacs使用的是develop分支,因为stable分支的latexmk始终找不到,是看的spacemacs某个issue改的,改完后正常使用。

但是却发现 emacs client还是报错latexmk找不到。

spacemacs 中自定义设置见下:

   dotspacemacs-configuration-layers
   '(
     ;; ----------------------------------------------------------------
     ;; Example of useful layers you may want to use right away.
     ;; Uncomment some layer names and press <SPC f e R> (Vim style) or
     ;; <M-m f e R> (Emacs style) to install them.
     ;; ----------------------------------------------------------------
     helm
     auto-completion
     ;; better-defaults
     emacs-lisp
     git
     markdown
     org
     python
     ;; (shell :variables
     ;;        shell-default-height 30
     ;;        shell-default-position 'bottom)
     (spell-checking :variables spell-checking-enable-auto-dictionary nil)
     syntax-checking
     ;; version-control
     (latex :variables latex-build-command "LatexMk")
     )

(defun dotspacemacs/user-config ()
  "Configuration function for user code.
This function is called at the very end of Spacemacs initialization after
layers configuration.
This is the place where most of your configurations should be done. Unless it is
explicitly specified that a variable should be set before a package is loaded,
you should place your code here."
  (add-hook 'doc-view-mode-hook 'auto-revert-mode)
  (setq TeX-view-program-list
        '(("Okular" "okular --unique %o#src:%n`pwd`/./%b")
          ("Skim" "displayline -b -g %n %o %b")))
  (cond
   ((spacemacs/system-is-mac) (setq TeX-view-program-selection '((output-pdf "Skim"))))
   ((spacemacs/system-is-linux) (setq TeX-view-program-selection '((output-pdf "Okular")))))
  )

同有一台arch,共享 .spacemacs,spacemacs还在stable分支,emacs client使用正常。

望诸位大佬,尤其是在mac上用latex的不吝赐教。

自己破案了

sudo launchctl config user path $PATH


知道是为啥了,解决方法就很多了。

通过launchctl跑自启动的话,plist的$PATH默认是空的,就和Automator.app 里脚本的可执行文件需要写full path一样的。

所以解决办法有这些:

  • sudo launchctl config user path $PATH 改所有 app 的 $PATH 环境变量,这样对系统改动有点大,work 后我又改回空了。
  • plist里加环境变量,这个可以的,但是提交给emacs-plus不合适,因为每个人的path不一定相同,今天我需要latex,明天别人需要别的,写plist的应该还需要在homebrew里hack下,把当前$PATH加到plist里。应该work,没测试。
  • 最简单的,我现在用的方法,可以放弃homebrew的服务了,emacsclient.app 的脚本写作/usr/local/bin/emacsclient -nca "/usr/local/bin/emacs --daemon" -- "$@" >/dev/null 2>&1 或者 /usr/local/bin/emacsclient -nca "/usr/local/bin/emacs --fg-daemon" -- "$@" >/dev/null 2>&1 后一个需要emacs 26.1以后支持,按说前一种跑的方式,在终端里只需要跑一遍,不过实际用起来,都需要跑2遍,当然只是第一次开emacsclient的时候需要跑2遍,第一次跑deamon,第二次运行emacsclient。都work。

推荐最后一种方法,来搞 emacsclient.app,终端设置 alias 或者 function 就更直接了,我就不班门弄斧了。

1 个赞