branch: externals/org-mathsheet
commit 8c6b1e9cce5c91cbba7e1b04feeffcf92e7e4667
Author: Ian Martins <ia...@jhu.edu>
Commit: Ian Martins <ia...@jhu.edu>

    Add instruction and use template name for worksheet
---
 example.org   | 43 ++++++++++++++++++++++++++++++++++---------
 mathsheet.org | 25 +++++++++++++++++--------
 2 files changed, 51 insertions(+), 17 deletions(-)

diff --git a/example.org b/example.org
index aec3af0dbb..728cdeaa43 100644
--- a/example.org
+++ b/example.org
@@ -18,23 +18,48 @@
 |      1 |     4 | [a=1..10] + [0..10] - [0..$a] | three with subtraction, 
positive result |
 |      0 |     0 | [$a*[1..5]] / [a=1..10]       | division                    
            |
 
+#+BEGIN: problem-set :templates "add-sub-1" :count 21 :instruction "Compute 
the answer"
+| problem | answer |
+|---------+--------|
+| 6 + 3   |      9 |
+| 1 + 6   |      7 |
+| 5 + 6   |     11 |
+| 2 + 0   |      2 |
+| 1 + 4   |      5 |
+| 8 + 7   |     15 |
+| 6 + 5   |     11 |
+| 2 + 3   |      5 |
+| 9 + 9   |     18 |
+| 3 + 8   |     11 |
+| 1 + 11  |     12 |
+| 4 + 2   |      6 |
+| 2 + 9   |     11 |
+| 1 + 4   |      5 |
+| 11 + 1  |     12 |
+| 6 + 0   |      6 |
+| 4 + 9   |     13 |
+| 7 + 10  |     17 |
+| 3 - 1   |      2 |
+| 9 - 8   |      1 |
+| 2 - 1   |      1 |
+#+END:
+
+* algebra
 #+name: algebra-1
 | weight | order | template                           | descr  |
 |--------+-------+------------------------------------+--------|
 |      3 |     1 | x / ([2..4] + [a=0..5]) = [$a..10] | simple |
 |      3 |     2 | [$a*[2..10]] / x = [a=1,2,4]       | simple |
 
-#+BEGIN: problem-set :templates "algebra-1" :count 8
+#+BEGIN: problem-set :templates "algebra-1" :count 8 :instruction "Solve for x"
 | problem         | answer |
 |-----------------+--------|
-| x / (2 + 2) = 2 | x = 8  |
-| x / (2 + 0) = 8 | x = 16 |
 | x / (3 + 1) = 1 | x = 4  |
-| x / (3 + 4) = 7 | x = 49 |
+| x / (3 + 0) = 5 | x = 15 |
+| x / (2 + 4) = 5 | x = 30 |
+| x / (2 + 1) = 6 | x = 18 |
+| 16 / x = 2      | x = 8  |
 | 2 / x = 1       | x = 2  |
-| 7 / x = 1       | x = 7  |
-| 10 / x = 2      | x = 5  |
-| 28 / x = 4      | x = 7  |
+| 9 / x = 1       | x = 9  |
+| 8 / x = 4       | x = 2  |
 #+END:
-
-* bigger addition and multiplications
diff --git a/mathsheet.org b/mathsheet.org
index 386147c5b2..727252fd4b 100644
--- a/mathsheet.org
+++ b/mathsheet.org
@@ -475,6 +475,8 @@ I need to extract the values
       ;; should we generate the sheet?
       (when (y-or-n-p "Write worksheet? ")
         (ianxm/gen-worksheet
+         (plist-get params :templates)
+         (plist-get params :instruction)
          problems))))
 #+end_src
 
@@ -505,10 +507,13 @@ solution for how to enumerate with circled numbers from 
[[https://latex.org/foru
   \rhead{\textmd{\textsf{Date: \today}}}
   \cfoot{}
 
-  \renewcommand{\familydefault}{\ttdefault}
 
   \begin{document}
 
+  \noindent\textbf{<<instruction>>}
+  \vspace{.2cm}
+  \renewcommand{\familydefault}{\ttdefault}
+
     \begin{multicols}{2}
       \begin{enumerate}[itemsep=0.5cm]
         <<problems>>
@@ -542,13 +547,16 @@ convert it to a pdf. We save it as ~worksheet.tex~ and 
the final
 worksheet is named ~worksheet.pdf~. Each execution will overwrite the
 same file.
 
-**** TODO get the base filename from the org buffer
-
-
 #+begin_src elisp :results silent :tangle mathsheet.el
-  (defun ianxm/gen-worksheet (problems)
-    (with-temp-file "worksheet.tex"
+  (defun ianxm/gen-worksheet (template-name instruction problems)
+    (with-temp-file (concat template-name ".tex")
       (insert ianxm/worksheet-template)
+
+      (goto-char (point-min))
+      (search-forward "<<instruction>>")
+      (replace-match "")
+      (insert instruction)
+
       (goto-char (point-min))
       (search-forward "<<problems>>")
       (replace-match "")
@@ -558,12 +566,13 @@ same file.
                        (car row)))
           (insert (format"\\CircledItem %s = 
\\rule[-.2\\baselineskip]{2cm}{0.4pt}\n"
                          (car row)))))
+
       (goto-char (point-min))
       (search-forward "<<answers>>")
       (replace-match "")
       (dolist (row problems)
-        (insert (format "\\CircledItem %s\n\n"
+        (insert (format "\\CircledItem %s\n"
                         (cadr row)))))
-    (shell-command "texi2pdf worksheet.tex"
+    (shell-command (concat "texi2pdf " template-name ".tex")
                    (get-buffer-create "*Standard output*")))
 #+end_src

Reply via email to