1

I just started using emacs so I don't know if I am even doing this correctly. C-c C-c then the prompt says Command [pdflatex]: so I type in latexmk. Is that even what it is expecting? Then I am giving the following error:

Latexmk: Initialization file '/home/dustin/.latexmkrc' gave an error:
     Substitution pattern not terminated at (eval 10) line 1, <GEN0> chunk 1.

Latexmk: Stopping because of problem with rc file

Here is my .latexmk file:

$pdflatex = 'pdflatex -interaction=nonstopmode -file-line-error -synctex=1' -pdf %s;

and here is my .emacs file:

(add-to-list 'load-path "~/.emacs.d/plugins")
(setq py-install-directory "~/.emacs.d/plugins")
(require 'python-mode)

;; ========== Prevent Emacs from making backup files ==========                        

(setq make-backup-files nil)

;; ========== Enable Line Numbering ==========                                         

(line-number-mode 1)

;; ========== Set the fill column ==========                                           

(setq default-fill-column 80)

;; ===== Turn on Auto Fill mode automatically in all modes =====                       

;; Auto-fill-mode the the automatic wrapping of lines and insertion of                 
;; newlines when the cursor goes over the column limit.             

;; This should actually turn on auto-fill-mode by default in all major                 
;; modes. The other way to do this is to turn on the fill for specific modes           
;; via hooks.                                                                          

(setq auto-fill-mode 1)

;; ========= Set colours ==========                                                    

;; Set cursor and mouse-pointer colours                                                
(set-cursor-color "white")
(set-mouse-color "goldenrod")

;; Set region background colour                                                        
(set-face-background 'region "blue")

;; Set emacs background colour                                                         
(set-background-color "black")

(defun run-latexmk ()
  (interactive)
  (let ((TeX-save-query nil)
        (TeX-process-asynchronous nil)
        (master-file (TeX-master-file)))
    (TeX-save-document "")
    (TeX-run-TeX "latexmk"
         (TeX-command-expand "latexmk -pdflatex='pdflatex -file-line-error -synctex=1'\
                               -pdf %s" 'TeX-master-file)
                 master-file)
    (if (plist-get TeX-error-report-switches (intern master-file))
        (TeX-next-error t)
      (progn
    (demolish-tex-help)
    (minibuffer-message "latexmk: done.")))))
N.N.
  • 8,336
  • 12
  • 54
  • 94
dustin
  • 4,309
  • 12
  • 57
  • 79

2 Answers2

2

The error you get is due to your .latexmkrc file. Rather than providing the command-line option -pdf you can use the equivalent configuration option $pdf_mode = 1;. Also, appending the source file, %s, to the configuration file seem to confuse latexmk. Thus, try to use:

$pdf_mode = 1;
$pdflatex = 'pdflatex -interaction=nonstopmode -file-line-error -synctex=1';

If you want to bind latexmk to a key in Emacs and make it show errors if there are any you might be interested in the answers to this question.

Community
  • 1
  • 1
N.N.
  • 8,336
  • 12
  • 54
  • 94
  • 1
    that got me passed the first error but it still isn't working. It now says `LaTeX exited abnormally with code 1` – dustin Apr 09 '13 at 15:22
  • @dustin Are you sure that is not due to `pdflatex` failing, i.e. that there is an error in the LaTeX file you try to compile? – N.N. Apr 09 '13 at 15:42
  • on tex.stackexchange I asked a different question and doing `C-c C-t C-p` would work. It did. How can I incorporate this into emacs? I have been reading all the post on tex and over but I can't seem to get AucTex, Latexmk, Okular, and Emacs to work right. – dustin Apr 09 '13 at 15:44
  • @dustin Try to use the post I linked to from this answer and mind that you need to use both answer and edit them to user okular rather than evince. – N.N. Apr 09 '13 at 15:46
  • There is nothing about Evince any of the following links since some link to other pages. [auctex Emacs](http://stackoverflow.com/questions/7885853/emacs-latexmk-function-throws-me-into-an-empty-buffer), [auctex Emacs follow up](http://stackoverflow.com/questions/7587287/how-do-i-bind-latexmk-to-one-key-in-emacs-and-have-it-show-errors-if-there-are-a), [latex how to call latexmk emacs](http://stackoverflow.com/questions/2199678/how-to-call-latexmk-in-emacs-and-jump-to-next-error). There is one problem. They have different functions and different latexmkrc. What do I follow? – dustin Apr 09 '13 at 15:53
  • @dustin Sorry, I am tired. The link I refer to is the right one but the `latexmk` setup is separate from pdf viewer setup. Once you got `latexmk` working you should be able to setup emac with Okular. – N.N. Apr 09 '13 at 15:57
  • so should I just delete everything related to `latexmk` in my current `.emacs` and paste that in there? – dustin Apr 09 '13 at 15:59
  • @dustin Yes.. Do as the posts say. Use the required parts by putting them in your .emacs. Backup first though so you do not lose anything you do not want to lose. – N.N. Apr 09 '13 at 16:02
  • @dustin I suggest you ask a new question because this site works best when you ask one clearly defined question at the time. – N.N. Apr 09 '13 at 16:25
0

I found what needed to be done. On this post how to call latexmk, I just had to add the

(add-hook 'LaTeX-mode-hook (lambda ()
  (push
    '("Latexmk" "latexmk -pdf %s" TeX-run-TeX nil t
      :help "Run Latexmk on file")
    Tex-command-list)))

Now, I am just left with having okular to produce the pdf after completion. Does anyone have an idea on that?

Community
  • 1
  • 1
dustin
  • 4,309
  • 12
  • 57
  • 79