# Understanding Emacs macro and org mode tikz behavior

I found this discussion, and the last response gives this code:

#+TITLE: Test
#+AUTHOR: Blah
#+LATEX_CLASS: article
#+LATEX_CLASS_OPTIONS: [american]
#
# Setup tikz package for both LaTeX and HTML export:
#

* One Diamond

#+name: diamond
#+header: :file (by-backend (latex "diamond.tikz") (t "diamond.svg"))
#+begin_src latex :results raw file
\begin{tikzpicture}
\draw (1,0) -- (0,1) -- (-1,0) -- (0,-1) -- cycle;
% \node at (0,0) {$$x_i$$};
\end{tikzpicture}
#+end_src

#+caption: A diamond.
#+attr_latex: :float t :width ""
#+results: diamond

* COMMENT setup

#+name: setup
#+begin_src emacs-lisp :results silent :exports none
;; (setq org-babel-latex-htlatex "htlatex")
(defmacro by-backend (&rest body)
(case (if (boundp 'backend) (org-export-backend-name backend) nil) ,@body))
#+end_src

# Local variables:
# eval: (org-sbe "setup")
# End:


First, the local variable call to elisp block setup doesn't seem to work. But then I don't really understand what by-backend is doing. Where can I learn about such a macro and why is it used in this situation? Also, why is so much placed in the org-mode header, i.e., what exactly are these doing?

#+LATEX_CLASS: article
#+LATEX_CLASS_OPTIONS: [american]
#
# Setup tikz package for both LaTeX and HTML export:

\documentclass[tikz, margin=3mm]{standalone}

• I don't know which version of org-mode above code was written for: by-backend is seemingly used for swiching the export behaviour according to chosen backends (latex vs. html e.g.). in org-mode 9 such a functionality is provided by org-export-current-backend. – Dieter.Wilhelm Jan 1 '17 at 20:09
• #+LATEX_CLASS: will invoke an Org template named "article", this template defines documentclass and some other headers. #+LATEX_CLASS_OPTIONS: will populate the part of the template related to documentclass. #+LATEX_HEADER: will also populate the same template, but will insert any LaTeX code before documentclass and \begin{document}. You don't have to use tikz` document class (unless your entire work is in tikz, in which case you don't really need Org). – wvxvw Jan 2 '17 at 5:58