5

When I run TeX on a file containing an error (e.g. an undefined control sequence), I receive this message

Type <return> to proceed, S to scroll future error messages,
R to run without stopping, Q to run quietly,
I to insert something, E to edit your file,
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
H for help, X to quit.
? 

If I type "E" to edit my file, I then receive

...
I cannot find emacs in the PATH.

Is it possible to change the editor from emacs to one that is installed on my system?

If so, what would the procedure be?

(My TeX distribution is TeX Live 2021, if that is relevant.)

  • 2
    very few people use e these days, it is far more common to stay within the editor and run tex from within the editor rather than fire up a new editor when you get an error. – David Carlisle Jun 19 '21 at 10:19
  • @DavidCarlisle I learned that it's possible to do both, since my editor has a built-in terminal and also a command-line switch to reuse the running instance if invoked from elsewhere – user244733 Jun 19 '21 at 13:39

1 Answers1

7

You have to set the TEXEDIT environment variable in your texmf.cnf file. To find this file you can run kpsewhich texmf.cnf which, on Linux, should be /usr/local/texlive/2021/texmf.cnf if you used the default installation directory.

The default for TEXEDIT is:

%TEXEDIT = vi +%d '%s'                    % default for Unix
%TEXEDIT = texworks --position=+%d "%s"   % default for Windows

In the TEXEDIT line, the '%s' is the file name wrapped around quotes to preserve spaces, and %d is the line number. If your editor doesn't open at a specific line number, you can omit %d.

Since you didn't say which editor you are using, here are a few options (found on the internet; most of them untested), in alphabetic order:

TEXEDIT = atom "%s":+%d
TEXEDIT = emacs +%d "%s"
TEXEDIT = nano +%d "%s"
TEXEDIT = start notepad++ "%s" -n%d
TEXEDIT = subl "%s":+%d
TEXEDIT = texstudio --line "+%d" "%s"
TEXEDIT = texworks --position=+%d "%s"
TEXEDIT = vi +%d "%s"
TEXEDIT = vim +%d "%s"
  • I was able to get it working (I am on Windows). Is there another directory for the texmf.cnf file so as to be year-independent? Or would I need to redo this every time I upgrade the distribution? – user244733 Jun 19 '21 at 02:14
  • @user244733 On Linux, I'd do what's described here, so there should be a similar procedure on Windows. i.e.: create a common texmf.cnf and create an environment variable called TEXMFCNF that points to the folder that contains that file. – Phelype Oleinik Jun 19 '21 at 03:42
  • I think I got it to work. Using a colon at the end of the path in the definition of TEXMFCNF as described in the post gave me the warning kpathsea: configuration file texmf.cnf not found in these directories: $TEXMFCNF when I typed kpsewhich -all texmf.cnf. If I used a semicolon instead of a colon, there is no warning and it yields the paths to my personal texmf.cnf and the distribution texmf.cnf files. Maybe it is a Windows thing – user244733 Jun 19 '21 at 04:28
  • 1
    @user244733 yes web2c paths use ; on windows to allow : to be used for drive letters. – David Carlisle Jun 19 '21 at 10:14
  • One can also set TEXEDIT in the environment, which would override the value in texmf.cnf – egreg Jun 19 '21 at 11:59