Emacs / AUCTeX Prefix Arguments

In LaTeX mode, C-c C-c

bound to:

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

      

Typically this interactive function will execute a command, perhaps a LaTeX compilation, asking for confirmation.

In tex-buf.el

he reads:

If the prefix argument OVERRIDE-CONFIRM is specified, confirmation will depend on being positive instead of being written to "TeX-command-list".

It's a little cryptic to me and reading it C-h v TeX-command-list

didn't help.

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

+3


source to share


6 answers


Build and View

Again, this solution TeX-command-master

overwrites it instead of changing the behavior . The rewritten version of the command, named build-view

, follows fairly simple logic.

  • If the LaTeX file buffer is unmodified, it launches the default viewer;
  • If the buffer is dirty, it launches the default LaTeX compiler and, upon 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 enter M-x build-view

and run the specified build process, or bind it to a new key binding such as "F2":

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

      

Note. As suggested by Tyler, the variable TeX-save-query

changes locally, so the old C-c C-c

/ TeX-command-master

unchanged and will keep asking for confirmation.

Modify this code to make it better or easier to read!

+2


source


See the Emacs documentation for prefix arguments. In general, you can pass the command to a prefix argument C-ufollowed by a number. For single digit numbers, you can also enter Metafollowed by a number. Thus, to pass a positive prefix argument TeX-command-master

, you can type:

M-1 C-c C-c

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

If you want to avoid the question of the command used, you can bind the undocumented variable TeX-command-force

to "LaTeX" with:



(setq TeX-command-force "LaTeX")

      

However, this will have the disadvantage that you basically bind C-c C-cto the "latex" command, you cannot use any other commands like "bibtex" or "view".

Also, LaTeX mode doesn't allow for customization C-c C-c. Your best options are either to tell a function TeX-command-query

, or bind C-c C-cto a wrapper function to set dynamically TeX-command-force

. The latter will probably be the preferred option if you also want to automatically save the buffer.

+2


source


I puzzled the OVERRIDE-CONFIRM bit for a while and couldn't figure out how it was supposed to work. If you want to automatically launch Latex on your file without worrying about saving it in the beginning, or confirming you want latex (not view, bibtex, etc.), you can use a function like this:

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

      

Tie this to something convenient and you still have C-c C-c

if you want to use the default processing commands. You can change the line TeX-command

if Latex is not the processor you want to call.

+2


source


The mystery seems OVERRIDE-CONFIRM

to continue. At the same time, a person assumes that if we cannot manage TeX-command-master

, we can simply rewrite it.

In my version, based on it, if the buffer is not changed, an external viewer is launched; if the buffer is modified, the compiler starts. All without confirmation of saving or executing this 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, my-run-latex

you can bind for binding my-run-latex

.

From a user perspective, this is a solution to my own question. Am I clicking the close tag? Well, from a curious point of view, I'm still interested in mysterious technical considerations.

If anyone needs to know ...

PS Yes, TeX-save-query

cancels the request to save the file, also with TeX-command-master

, that is C-c C-c

. But you will still be asked to confirm the action of the command.

+2


source


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

(setq TeX-command-force "")

      

Then you can compile the source with Cc Cc and it won't ask for confirmation. The only problem with this solution is that you can no longer change the command, but with most docs, you won't want to. I would suggest that at the same time you can add this to your .emacs for even more flexibility by providing a Cc Cc equivalent to the previous 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)))) 

      

Then you can just work in your document, do Cx Cs, Cc Cc and then Cc Cv to see it. Like others have suggested, you can also do the same for the save command and compile it automatically on save, but some of my docs are in CVS and so I didn't put any hooks on it.

Credit to Ivan for help with this - don't know if it's on StackOverflow

0


source


I think the gist of this question is, "How do I quickly compile my TeX document from AUCTeX without all the keystrokes and confirmations?"

My answer to this is using the latexmk command, not trying to get AUCTeX to do it.

latexmk -pdf -pvc myfile.tex

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

0


source







All Articles