In my shell (Bash), I can switch among several LaTeX distros setting the $PATH variable. E.g.:

export PATH=/usr/local/texlive/2016/bin/x86_64-linux:$PATH


export PATH=/usr/local/texlive/2018/bin/x86_64-linux:$PATH

This doesn't affect the LaTeX distro used by emacs when I call the function tex-file.

Is there a way to set the $PATH variable used by emacs once it is running.

I need it to test the .pdf file layout generated by different LaTeX distros while working on a document.

  • From emacs you can call setenv and then modify PATH as you need, which should have the effect you desire. If this works for your use case, you could probably write a small elisp function to ease the switching between various texlive distributions
    – einfeyn496
    Jul 29 '20 at 8:00
  • @einfeyn496 Ok, I just noticed that changing the value of PATH does't have effect on the Latex distro used by emacs. Your answer is right, my question was wrong. if you deem it appropriate you can post your comment as an answer so I can accept it. Jul 29 '20 at 8:10

Emacs initialises C-hv exec-path based on PATH at start-up, and finds executables based upon that.

This doesn't affect the LaTeX distro used by emacs when I call the function tex-file.

Try this:

(let ((exec-path (cons "/usr/local/texlive/2018/bin/x86_64-linux"

Note that exec-path is not automatically copied into the environment inherited by other processes started by Emacs; so if the executable ultimately called by tex-file itself also required PATH to contain /usr/local/texlive/2018/bin/x86_64-linux then you would need to set process-environment as well:

(let* ((tex "/usr/local/texlive/2018/bin/x86_64-linux")
       (exec-path (cons tex exec-path))
       (process-environment (cons (format "PATH=%s:%s"
                                          tex (getenv "PATH"))

Using the emacs function setenv is a way to modify the environment of the running emacs process.

For your particular use case, you'd want to evaluate:

(setenv PATH "modified-path-variable")

or simply M-x setenv and enter the value at the prompt.

You can put together an elisp function following the answers here, to quickly toggle between your texlive distributions.

Or you can probably do the same using the answer from @phils

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.