3

In LaTeX mode C-c C-c is bound to:

(TeX-command-master &optional OVERRIDE-CONFIRM)

Normally this interactive function runs a command, perhaps a LaTeX compilation, asking for confirmation.

In tex-buf.el it reads:

If a prefix argument OVERRIDE-CONFIRM is given, confirmation will depend on it being positive instead of the entry in `TeX-command-list'.

This is a bit cryptic for me and reading C-h v TeX-command-list didn't help.

How can I pass the prefix argument to "TeX-command-master" so that I avoid all the confirmation requests?

antonio
  • 10,629
  • 13
  • 68
  • 136
  • What I did myself, is have a function that saves the document before calling tex command master. Might do you good as well. – PascalVKooten Feb 02 '13 at 18:50
  • @Dualinity: Good only for the first confirmation. `C-c C-c` asks confirmation for types of action too, e.g. compile or view. – antonio Feb 03 '13 at 13:04
  • For "view", you could use `C-c C-v`, that's what I use anyway. For me, that does not ask for confirmation. If this does not directly do it for you, let me know because then somewhere in my settings I do have something to drop the confirmation. – PascalVKooten Feb 03 '13 at 13:51
  • @Dualinity: I get two requests for confirmation: "Save" and "Command". With a saved document I can only avoid the first one; it still asks me for LaTeXing the document. – antonio Feb 03 '13 at 14:55
  • Did you check `C-c C-v` though, this sounds still as `C-c C-c`. With the `v` it should go directly to "view" – PascalVKooten Feb 03 '13 at 15:03
  • @Dualinity: Sorry, didn't write. `C-c C-v` works fine. The problem, not a dramatic one anyway, is to avoid the confirmation when compiling. – antonio Feb 03 '13 at 16:32

6 Answers6

2

Take a look at Emacs' documentation to find out about prefix arguments. In general, you can pass a command a prefix argument with C-u followed by a number. For one-digit numbers, you can also just type Meta followed by the digit. Thus to pass a positive prefix argument to TeX-command-master you could type:

M-1 C-c C-c

However, this will actually add another minibuffer confirmation, namely about the shell command to be used to compile the LaTeX source. Without the prefix argument, a command-dependent default is used for that.

If you want to avoid the question about the command to use, you can bind the undocumented variable TeX-command-force to "LaTeX" via:

(setq TeX-command-force "LaTeX")

However, this will have the downside that you're basically binding C-c C-c to the "latex" command, you cannot use any of the other commands such as "bibtex" or "view".

Other than that, LaTeX-mode does not allow for any customization of C-c C-c. Your best options are to either advise the function TeX-command-query or to bind C-c C-c to a wrapper function to set TeX-command-force dynamically. The latter would probably be the preferred option if you also want to auto-save the buffer.

Thomas
  • 17,016
  • 4
  • 46
  • 70
  • To me `M-1 C-c C-c` keeps asking both confirmations (save and compile/view). Perhaps the answer comes from the help telling that the argument has to _positive_ "instead of the entry in 'TeX-command-list'". From the help for this variable I read that `TeX-command-list` is a list of commands to execute on the current document, where each element is a list, whose first element is the name of the command as it will be presented to the user. I keep not understanding which is the _entry_ requested _to be positive_. – antonio Feb 03 '13 at 13:23
  • Perhaps you could clarify what confirmations you actually mean. If you give a positive prefix to `Tex-command-master` by typing `M-1` before `C-c C-c` you actually *add* more confirmations, namely about the shell command to be used for which otherwise a default would be used. – Thomas Feb 03 '13 at 22:31
  • I simply mean all confirmations, I'd like to have none, to further clarify how `C-c C-c` works. It is a command context-driven. If the TeX file is not saved, it asks to confirm that: a) you want to save the file and b) you want to compile it. If the TeX file is saved, it asks to confirm that you want to view it via default viewer. Default values are always OK and I'd like to override the confirmations. Hope this helps. – antonio Feb 04 '13 at 01:25
2

I puzzled over the OVERRIDE-CONFIRM bit for a while, and couldn't figure out how it was supposed to work. If you want to automatically run Latex on your file, without being bothered about saving it first, or confirming that you want latex (rather than view, bibtex etc), you could use a function like this:

(defun my-run-latex ()
  (interactive)
  (TeX-save-document (TeX-master-file))
  (TeX-command "LaTeX" 'TeX-master-file -1))

Bind this to something handy, and you'll still have C-c C-c for when you want to use the default processing commands. You may want to modify the TeX-command line if "Latex" isn't the processor you want to call.

Tyler
  • 9,872
  • 2
  • 33
  • 57
  • The problem, is that unless setting some specific option, `(TeX-save-document (TeX-master-file))` asks for a confirmation as well. Besides `TeX-command-master` tries to be clever, giving the right command for the right occasion, e.g. compiling for buffer modified, opening the viewer otherwise. I tried to remedy to this posting an answer. – antonio Feb 05 '13 at 01:58
  • How can I bound `my-run-latex` to `C-c C-c`? – alper Jan 14 '21 at 12:19
2

It seems that the mystery of the OVERRIDE-CONFIRM continues. In the meantime a fellow suggests that, if we are unable to manage TeX-command-master, we can simply rewrite it.

In my version, based on his, if the buffer is not modified, the external viewer is launched; if the buffer is modified the compiler is run. Everything with no confirmation for saving or running the given command.

(defun my-run-latex ()
  (interactive)
  (if (buffer-modified-p)
      (progn  
        (setq TeX-save-query nil) 
        (TeX-save-document (TeX-master-file))
        (TeX-command "LaTeX" 'TeX-master-file -1))
    (TeX-view)))

Of course one can bind my-run-latex to whatever keybinding.

On the user's point of view this is a solution to my own question. Do I click the close tag? Well, on the curious guy point of view I am still interested in understanding the mysterious TeX-command-master technicalities.

If someone should happen to know...

P.S. Yes, TeX-save-query overrides the save-file request, also with TeX-command-master, that is C-c C-c. But you will still be asked to confirm the command action.

Tyler
  • 9,872
  • 2
  • 33
  • 57
antonio
  • 10,629
  • 13
  • 68
  • 136
  • 1
    If you put the assignment of `TeX-save-query` in a `(let ...)` statement your change will be local only, and won't alter the default value of this variable: `(defun my-run-latex () (interactive) (if (buffer-modified-p) (let ((TeX-save-query nil)) (TeX-save-document (TeX-master-file)) (TeX-command "LaTeX" 'TeX-master-file -1)) (TeX-view)))` – Tyler Feb 05 '13 at 03:36
  • +1 thanks, @Tyler. Do you know if there is a way to tell when `TeX-command "LaTeX"` has finished? If we are to rewrite `TeX-command-master`, we could do a better job by setting a build and view sequence as many modern specialised TeX editors: `TeX-command "LaTeX" -> TeX-view`. Anyway `TeX-view` gives an error if it is started immediately (i.e. before `TeX-command "LaTeX"` finishes its job). – antonio Feb 05 '13 at 13:36
2

Build & view

Again, this solution, instead of modifying the behaviour of the TeX-command-master, rewrites it. The rewritten version of the command, named build-view, follows a rather straightforward logic.

  1. If the LaTeX file buffer is not-modified, it runs the default viewer;
  2. If the buffer is dirty, it runs the default LaTeX compiler and, after the build, opens the output in the default viewer.

Here's the code:

(defun build-view ()
  (interactive)
  (if (buffer-modified-p)
      (progn  
    (let ((TeX-save-query nil)) 
    (TeX-save-document (TeX-master-file)))
    (setq build-proc (TeX-command "LaTeX" 'TeX-master-file -1))
    (set-process-sentinel  build-proc  'build-sentinel))
    (TeX-view)))

(defun build-sentinel (process event)    
  (if (string= event "finished\n") 
      (TeX-view)
    (message "Errors! Check with C-`")))

You can now type M-x build-view and start the told build-view process or associate it with a new keybinding such as “F2”:

(add-hook 'LaTeX-mode-hook '(lambda () (local-set-key (kbd "<f2>") 'build-view)))

Note: As suggested by Tyler, TeX-save-query variable is changed locally, therefore the old C-c C-c/ TeX-command-master is unaffected and will keep asking confirmations.

Do edit this code to make it better or easier to read!

antonio
  • 10,629
  • 13
  • 68
  • 136
  • nice one, I've been looking for that command since a while! Just one nit: if it compiles successfully, the compile message `hit C-c C-l to view the log` won't disappear. I replaced `(TeX-view)` by `(TeX-view)` to fix that, I don't need to trigger `TeX-view` each time I compile! – Kevin Jun 11 '13 at 14:03
  • @Kevin: sorry, replaced `(TeX-view)` by `(TeX-view)`? Typo? – antonio Jun 14 '13 at 19:18
  • sure it's a type, I meant "I replaced it by (message "Document successfully formatted.`") – Kevin Jun 15 '13 at 16:16
  • @Antonio, when there is an error, doing C-c ` or C-` does not enter the debugging mode. Any solution for that? Or do we just do C-c C-c and check ? Just want to know why this might be happening. – Anusha Jul 27 '13 at 16:59
0

If you are just looking to compile the latex source without a confirmation dialog, just add the following to your .emacs:

(setq TeX-command-force "")

You can then compile the source with C-c C-c and it won't ask to confirm. The only problem with this solution is that you can no longer change the command, but with most documents you won't want to. I might suggest that at the same time you can add this to your .emacs for even more flexibility, giving you a C-c C-c equivalent to the former behavior:

(define-key LaTeX-mode-map "\C-c\C-a"   
   ;;; 'a' for ask, change to anything you want 
  (lambda (arg) (interactive "P") 
    (let ((TeX-command-force nil)) 
      (TeX-command-master arg)))) 

You can then just work away at your document, do a C-x C-s, C-c C-c and then C-c C-v to see it. Like others have suggested you can also do the same for the save command and have it compile automatically on save, but some of my documents are in CVS and so I avoid putting hooks on that.

Credit to Ivan for some help on this one - don't know if he is on StackOverflow

0

I think the gist of this question is "how do I quickly compile my TeX document from AUCTeX without all the key presses and confirmations?"

My answer to that is to use the latexmk command rather than trying to coerce AUCTeX to do it.

latexmk -pdf -pvc myfile.tex

latexmk will monitor the file in question and rebuilt it as soon as you save it. If you use a good pdf viewer, it will notice the change in PDF and re-display it immediately. On OS X, skim works well for this.

Jason Lewis
  • 147
  • 11