0

I'm using TeXLive 2014 on MacOS X 10.6 and I'm currently working with Aquamacs 2.5.

I'm currently using two different shell scripts for compiling my LaTeX document (thesis), which are located in ~/bin/script1.sh and ~/bin/script2.sh

  • At the moment I always switch to the terminal application for compiling and launch one of those commands there.
  • I'd like to define a custom keybinding in Emacs which lets me run those scripts directly without leaving Emacs.

How can I do that?

1

I assume you call your compile scripts like this:

~/bin/script1.bash master.tex

and that you only has to call it once. In this case here's a defun which does it:

(defun tex-custom-compile (arg)
  (interactive "P")
  "Calls `~/bin/script1.sh' on file associated with current buffer.
With C-u calls `~/bin/script2.sh' instead"
  (let (script texFile)

    (cond
     ((equal arg '(4))
      (setq script "~/bin/script2.sh ")
     )
     (t
      (setq script "~/bin/script1.sh ")
     )
    )

    (async-shell-command 
     (concat
      script
      (buffer-file-name)
     )
    )
  )
)

This defun should be easy to tweak to adjust it to your particular need. When you are satisfied with this defun bind it to a key:

(define-key TeX-mode-map (kbd "C-c C-t C-p") 'tex-custom-compile)
  • 3
    Could you edit your code to follow elisp coding conventions regarding close parentheses? – Dan Jan 8 '15 at 20:39
  • @Dan: I'd read the article you linked. For myself I use this style, because it allows me to comment a single line or a block: if I were to put multple closing parenthesis on the same line -- commenting won't work the simple way. – Adobe Jan 8 '15 at 20:47
  • thanks for your help! No, I just call the script like I wrote (without any additional arguments yet, as it only compiles my thesis - THE ONE document ;-) ). And yes, I just call it once. One of the scripts just starts one pdflatex run and does some postprocessing/ document statistics, the other one starts latexmk (with several runs) and then the postprocessing/ document statistics. – MostlyHarmless Jan 8 '15 at 21:20
  • 1
    @Martin: just comment (buffer-file-name) line and you done. – Adobe Jan 8 '15 at 23:16

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.