commit b236013b2e7599c85d8698ad2f09201d5b7702c9 Author: Philip Woods Date: Thu Apr 30 10:14:30 2015 -0400 Refactored init-ipsur.el and Makefile to allow building textbook from withing Emacs and removing dependence on absolute directories diff --git a/IPSUR.org b/IPSUR.org index f13813e..ebc78c1 100644 --- a/IPSUR.org +++ b/IPSUR.org @@ -99,7 +99,7 @@ bayesian material in later editions of this book. ** Exercises #+LaTeX: \setcounter{thm}{0} -#+INCLUDE: "~/git/IPSUR/include/prelim.R" src R +#+INCLUDE: "include/prelim.R" src R * An Introduction to R :introR: :PROPERTIES: diff --git a/Makefile b/Makefile index 3b7cc24..0401eb8 100644 --- a/Makefile +++ b/Makefile @@ -19,41 +19,37 @@ .PHONY: pkg .PHONY: www -basedir = git -buildir = build -ipsurdir = IPSUR -figdir = fig -psdir = ps -pdfdir = pdf -htmldir = html -texdir = tex +basedir := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) +buildir = $(basedir)/build +figdir = $(basedir)/fig +psdir = $(basedir)/ps +pdfdir = $(basedir)/pdf +htmldir = $(basedir)/html +texdir = $(basedir)/tex orgfile = IPSUR -backdir = backup -Rdir = R +backdir = $(basedir)/backup +Rdir = $(basedir)/R all: -mkdir $(texdir) -mkdir $(psdir) - emacs -Q -batch -eval "(progn (load \"~/$(basedir)/$(ipsurdir)/init-ipsur.el\") (R) (org-publish \"ipsurlatex\"))" + emacs --batch -eval "(progn (load \"$(basedir)/init-ipsur.el\") (R) (ipsur-publish \"ipsurlatex\"))" -cd $(texdir); latex $(orgfile).tex; bibtex $(orgfile); makeindex $(orgfile); latex $(orgfile).tex; latex $(orgfile).tex; dvips $(orgfile) gs -dSAFER -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sPAPERSIZE=a4 -dPDFSETTINGS=/printer -dCompatibilityLevel=1.3 -dMaxSubsetPct=100 -dSubsetFonts=true -dEmbedAllFonts=true -sOutputFile=$(texdir)/$(orgfile).pdf $(texdir)/$(orgfile).ps -rm -r ~/.org-timestamps tex: -mkdir $(texdir) - emacs -Q -batch -eval "(progn (load \"~/$(basedir)/$(ipsurdir)/init-ipsur.el\") (R) (org-publish \"ipsurlatex\"))" + emacs --batch --eval "(progn (load \"$(basedir)/init-ipsur.el\") (ipsur-publish \"ipsurlatex\"))" -rm -r ~/.org-timestamps pdf: - -rm $(pdfdir) - cp -R $(texdir) $(pdfdir) - -cd $(pdfdir); xelatex $(orgfile).tex; bibtex $(orgfile); makeindex $(orgfile); xelatex $(orgfile).tex; xelatex $(orgfile).tex + emacs --batch --eval "(progn (load \"$(basedir)/init-ipsur.el\") (ipsur-publish-pdf)" texpdf: tex pdf figures: - -mkdir $(psdir) - emacs -Q --batch --eval "(progn (load \"~/$(basedir)/$(ipsurdir)/init-ipsur.el\") (R) (find-file \"~/$(basedir)/$(ipsurdir)/$(orgfile).org\") (org-babel-execute-buffer) (kill-buffer))" + emacs --batch --eval "(progn (load \"$(basedir)/init-ipsur.el\") (ipsur-make-figures))" pkg: R CMD build pkg @@ -63,38 +59,36 @@ check: Rtangle: -mkdir $(Rdir) - emacs -Q --batch --eval "(progn (load \"~/$(basedir)/$(ipsurdir)/init-ipsur.el\") (R) (find-file \"~/$(basedir)/$(ipsurdir)/$(orgfile).org\") (org-babel-tangle) (kill-buffer))" + emacs --batch --eval "(progn (load \"$(basedir)/init-ipsur.el\") (R) (ipsur-init) (find-file \"$(basedir)/$(orgfile).org\") (org-babel-tangle) (kill-buffer))" web: @echo "Generating HTML..." - emacs -Q -batch -eval "(progn (load \"~/git/IPSUR/www/publish_config.el\") (org-publish \"ipsurweb\"))" + emacs --batch -eval "(progn (load \"$(basedir)/init-ipsur.el\") (ipsur-publish \"ipsurweb\"))" @echo "HTML generation done" -rm -r ~/.org-timestamps publish: @echo "Generating HTML..." - emacs -Q -batch -eval "(progn (load \"~/git/IPSUR/www/publish_config.el\") (org-publish \"ipsurweb\"))" + emacs --batch -eval "(progn (load \"$(basedir)/init-ipsur.el\") (ipsur-publish \"ipsurweb\"))" @echo "HTML generation done" -rm -r ~/.org-timestamps - cd ~/git/IPSURweb + cd $(basedir)/html git add -A git commit -m "publishing website" git push - cd ~/git/IPSUR + cd $(basedir)/ backup: -mkdir $(backdir) - cp $(texdir)/$(orgfile).pdf $(backdir)/$(orgfile).pdf + cp $(orgfile).pdf $(backdir)/$(orgfile).pdf clean: - -rm -r $(texdir) - -rm -r $(pdfdir) + -rm IPSUR.{aux,bbl,blg,brf,idx,ilg,ind,lof,log,lot,out,tex,toc} -rm -r IPSUR.Rcheck -rm -r ~/.org-timestamps distclean: - -rm -r $(texdir) - -rm -r $(pdfdir) + -rm IPSUR.{aux,bbl,blg,brf,idx,ilg,ind,lof,log,lot,out,pdf,tex,toc} -rm -r $(backdir) -rm -r $(Rdir) -rm -r IPSUR.Rcheck diff --git a/init-ipsur.el b/init-ipsur.el index 3bad3b9..2fddaac 100644 --- a/init-ipsur.el +++ b/init-ipsur.el @@ -1,94 +1,180 @@ -;; IPSUR: Introduction to Probability and Statistics Using R -;; Copyright (C) 2014 G. Jay Kerns +;;; init-ipsur.el --- IPSUR: Introduction to Probability and Statistics Using R ;; -;; This file is part of IPSUR. +;; Copyright (C) 2014 G. Jay Kerns ;; -;; IPSUR is free software: you can redistribute it and/or modify -;; it under the terms of the GNU General Public License as published by -;; the Free Software Foundation, either version 3 of the License, or -;; (at your option) any later version. +;; Author: Jay Kerns +;; Version: 2.0 +;; Keywords: textbook, statistics +;; Package-Requires: ((ess "15.03") (org "8.2.10"))) ;; -;; IPSUR is distributed in the hope that it will be useful, -;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;; GNU General Public License for more details. +;; This file is part of IPSUR. +;; +;; IPSUR is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. +;; +;; IPSUR is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. :: -;; You should have received a copy of the GNU General Public License -;; along with IPSUR. If not, see . - -(defvar org-dist "~/git/org-mode") -(add-to-list 'load-path (concat org-dist "/lisp")) -(add-to-list 'load-path (concat org-dist "/contrib/lisp")) +;; You should have received a copy of the GNU General Public License +;; along with IPSUR. If not, see . +;; +;;; Commentary: +;; +;; This file contains a function to export IPSUR.org to PDF, Tex, HTML, etc. +;; +;;; Code: -(setq load-path (cons "~/git/ESS/lisp" load-path)) (require 'ess-site) -(setq ess-ask-for-ess-directory nil) (require 'org) (require 'ox-latex) -(setq org-confirm-babel-evaluate nil) -(org-babel-do-load-languages - 'org-babel-load-languages - '((R . t) - (emacs-lisp . t) - (latex . t) - (org . t) - (sh . t))) -(setq org-entities-user nil) -(setq org-export-latex-packages-alist nil) -(setq ox-latex-classes nil) -(setq ox-latex-tables-booktabs nil) -(setq ox-latex-title-command nil) -(setq org-export-latex-hyperref-format "\\ref{%s}") -(setq org-latex-toc-command "\\tableofcontents\n\n") -(setq ox-latex-classes nil) -(add-to-list 'org-latex-classes - '("scrbook" - "\\documentclass{scrbook} + +(defvar ipsur-base-dir (file-name-directory load-file-name) "Base directory of IPSUR code.") + +(defun ipsur-init () + "Initialize needed variables for IPSUR." + (setq org-confirm-babel-evaluate nil) + (org-babel-do-load-languages + 'org-babel-load-languages + '((R . t) + (emacs-lisp . t) + (latex . t) + (org . t) + (sh . t))) + (setq org-entities-user nil) + (setq org-export-latex-packages-alist nil) + (setq ox-latex-classes nil) + (setq ox-latex-tables-booktabs nil) + (setq ox-latex-title-command nil) + (setq org-export-latex-hyperref-format "\\ref{%s}") + (setq org-latex-toc-command "\\tableofcontents\n\n") + (setq ox-latex-classes nil) + (add-to-list 'org-latex-classes + '("scrbook" + "\\documentclass{scrbook} [NO-DEFAULT-PACKAGES]" - ("\\chapter{%s}" . "\\chapter*{%s}") - ("\\section{%s}" . "\\section*{%s}") - ("\\subsection{%s}" . "\\subsection*{%s}") - ("\\subsubsection{%s}" . "\\subsubsection*{%s}") - ("\\paragraph{%s}" . "\\paragraph*{%s}"))) + ("\\chapter{%s}" . "\\chapter*{%s}") + ("\\section{%s}" . "\\section*{%s}") + ("\\subsection{%s}" . "\\subsection*{%s}") + ("\\subsubsection{%s}" . "\\subsubsection*{%s}") + ("\\paragraph{%s}" . "\\paragraph*{%s}"))) + + (setq org-publish-project-alist + `( + ("ipsurlatex-org" + :base-directory ,ipsur-base-dir + :base-extension "org" + :exclude "INSTALL.org" + :publishing-directory ,ipsur-base-dir + :publishing-function org-latex-publish-to-latex + :auto-sitemap nil + :makeindex nil) + + ("ipsurlatex-ps" + :base-directory ,(file-name-directory (concat ipsur-base-dir "fig")) + :base-extension "ps" + :recursive t + :publishing-directory ,(file-name-directory (concat ipsur-base-dir "fig")) + :publishing-function org-publish-attachment) + + ("ipsurlatex-pdf" + :base-directory ,(file-name-directory (concat ipsur-base-dir "fig")) + :base-extension "pdf" + :recursive t + :publishing-directory ,(file-name-directory (concat ipsur-base-dir "fig")) + :publishing-function org-publish-attachment) + + ("ipsurlatex-tex" + :base-directory ,(file-name-directory (concat ipsur-base-dir "include")) + :base-extension "tex" + :publishing-directory ,(file-name-directory (concat ipsur-base-dir "include")) + :publishing-function org-publish-attachment) + + ("ipsurlatex-other" + :base-directory ,(file-name-directory (concat ipsur-base-dir "include")) + :base-extension "bib" + :publishing-directory ,(file-name-directory (concat ipsur-base-dir "include")) + :publishing-function org-publish-attachment) + + ("ipsurlatex" :components ("ipsurlatex-org" "ipsurlatex-tex" "ipsurlatex-pdf" "ipsurlatex-other" "ipsurlatex-ps")) + + ("ipsurweb-notes" + :base-directory ,(file-name-directory (concat ipsur-base-dir "www")) + :base-extension "org" + :publishing-directory ,(file-name-directory (concat ipsur-base-dir "html")) + :recursive t + :publishing-function org-html-publish-to-html + :headline-levels 4 ; Just the default for this project. + :auto-preamble t + :section-numbers nil + :headline-levels 3 + :table-of-contents nil + :html-doctype "html5" + :html-head "" + :html-head-include-default-style nil) + + ;; These are static files (images, pdf, etc) + ("ipsurweb-static" + :base-directory ,(file-name-directory (concat ipsur-base-dir "www")) + :base-extension "css\\|R\\|RData\\|js\\|png\\|jpg\\|ico\\|gif\\|pdf\\|mp3\\|ogg\\|swf\\|txt\\|asc" + :publishing-directory (file-name-directory (concat ipsur-base-dir "html")) + :recursive t + :publishing-function org-publish-attachment) + + ("ipsurweb" :components ("ipsurweb-notes" "ipsurweb-static"))))) + +(defmacro with-org-and-R (&rest body) + "Macro to set-up R and org-file before executing BODY." + `(let ((R-p (get-buffer "*R*")) + (org-p (get-file-buffer (concat ipsur-base-dir "IPSUR.org")))) + (when (not R-p) + (setq ess-ask-for-ess-directory nil) + (R) + (set-process-query-on-exit-flag (get-process "R") nil)) + (find-file (concat ipsur-base-dir "IPSUR.org")) + (ipsur-init) + ,@body + (when (not org-p) + (kill-buffer)) + (when (not R-p) + (kill-buffer (get-buffer "*R*"))))) + +(defun ipsur-make-figures () + "Create figures for IPSUR textbook." + (interactive) + (with-org-and-R + (org-babel-execute-buffer) + (save-buffer))) + +(defun ipsur-publish (project) + "Export IPSUR to a format determined by PROJECT." + (interactive) + (with-org-and-R + (org-publish project))) -(setq org-publish-project-alist - '( - ("ipsurlatex-org" - :base-directory "~/git/IPSUR/" - :base-extension "org" - :exclude "INSTALL.org" - :publishing-directory "~/git/IPSUR/tex" - :publishing-function org-latex-publish-to-latex - :auto-sitemap nil - :makeindex nil - ) - - ("ipsurlatex-ps" - :base-directory "~/git/IPSUR/fig/" - :base-extension "ps" - :recursive t - :publishing-directory "~/git/IPSUR/tex/fig" - :publishing-function org-publish-attachment) +(defun ipsur-publish-pdf () + "Create PDF for IPSUR textbook." + (interactive) + (when (not (file-exists-p (concat ipsur-base-dir "IPSUR.tex"))) + (ipsur-publish "ipsurlatex")) + (mapc #'shell-command (list "xelatex --interaction=nonstopmode IPSUR.tex" + "bibtex IPSUR" + "makeindex IPSUR" + "xelatex --interaction=nonstopmode IPSUR.tex")) + (mapc #'(lambda (f) + (delete-file (concat ipsur-base-dir f))) + (list "IPSUR.aux" "IPSUR.bbl" "IPSUR.blg" "IPSUR.brf" "IPSUR.idx" "IPSUR.ilg" "IPSUR.ind" + "IPSUR.lof" "IPSUR.log" "IPSUR.lot" "IPSUR.out" "IPSUR.tex" "IPSUR.toc"))) - ("ipsurlatex-pdf" - :base-directory "~/git/IPSUR/fig/" - :base-extension "pdf" - :recursive t - :publishing-directory "~/git/IPSUR/tex/fig" - :publishing-function org-publish-attachment) +(defun ipsur-tangle () + "Generate R files for IPSUR textbook." + (interactive) + (with-org-and-R + (org-babel-tangle))) - ("ipsurlatex-tex" - :base-directory "~/git/IPSUR/include/" - :base-extension "tex" - :publishing-directory "~/git/IPSUR/tex/include" - :publishing-function org-publish-attachment) - - ("ipsurlatex-other" - :base-directory "~/git/IPSUR/include/" - :base-extension "bib" - :publishing-directory "~/git/IPSUR/tex/include" - :publishing-function org-publish-attachment) - - ("ipsurlatex" :components ("ipsurlatex-org" "ipsurlatex-tex" "ipsurlatex-pdf" "ipsurlatex-other" "ipsurlatex-ps")) - )) +(provide 'init-ipsur) +;;; init-ipsur.el ends here