Created
January 27, 2018 19:55
-
-
Save dwcoates/3a3a00d6436e24105a874b3500b7d845 to your computer and use it in GitHub Desktop.
A function for cleanly exporting current active region to pdf. Unlike normal exporting, prompts for filename and declutters output.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun org-latex-export-region-to-pdf (beg end &optional no-declutter) | |
"Export the current region to pdf, prompting for output filename. | |
This can be done by narrowing region, but it's a bit slow, and | |
the output is ugly and cluttered. More importantly, it also | |
writes the pdf file for the region using the name of the | |
original file, which is obviously annoying. | |
with NO-DECLUTTER non-nil, don't declutter the pdf output." | |
(interactive (if (region-active-p) | |
(list (region-beginning) | |
(region-end) | |
(or current-prefix-arg no-declutter)) | |
(user-error "No active region to export."))) | |
(when (not (equal major-mode 'org-mode)) | |
(user-error "Not in an org-mode context.")) | |
(let ((buf (make-temp-name "temp")) | |
(str (buffer-substring-no-properties beg end))) | |
(switch-to-buffer buf) | |
(org-mode) | |
(when (not arg) | |
(insert "#+OPTIONS: toc:nil num:nil prop:nil tags:nil title:nil\n\n")) | |
(insert str) | |
(org-forward-heading-same-level 1 t) | |
(let ((cur-level (org-current-level))) ; | |
(loop repeat (/ (- cur-level 1) (org-level-increment)) | |
do (org-promote-subtree))) | |
(org-latex-export-to-pdf) | |
(kill-buffer buf))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment