0

I am new to Emacs (I am using spacemacs). Please be patient. I am still learning but now that I realize the power of Emacs I want and hope to learn elisp also.

I have a bunch of org files prefixed "01" up to "17". Each file is an individual publication. On each file I included a snippet of elisp code (borrowed from the dft-book) which looks like this one:

; This allows to selectively ignores headlines
; See: https://emacs.stackexchange.com/questions/55241/how-to-avoid-export-org-mode-header-title
(require 'ox-extra)
(ox-extras-activate '(ignore-headlines))

(org-latex-export-to-latex nil nil nil nil
        '(:with-author t
          :with-date t
          :with-title t
          :with-timestamps t
          :with-todo-keywords t
          :with-toc nil))

(shell-command (format "pdflatex -shell-escape -interaction=batchmode %s" inputfilename))
(shell-command (format "bibtex %s" inputfilename))
(shell-command (format "makeindex %s" inputfilename))
(shell-command (format "pdflatex -shell-escape -interaction=batchmode %s" inputfilename))
(shell-command (format "pdflatex -shell-escape -interaction=batchmode %s" inputfilename))
; delete some files
(mapcar (lambda (ext)
        (let ((filename (concat (format "%s" inputfilename) ext)))
          (when (file-exists-p filename) (delete-file filename))))
      '(".sol" "_xdefs.cut" ".aux" ".ind" ".ilg" ".idx"
        ".bbl" ".qsl" ".out" ".log" ".blg"))

(mapcar (lambda (x)
        (when (file-exists-p x) (delete-file x)))
      '("exerquiz.djs" "dljslib.ljs" "dljslib.djs" "texput.log" ".tex"))

(save-buffer)
(princ (format "BUILT ON %s" (current-time-string)))

When I hit C-c C-c on that block I get the pdf document generated, so it works great! Now I would like to go a step further.

With the idea of latexmk in mind, I thought it would be nice to have latex to compile the document on every change of the org file. I made a research and apparently it is possible according to reddit user u/larstvei.

I have adapted the snippet to my needs by including this at the end of the file:

# Local Variables:
# eval: (server-start)
# eval: (add-hook 'after-save-hook 'org-latex-export-to-latex nil t)
# eval: (compile (format "latexmk -pdf -pvc %s" "10-article"))
# End:

This is working fine, as soon as I modify the org file it gets exported to latex and then compiled to pdf. Amazing!

My problem is that I need to export to PDF using the first snippet I included since I need the (ox-extras-activate '(ignore-headlines)) part. Ideally I would like to have that snippet as a separated file (i.e. "myexport.el"), with the first code I included.

My purpose would be three fold:

  • I could call myexport.el from within a babel block manually (C-c C-c).

  • I could use the same code to link it to the latexmk from the local variables section and have the document built automatically whenever the file changes on disk.

  • Integrate this also on a CI on either github or gitlab.

Could anyone tell me how to do it?

Thanks a lot!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.