2

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

or

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.

Drew
  • 75,699
  • 9
  • 109
  • 225
Gabriele Nicolardi
  • 1,199
  • 8
  • 17
  • 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 08: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. – Gabriele Nicolardi Jul 29 '20 at 08:10

2 Answers2

3

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"
                       exec-path)))
  (tex-file))

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"))
                                  process-environment)))
  (tex-file))
phils
  • 48,657
  • 3
  • 76
  • 115
3

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

einfeyn496
  • 231
  • 2
  • 3