I have a simple template in emacs .org mode . \begin{flushright} Name :

Phone no:

Billed amount:

Date \end {flushright} • Details .........

I export the document to pdf and print it. I create multiple such documents in a day. I want to capture the information to table as below for final accounting with a single key stroke | name| billed amount| . Note I don’t want to parse multiple files in one go but do this for one file at a time.

Is it possible?

  • How do you get the phone number? – NickD Aug 1 at 21:11
  • Manual entry on template. I just want to avoid duplicating work. – Vaibhav Aug 2 at 2:03
up vote 1 down vote accepted

Here's a bare-bones implementation. It uses a template file in the current directory called template.org and substitutes name, phone, amount into placeholders in the template (%NAME%, %PHONE%, %AMOUNT% resp.) It then saves the resulting org-mode file in /tmp/munged-name.org where the munged-name is just the name variable with spaces replaced by dashes. It then runs the org-latex-export-to-pdf function to process the file to PDF (in /tmp/munged-name.pdf). The function is bound to F10 z (i.e. function key F10 followed by letter z) although you can bind it to whatever you want - see the code for details.

The lisp code:

(defun fill-template-and-export (name phone amt)
  (interactive "sName: \nsPhone: \nsAmount: ")
  (with-temp-buffer
    (insert-file-contents "template.org")
    (save-excursion
       (while (re-search-forward "%NAME%" nil t)
         (replace-match name)))
    (save-excursion
       (while (re-search-forward "%PHONE%" nil t)
         (replace-match phone)))
    (while (re-search-forward "%AMOUNT%" nil t)
      (replace-match amt))
    (write-file (format "/tmp/%s.org" (replace-regexp-in-string " " "-" name)))
    (org-latex-export-to-pdf)))

;;; define the function key F10 as a prefix key
(setq f10-keymap (make-sparse-keymap))
(define-key global-map [f10] f10-keymap)

;;; F10 z calls the function above
(define-key f10-keymap "z" 'fill-template-and-export)

The template file:

 #+OPTIONS: toc:nil num:nil
 #+LATEX_HEADER: \setlength{\parindent}{0pt}

 * Invoice

 \begin{flushright}
 Name: %NAME%\\

 Phone: %PHONE%\\

 Amount: %AMOUNT%\\
 \end{flushright}

 Dear Sir/Madam:

 We would appreciate your immediate attention to this invoice.

 Sincerely,
 \vspace{2cm}

 A.U. Thor

You can of course tweak it if you don't like the design decisions I made.

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.