2

I would like to run force-compile (see Run TeX-command-run-all when there are no changes in .tex-file) on a region of my LaTeX document.

(defun force-compile ()
"Set the file modification times on the current file, then call
TeX-command-sequence.
This forces a complete recompilation of the document, even if the 
source
(.tex) is older than any existing outputs (.pdf etc)."
(interactive)
(set-file-times (buffer-file-name)) ;; sets mod time to current time
(TeX-command-sequence t t))

I was already able to bind force-compile to C-c C-a which then compiles the file even when there are no changes in the file itself. Now I want to be able to do the same on a region of the file.

How can i use force-compile on a region of the LaTeX-file?

  • 1
    I'm not sure what the most elegant way to do this is, but you could create a new function (force-compile-region) with the same definition, but replace (TeX-command sequence t t ) with (TeX-command-region). – Tyler Jun 5 '18 at 17:50
  • That worked perfectly when using (TeX-command-run-all-region). One last thing: I need to save the region of the buffer and not the buffer itself. Is there a command to it? – quark Jun 6 '18 at 9:51
  • 1
    I don't think it's possible to save only part of a buffer - it's all the same file. I don't understand what you're asking. – Tyler Jun 6 '18 at 13:44
  • @quark Maybe you are looking for write-region? – Tobias Jun 6 '18 at 17:00
  • 1
    See the help for write-region, C-h f write-region. It takes three arguments, the start and end of the region ((region-beginning) and (region-end) should work), and the name of a file to write the region to. You don't want to use the current file, or you'll end up over-writing your entire file with just the active region, erasing everything else. – Tyler Jun 7 '18 at 20:42
1

From the comment thread, the following solution appears to work:

(defun force-compile-region ()
  "Set the file modification times on the current file, then call
   TeX-command-run-all-region. This forces a complete recompilation of 
   the document, even if the source (.tex) is older than any 
   existing outputs (.pdf etc)."
  (interactive)
  (set-file-times (buffer-file-name)) ;; sets mod time to current time
  (TeX-command-run-all-region))

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.