You are not logged in.
Hello all,
I am a very frequent LaTeX user, and I often have BibTeX references and pstricks images, so I end up compiling my document several times for every document. To speed up this process, I wrote a short, simple shell script (below)
#!/bin/sh
file="$1"
latex \\nonstopmode\\input $file.tex
bibtex $file
latex \\nonstopmode\\input $file.tex
latex \\nonstopmode\\input $file.tex
dvips $file.dvi
ps2pdf $file.ps
This has been much nicer, since instead of typing all of those things, I simply type "mytex file."
Being the greedy person that I am, I would now like to compile it from emacs without typing the shell command, kind of like C-c C-f when I am just compiling as usual. I don't have very much experience with custom keybindings in emacs anyway, but I certaintly do not know how to call a particular shell command including the current file name.
Any tips?
Last edited by keither (2010-02-15 15:18:42)
Offline
Global binding (untested):
(global-set-key (kbd "C-c f")
(lambda ()
(shell-command (concat "mytex " buffer-file-name))))
It is simple to make it specific to a major-mode, though exactly what is required depends on the mode in use.
Offline
Thank you very much for you response. With this keybinding, I get the following error:
Wrong type argument: commandp, (lambda nil (shell-command (concat "mytex " buffer-file-name)))
Any idea what might be going on there?
Offline
Yes, sorry. I realised the mistake shortly after posting, but didn't get chance to correct it. It should have read:
(global-set-key (kbd "C-c f")
(lambda ()
(interactive)
(shell-command (concat "mytex " buffer-file-name))))
Offline
Beautiful! Thank you!
This is also a good introduction to keybinding next time I want to teach emacs something.
Offline
Actually, one more thing. My shell command is more successful if I don't type the .tex file extension. I tried to remove it like this:
(global-set-key (kbd "C-c f")
(lambda ()
(interactive)
(shell-command (concat "mytex " file-name-sans-extension (buffer-file-name)))))
but I get "Symbol's value as variable is void: file-name-sans-extension"
Offline
The parens will also need to enclose `file-name-sans-extension'.
(global-set-key (kbd "C-c f")
(lambda ()
(interactive)
(shell-command (concat "mytex " (file-name-sans-extension buffer-file-name)))))
Offline
First of all, you will probably save some compilation time by using an "inteligent" script such as latexmk. You should look into it if you have not done so already.
Second of all, AUCTeX will also suggest the "correct" next step when using C-c C-c. Also, you should consider just adding latexmk or your own script to the C-c C-c cycle. Here are some examples from my .emacs
(eval-after-load "tex"
'(progn
(add-to-list 'TeX-command-list
(list "View in Acrobat Reader" "acroread %o"
'TeX-run-command nil t))
(add-to-list 'TeX-command-list
(list "Count Words" "texcount -inc %s.tex"
'TeX-run-command nil t))
(add-to-list 'TeX-command-list
'("Synctex" "/home/rasmus/.scripts/synctex-emacs %t %b %n" TeX-run-TeX nil t) t)
))
If you want to use a script as the one suggested by yourself you would want to look into the last exampe ("Synctex").
--Rasmus
Arch x64 on Thinkpad X200s/W530
Offline
Hmm...I still get the same errors with the parentheses, actually.
Pank, good suggestions, though I'll have to go look at Synctex and make sure it's actually doing what I need. When I have pstricks images, for example, the order of operations (latex -> dvips -> ps2pdf) is sometimes important. I will definitely add all of that stuff though, I've been opening the terminal to use texcount.
Offline
AUCTeX should detect pstricks and suggest the correct procedure. This should especially be true for simple, single-file documents. I have never used pstricks myself since pdftex is a priority to me. (I stick with PGF/TikZ instead).
On the error: My snip should be okay. Try to eval it in scratch.
Arch x64 on Thinkpad X200s/W530
Offline
Sorry, the error referred to the post above yours, not your snip.
Offline
Hmm...I still get the same errors with the parentheses, actually.
Strange -- I tested it before submitting and just now without any problems so long as the buffer corresponds to a file (which itself is a trivial error to solve). Is it possible that the old command for that binding was still being used?
Last edited by chpln (2010-02-17 02:30:17)
Offline