When creating a new TeX document, AUCTeX asks what the master file should be, for instance:

AUCTeX asks for the master file

The value specified is written into the file as an Emacs file variable (see here). For example, choosing the default in the above example results in the following initial document:

%%% Local Variables:
%%% mode: latex
%%% TeX-master: "<none>"
%%% End:

If the new file is not going to \include other TeX files, it is its own master file. To indicate this, AUCTeX's TeX-master option should be set to t (see here). This configuration is stored in the new file as a file variable as follows:

%%% TeX-master: t

Observe that in contrast to the previous example the t is not delimited with quotation marks.

Suppose that upon creating a new TeX document I am presented with the Master file query shown in the screencap above, namely

Master file: (default <none>) ~/

What should I enter if I wish to set the TeX-master variable to t? Simply writing t, thus:

Master file: (default <none>) t

doesn't work, as this results in a quoted value:

%%% TeX-master: "t"

which is not functionally equivalent to

%%% TeX-master: t

Of course, I can always edit the file variable after the document is created, but is there a way to generate a correct file from the get-go?

  • I don't get <none> as default value. I get "this file" which results in the value t. The logic for finding a default is in the function TeX-dwim-master. It looks for a buffer in the same directory which already has a master file. – YoungFrog May 30 '17 at 9:52
  • @YoungFrog: I also normally get "this file", but there are circumstances when one is presented with another default option, which may be <none> or may be some other value. I don't know what these circumstances are, but it doesn't matter. The important thing is that these circumstances occur. I know it from experience. The question is: when these circumstances occur, how can you instruct AUCTeX to set Tex-master to t? – Evan Aad May 30 '17 at 10:06
  • Ok I misread the question, I thought you wanted to debug this specific default value (which looks bogus). Back to the question : I don't have an Emacs session at hand to check, but I believe hitting C-g does that. – YoungFrog May 30 '17 at 10:17
  • 1
    What's your default value of TeX-master? Did you add the line (setq-default TeX-master nil) in your init file? – giordano May 30 '17 at 15:35
  • 2
    @giordano - I can confirm that AUCTeX also included the string "<none>" into my a file of mine as value to TeX-master. But I couldn't create a recipe to reproduce this issue. – Arash Esbati May 31 '17 at 20:16

TL;DR version

Any of these should work. At least they work for me:

  • C-a C-k RET (go to beginning of line, kill it, confirm)
  • C-a C-k C-m (same)
  • M-p RET (insert current file name and confirm)

(The third one won't work in every circumstances.)

Longer version:

The relevant bit of code is in TeX-master-file-ask :

(let* ((default (TeX-dwim-master))
   (name (or (and (eq 'dwim TeX-master) default)
         (condition-case nil
         (read-file-name (format "Master file: (default %s) "
                     (or default "this file"))
                 nil default)
           (quit "<quit>")))))
  (cond ((string= name "<quit>")
     (setq TeX-master t))
    ((string= name default)
     (setq TeX-master default)
      ;; Default `read-file-name' proposes and buffer visits a file.
      (string= (expand-file-name name) (buffer-file-name))
      ;; Default of `read-file-name' and buffer does not visit a file.
      (string= name default-directory)
      ;; User typed <RET> in an empty minibuffer.
      (string= name ""))
     (setq TeX-master t)
     (setq TeX-master (TeX-strip-extension (file-relative-name name)
                       (list TeX-default-extension)

I suggested in a comment that C-g would work but, as you can see, while hitting C-g indeed sets the file as its own master, it does not actually update the file variables accordingly.

On the other hand, doing any of these :

  • giving as input the actual name of the file being visited
  • giving as input the name of the directory in which the file lies
  • giving an empty input

will both set the variable TeX-master and update the file variables.

  • Thanks! Why is it the case that 'The third one won't work in every circumstances'? – Evan Aad May 30 '17 at 17:05
  • 1
    M-p grabs the last filename read from the history, which might not be the current filename. IOW : inserting the current filename will always work, but the key sequence I suggested might not do that in some circumstances. – YoungFrog Jun 1 '17 at 9:19

What should I enter if I wish to set the TeX-master variable to t?

Just select the current file.

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.