From 75b2eec10274d26447e0e49f2dc63b7d6ecda2de Mon Sep 17 00:00:00 2001 From: Gerard Vermeulen Date: Sun, 9 Jan 2022 19:20:15 +0100 Subject: [PATCH] Clean up the implementation of the org-mode kbd macro --- README.org | 50 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/README.org b/README.org index 93ddc6d..a59478a 100644 --- a/README.org +++ b/README.org @@ -885,7 +885,7 @@ in listing [[lst:configure-tex]] corrects this by advising to override :END: The code in listing [[lst:customize-org-babel]], [[lst:customize-org]], and -[[lst:customize-org-export]] does basic customization of [[https://orgmode.org/][Org Mode]] variables. +[[lst:customize-org-export]] does basic customization of [[https://orgmode.org/][Org mode]] variables. #+caption[Customize =org-babel=]: #+caption: Customize =org-babel=. @@ -987,7 +987,7 @@ The code in listing [[lst:customize-org-babel]], [[lst:customize-org]], and (diff "diff") (shell-script "bash") (caml "ocaml") - (org "latex"))) + (org "text"))) '(org-latex-minted-options '(("bgcolor" "LightGoldenrodYellow"))) `(org-latex-logfiles-extensions ',(cl-union '("lof" "lot") org-latex-logfiles-extensions :test #'equal)) @@ -1311,7 +1311,7 @@ Evaluation of the source block in listing [[lst:make-source-block-with-export-keyword-settings]] produces the source block that exports to listing [[lst:source-file-export-keyword-settings]] which shows the first six lines of this [[file:README.org]] file. The last two lines show that -[[file:setup-include.org][setup-include.org]] is argument for [[info:org#Export Settings][#+SETUPFILE:]] *and* [[info:org#Export Settings][#+INCLUDE:]]. +[[file:setup-include.org][setup-include.org]] is the argument for [[info:org#Export Settings][#+SETUPFILE:]] *and* [[info:org#Export Settings][#+INCLUDE:]]. #+caption[Make setup and include file export keyword settings source block]: #+caption: The shell script to make the source block containing the export @@ -1343,21 +1343,41 @@ first six lines of this [[file:README.org]] file. The last two lines show that #+end_src :end: -Listing [[lst:setup-include-export-keyword-settings]], [[lst:use-latex-header-1]], -[[lst:use-latex-header-2]], [[lst:use-latex-header-3]], and [[lst:use-latex-header-4]] -tangle into the [[file:setup-include.org][setup-include.org]] file. +Listing [[lst:setup-include-export-keyword-settings]] tangles into the +[[file:setup-include.org][setup-include.org]] file and listing [[lst:by-backend-kbd-org-macro]] defines +the tools for the [[https://orgmode.org/][Org mode]] =kbd= macro in [[file:setup-include.org][setup-include.org]]. #+caption[Setup and include file export keyword settings]: #+caption: Setup and include file export keyword settings. #+name: lst:setup-include-export-keyword-settings #+begin_src org ,#+babel: :cache no - ,#+macro: kbd (eval (by-backend (html (format "@@html:%s@@" (htmlize-protect-string $1))) (latex (format "@@latex:\\colorbox{PowderBlue}{\\texttt{%s}}@@" $1)))) + ,#+macro: kbd (eval (by-backend-kbd-org-macro $1)) ,#+property: header-args:emacs-lisp :exports code :results silent :tangle init.el ,#+property: header-args:org :tangle setup-include.org ,#+startup: content #+end_src +#+caption[Define the tools of the org-mode =kbd= macro]: +#+caption: Define the tools for the org-mode =kbd= macro. +#+name: lst:by-backend-kbd-org-macro +#+begin_src emacs-lisp + (with-eval-after-load 'ox + (autoload 'htmlize-protect-string "htmlize" nil t) + + (defmacro by-backend (&rest body) + `(cl-case org-export-current-backend ,@body)) + + (defun by-backend-kbd-org-macro (keys) + (by-backend + (html (format "@@html:%s@@" (htmlize-protect-string keys))) + (latex (format "@@latex:\\colorbox{PowderBlue}{\\texttt{%s}}@@" keys))))) +#+end_src + +Listing [[lst:use-latex-header-1]], [[lst:use-latex-header-2]], [[lst:use-latex-header-3]], +and [[lst:use-latex-header-4]] tangle into the [[file:setup-include.org][setup-include.org]] file in order to +create the [[https://www.latex-project.org/][LaTeX]] preamble. + #+caption[LaTeX preamble: language, lists and floats]: #+caption: LaTeX preamble: language, lists and floats. #+name: lst:use-latex-header-1 @@ -1610,25 +1630,15 @@ Listing [[lst:emacs-lisp-setup-call]] initializes the buffer local variables ,#+end_src #+end_src -#+caption[Specify export backend dependent header arguments]: -#+caption: Specify export backend dependent header arguments. -#+name: lst:header-arguments-by-backend -#+begin_src emacs-lisp - (with-eval-after-load 'ox - (defmacro by-backend (&rest body) - `(cl-case org-export-current-backend ,@body))) -#+end_src - This section updates the outdated [[https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-LaTeX.html#orgcc214c1][Worg: backend dependent execution]] example to Emacs-27.2 and Org-9.5.2. It shows how to export [[https://en.wikipedia.org/wiki/PGF/TikZ][PGF/TikZ]] images to: 1. [[https://en.wikipedia.org/wiki/PDF][PDF]] by embedding in [[https://www.latex-project.org/][LaTeX]]. 2. [[https://en.wikipedia.org/wiki/HTML][HTML]] by passing from [[https://www.latex-project.org/][LaTeX]] by [[https://en.wikipedia.org/wiki/PDF][PDF]] and to [[https://en.wikipedia.org/wiki/Scalable_Vector_Graphics][SVG]]. Listing [[lst:backend-dependent-execution-update]] tangles to [[file:worg-backend-dependent-execution-update.org][worg-backend-dependent-execution-update.org]] as either a standalone example or an -example for inclusion. Listing [[lst:header-arguments-by-backend]] tangles to the -=user-init-file= to make the convenience =by-backend= macro always available. -Finally, inclusion of [[file:worg-backend-dependent-execution-update.org][worg-backend-dependent-execution-update.org]] produces here -the figure with the nodes 1, 2, 3, and 4:\\ +example for inclusion. Finally, inclusion of +[[file:worg-backend-dependent-execution-update.org][worg-backend-dependent-execution-update.org]] produces here the figure with the +nodes 1, 2, 3, and 4:\\ #+include: worg-backend-dependent-execution-update.org How to include such figures as floats remains an open question.