Define custom tag in org-mode

There are tags in org-mode, as in #+AUTHOR or #+LATEX - are they called tags? I would like to define my own tag, which calls a function for preprocessing the data, and then outputs it - if the export target is LaTeX.

+6
source share
2 answers

My solution was to define my own qtree language for SRC blocks.

 #+BEGIN_SRC qtree [.CP [.TP [.NP [] [.N' [.N Syntax] []]] [.VP [] [.V' [.V sucks] []]]]] #+END_SRC 

And process it accordingly. I even added qtree mode with paredit . And the landscape parameter if the trees grow. https://github.com/Tass/emacs-starter-kit/blob/master/vendor/assorted/org-babel-qtree.el

 (require 'org) (defun org-babel-execute:qtree (body params) "Reformat a block of lisp-edited tree to one tikz-qtree likes." (let (( tree (concat "\\begin{tikzpicture} \\tikzset{every tree node/.style={align=center, anchor=north}} \\Tree " (replace-regexp-in-string " \\_<\\w+\\_>" (lambda (x) (concat "\\\\\\\\" (substring x 1))) (replace-regexp-in-string (regexp-quote "]") " ]" ; qtree needs a space ; before every closing ; bracket. (replace-regexp-in-string (regexp-quote "[]") "[.{}]" body)) ; empty leaf ; nodes, see ; http://tex.stackexchange.com/questions/75915 ) ; For ; http://tex.stackexchange.com/questions/75217 "\n\\end{tikzpicture}" ))) (if (assoc :landscape params) (concat "\\begin{landscape}\n" tree "\n\\end{landscape}") tree))) (setq org-babel-default-header-args:qtree '((:results . "latex") (:exports . "results"))) (add-to-list 'org-src-lang-modes '("qtree" . qtree)) (define-generic-mode 'qtree-mode ;; name of the mode to create '("%") ;; comments start with '%' '() ;; no keywords '(("[." . 'font-lock-operator) ;; some operators ("]" . 'font-lock-operator)) '() ;; files for which to activate this mode '(paredit-mode) ;; other functions to call "A mode for qtree edits" ;; doc string for this mode ) 
+5
source

It seems that they are called keywords for settings in the buffer . Whatever they call, they do not seem user-defined.

What you want to do is extremely related to the common way of processing, whereas for export with xelatex or pdflatex as described in Worg .

The relevant part will be:

 ;; Originally taken from Bruno Tavernier: http://thread.gmane.org/gmane.emacs.orgmode/31150/focus=31432 (defun my-auto-tex-cmd () (if (string-match "YOUR_TAG: value1" (buffer-string)) (do something)) (if (string-match "YOUR_TAG: value2" (buffer-string)) (do something else)) (add-hook 'org-export-latex-after-initial-vars-hook 'my-auto-tex-cmd) 
+4
source

Source: https://habr.com/ru/post/927286/


All Articles