summaryrefslogtreecommitdiff
path: root/mathsheet.org
diff options
context:
space:
mode:
Diffstat (limited to 'mathsheet.org')
-rw-r--r--mathsheet.org46
1 files changed, 40 insertions, 6 deletions
diff --git a/mathsheet.org b/mathsheet.org
index b971a77..c834a4c 100644
--- a/mathsheet.org
+++ b/mathsheet.org
@@ -89,6 +89,10 @@ Mathsheet allows for the following customizations:
- ~mathsheet-output-directory~ :: This is where worksheets should be
written. It defaults to your home directory. You'll probably want to
move it somewhere else.
+- ~dired-guess-shell-alist-user~ :: This is an existing variable that
+ comes with dired which can be used to configure which programs are
+ associated with various file types. When mathsheet tries to open the
+ new worksheet, this will determine which program is used.
*** Problem Templates
The worksheet is made of a set of math problems. Each problem is
defined by a template that lays out an equation or expression and
@@ -204,7 +208,7 @@ format.
;; Author: Ian Martins <ianxm@jhu.edu>
;; Keywords: tools, education, math
;; Homepage: https://gitlab.com/ianxm/mathsheet
- ;; Version: 1.2
+ ;; Version: 1.3
;; Package-Requires: ((peg "1.0")
;; (emacs "28.1"))
@@ -230,6 +234,8 @@ included in Emacs but we need to make sure they have been loaded.
(declare-function math-read-expr "calc-ext")
(declare-function calc-set-language "calc-lang")
+ (declare-function dired-do-shell-command "dired-aux")
+ (declare-function dired-guess-shell-command "dired-aux")
#+end_src
*** Variables
@@ -304,6 +310,10 @@ scope where the macro is called.
#+end_src
+In addition to these variables, we also use
+~dired-guess-shell-alist-user~ to determine which program to use to open
+the generated PDF file.
+
** UI Form
*** Form configuration
See details [[https://www.gnu.org/software/emacs/manual/html_mono/forms.html][here]].
@@ -506,15 +516,17 @@ This function is used to parse each problem row.
;; absolute path without extension
(fname (concat
(file-name-as-directory mathsheet-output-directory)
- (string-replace " " "-" (alist-get :name config)))))
+ (string-replace " " "-" (alist-get :name config))
+ ".pdf")))
(mathsheet--write-worksheet
fname
(alist-get :instr config)
problems
(alist-get :cols config))
- (message "Wrote %s problems to %s.pdf"
+ (message "Wrote %s problems to %s"
(alist-get :count config)
- fname))))
+ fname)
+ (mathsheet--open-worksheet fname))))
#+end_src
** Problem generation
*** Scan problem
@@ -1036,7 +1048,7 @@ of how each section is filled in is described below.
(let* ((default-directory mathsheet-output-directory)
(ret (shell-command-on-region
(point-min) (point-max)
- (format "groff -mm -e -Tpdf - > %s" (concat fname ".pdf")))))
+ (format "groff -mm -e -Tpdf - > %s" fname))))
(unless (eq ret 0)
(error "PDF generation failed")))))
#+end_src
@@ -1100,7 +1112,7 @@ fill-problems:
(unless (= index 0)
(insert ".NCOL\n"))
(dolist (row group)
- (message "convert to eqn %s -> %s" (car row) (mathsheet--convert-to-eqn (car row)))
+ ;; (message "convert to eqn %s -> %s" (car row) (mathsheet--convert-to-eqn (car row)))
(insert (format (if (nth 3 row)
".LI\n.EQ\n%s\n.EN\n.SP \\n[vs]p\n"
".LI\n.EQ\n%s =\n.EN\n\\l'5\\_'\n.SP \\n[vs]p\n")
@@ -1129,6 +1141,28 @@ fill-answers:
(if (< index (length problems)) "\n" "")))))
#+end_src
+*** Open new worksheet
+This opens the worksheet PDF file after it is written. This makes it
+easy to review and print.
+
+This uses ~dired-do-shell-command~ to open the file, and
+~dired-guess-shell-command~ to choose the program to use to open the
+file. The file should be a PDF so the program should be a PDF
+viewer. This can be configured for the local system using the variable
+~dired-guess-shell-alist-user~.
+
+#+begin_src elisp :results silent :noweb tangle :tangle mathsheet.el
+ (defun mathsheet--open-worksheet (fname)
+ "Open the worksheet FNAME.
+
+ FNAME is the file to open, probably a worksheet."
+ (dired-do-shell-command
+ (dired-guess-shell-command
+ (format "Open %s with " fname)
+ (list fname))
+ nil
+ (list fname)))
+#+end_src
** Convenience functions
*** Add key binding to form
This adds the keybinding to run the mathsheet generator from the