;;; my-org-article.el --- Summary  -*- lexical-binding: t -*-

;;; Commentary:
;; LaTeX and HTML export

;; EXAMPLE:
;; # -*- ispell-local-dictionary: "german" -*-
;; #+LANGUAGE: en
;; #+TITLE: Emacs
;; #+SUBTITLE:
;; #+AUTHOR: Daniel Weschke
;; #+EMAIL: daniel.weschke@directbox.de
;; #+DATE: 25. November 2019
;; #+KEYWORDS:
;; #+DESCRIPTION:
;; * Header   :ignore:

;;; Code:
(require 'ob-latex)
(require 'ob-gnuplot)
(require 'ox-latex)
(require 'ox-tufte)

;;(setq org-babel-latex-htlatex "htlualatex")
;;(setq org-babel-latex-htlatex "htlatex")
;; (executable-find org-babel-latex-htlatex)


;; Babel latex and gnuplot
;; PROPERTY src block header arguments https://orgmode.org/manual/Property-Syntax.html
;; https://orgmode.org/manual/Using-Header-Arguments.html
;; on src block C-c C-v I - org-babel-view-src-block-info this will eval as org backend
;; LaTeX
(setq org-babel-default-header-args:latex
      `((:results . "latex")
        (:exports . "results")
        (:prologue . (lambda ()
                       (concat (by-backend
                                (latex gnuplot-init-light)
                                (article-latex gnuplot-init-light)
                                (t gnuplot-init-dark)))))
        (:headers . (lambda ()
                    (if (org-export-derived-backend-p org-export-current-backend 'latex)
                        ""
                      "
\\usepackage{xcolor}
\\definecolor{color0}{HTML}{ffffff}
\\definecolor{color1}{HTML}{0071bc}
\\usepackage{pgfplots}
\\usepgflibrary{shapes.geometric}
\\usetikzlibrary{
  arrows.meta,
  arrows,
  calc,
  positioning,
  shapes.multipart,
  decorations.pathmorphing,
  backgrounds,
  pgfplotsclickable,
  shadows,
  shadows.blur,
  mindmap,
}
\\tikzset{every path/.style={color=white}}
\\makeatletter
\\tikzset{clip/.code={\\let\\tikz@mode=\\pgfutil@empty\\let\\tikz@preactions=\\pgfutil@empty\\let\\tikz@postactions=\\pgfutil@empty\\let\\tikz@options=\\pgfutil@empty\\tikz@addmode{\\tikz@mode@cliptrue}},}
\\makeatother")))
        (:packages . "\\usepackage{xcolor}
\\definecolor{color0}{HTML}{ffffff}
\\definecolor{color1}{HTML}{0071bc}
\\usepackage{svg}
\\usepackage{tikz}
\\usepackage{pgfplots}
\\pgfplotsset{compat=newest, axis line style={white}, every axis label/.append style ={white}, every tick label/.append style={white},color0/.style={color=white}}"
                   )))
;; Gnuplot
(setq org-babel-default-header-args:gnuplot
      `((:results . "file")
        (:exports . "results")
        (:session)
        (:prologue . (lambda ()
                       (concat (by-backend
                                (latex gnuplot-init-light)
                                (article-latex gnuplot-init-light)
                                (t gnuplot-init-dark)))))))

;; MACRO https://orgmode.org/manual/Macro-Replacement.html
(add-to-list
 'org-export-global-macros
 '("kbd" . "@@html:<kbd>$1</kbd>@@"))
(add-to-list
 'org-export-global-macros
 '("color" . "@@html:<font color=\"#$1\">$2</font>@@@@latex:\\textcolor[HTML]{$1}{$2}@@"))
;; ACRONYM
(add-to-list
 'org-export-global-macros
 '("ac" . "@@html:$1@@@@latex:\ac{$1}@@"))
(add-to-list
 'org-export-global-macros
 '("acf" . "@@html:$1@@@@latex:\acf{$1}@@"))
;; QUOTATION
;;; quotation mark (auto language, html using main language)
(add-to-list
 'org-export-global-macros
 '("enquote" . "@@html:“$1”@@@@latex:\enquote{$1}@@"))
;;; german quotation (glqq: german left quote quote, grqq ...)
(add-to-list
 'org-export-global-macros
 '("gq" . "@@html:„$1“@@@@latex:\\glqq{}$1\\grqq{}@@"))
;;; french quotation (flqq: french left quote quote, frqq ...)
(add-to-list
 'org-export-global-macros
 '("fq" . "@@html:«$1»@@@@latex:\flqq{}$1\frqq{}@@"))
;; FONT
(add-to-list
 'org-export-global-macros
 '("textsc" . "@@html:<span style=\"font-variant-caps: small-caps;\">$1</span>@@@@latex:\\textsc{$1}@@"))
(add-to-list
 'org-export-global-macros
 '("ruby" . "@@html:<ruby>$1<rp>(</rp><rt>$2</rt><rp>)</rp></ruby>@@@@latex:\\ruby{$1}{$2}@@"))

;; LaTeX
;;; Function Declarations
(defvar my-org-article-export-headline-levels)
(defvar my-org-article-export-with-sub-superscripts)
(defvar my-org-article-export-with-toc)
(defvar my-org-article-latex-default-packages-alist)
(defvar my-org-article-latex-packages-alist)
(defvar my-org-article-latex-compiler)
(defvar my-org-article-latex-default-class)
(defvar my-org-article-latex-default-class-options)
(defvar my-org-article-latex-header)
(defvar my-org-article-latex-header-extra)
(defvar my-org-article-latex-opening)
(defvar my-org-article-latex-closing)
(defvar my-org-article-latex-references)

(defcustom my-org-article-latex-references "" "")

(org-export-define-derived-backend 'article-latex 'latex

  :menu-entry
  '(?l ?a
       (
        ;;(?A "As LaTeX buffer" my-org-article-latex-export-as-latex)
	      ;;(?a "As LaTeX file" my-org-article-latex-export-to-latex)
	      (?a "As PDF-article file" my-org-article-latex-export-to-pdf)
	      (?A "As PDF-article and open"
	          (lambda (a s v b)
	            (if a (my-org-article-latex-export-to-pdf t s v b)
		            (org-open-file (my-org-article-latex-export-to-pdf nil s v b)))))))

  :options-alist
  '((:headline-levels nil "H" my-org-article-export-headline-levels)
    (:with-sub-superscript nil "^" my-org-article-export-with-sub-superscripts)
    (:with-toc nil "toc" my-org-article-export-with-toc)
    (:latex-class "LATEX_CLASS" nil my-org-article-latex-default-class t)
    (:latex-class-options "LATEX_CLASS_OPTIONS" nil my-org-article-latex-default-class-options t)
    (:latex-header "LATEX_HEADER" nil my-org-article-latex-header newline)
    (:latex-header-extra "LATEX_HEADER_EXTRA" nil my-org-article-latex-header-extra newline)
    (:latex-compiler "LATEX_COMPILER" nil my-org-article-latex-compiler t)
    (:article-closing "CLOSING" nil my-org-article-latex-closing newline)
    (:article-opening "OPENING" nil my-org-article-latex-opening newline)
    (:article-references "REFERENCES" nil my-org-article-latex-references newline))

  :translate-alist
  '((template . my-org-article-latex-template)))


;;; User Configurable Variables

(defgroup my-org-export-article nil
  "Options for exporting Org mode files."
  :tag "Org Export"
  :group 'org)

(defcustom my-org-article-export-headline-levels 5
  "See `org-export-headline-levels'."
  :group 'my-org-export-article
  :type 'integer
  :safe #'integerp)

(defcustom my-org-article-export-with-sub-superscripts "{}"
  "See `org-export-with-sub-superscripts'."
  :group 'my-org-export-article
  :version "24.4"
  :package-version '(Org . "8.0")
  :type '(choice
	  (const :tag "Interpret them" t)
	  (const :tag "Curly brackets only" {})
	  (const :tag "Do not interpret them" nil))
  :safe (lambda (x) (memq x '(t nil {}))))

(defcustom my-org-article-export-with-toc nil
  "See `org-export-with-toc'."
  :group 'my-org-export-article
  :type '(choice
	  (const :tag "No Table of Contents" nil)
	  (const :tag "Full Table of Contents" t)
	  (integer :tag "TOC to level"))
  :safe (lambda (x)
	  (or (booleanp x)
	      (integerp x))))

;;;; Compilation

(defcustom my-org-article-latex-compiler "lualatex"
  "See `org-latex-compiler'."
  :group 'my-org-export-article
  :type '(choice
	  (const :tag "pdfLaTeX" "pdflatex")
	  (const :tag "XeLaTeX"  "xelatex")
	  (const :tag "LuaLaTeX" "lualatex")
	  (const :tag "Unset" ""))
  :version "26.1"
  :package-version '(Org . "9.0"))

;;;; Preamble

(defcustom my-org-article-latex-default-class "koma-article"
  "The default LaTeX class."
  :group 'my-org-export-article
  :type '(string :tag "LaTeX class"))

(defvar my-org-article-latex-header-biblatex
  "
%\\usepackage[fixlanguage]{babelbib}   % Mehrsprachige Literaturliste, nicht mit biblatex
%\\selectbiblanguage{german}
\\usepackage[
   %bibstyle=chem-acs,
   style=numeric-comp,     % alphabetic, numeric-comp, authoryear-icomp, authortitle-icomp
   sorting=none,           % name, title, year, none
   %abbreviate=false,      % keine Abkürzungen
   %sortcites=true,        % sorted according to the global sorting order
   %sortgiveninits=true,   % sorting names will only use their initials
   %block=nbpar,           % none, space, par, nbpar, ragged
   autocite=footnote,      % citations as footnotes
   uniquename=init,        % set true if giveninits is set to true
   giveninits=true,        % all first and middle names will be rendered as initials
   isbn=false,
   maxnames=2,
   backend=biber,          % backend=bibtex8 by latin1, biber by utf8
   safeinputenc,           % erlaubt Zeichen aus dem tipa-Paket (Biber only)
]{biblatex}

% Erst Nachname, dann Vorname
\\DeclareNameAlias{default}{family-given}


% Autorennamen in Kapitälchen
\\renewcommand*{\\mkbibnamelast}[1]{\\textsc{#1}}

% muss ich noch nachvollziehen, nur dick?
\\renewbibmacro*{author/editor+others/translator+others}{%
  %\\mkbibbold{% ADDED
  \\ifboolexpr{
    test \\ifuseauthor%
    and
    not test {\\ifnameundef{author}}
  }
  {\\usebibmacro{author}}
  {\\ifboolexpr{
    test \\ifuseeditor%
    and
    not test {\\ifnameundef{editor}}
  }
  {\\usebibmacro{editor+others}}
  {\\usebibmacro{translator+others}}}
  %}% ADDED
  }

  % Trennen mit Semikolon, bei mehreren Autoren
  \\renewcommand*{\\multinamedelim}{\\addsemicolon\\space}
  \\renewcommand*{\\finalnamedelim}{\\addsemicolon\\space}

  %  :  als Trennzeichen nach Titel
  %\\DeclareFieldFormat{title}{\\mkbibemph{#1}~:\\addspace}
\\renewbibmacro*{title}{%
  \\ifthenelse{\\iffieldundef{title}\\AND\\iffieldundef{subtitle}}
    {}
    {\\printtext[title]{%
      \\printfield[titlecase]{title}}%
     %\\setunit{\\subtitlepunct}% DELETE
      \\setunit{~:\\addspace}%
% DELETE and close in title
     %\\printfield[titlecase]{subtitle}}
% ADD
     \\printfield{subtitle}
     \\newunit}%
  \\printfield{titleaddon}}
% Änderung des Subtitles
\\DeclareFieldFormat{subtitle}{\\mkbibemph{#1}}

%  :  als Trennzeichen zwischen Ort und Verlag
\\renewbibmacro*{publisher+location+date}{%
  \\printlist{location}%
  \\iflistundef{publisher}
    {\\setunit*{\\addcomma\\space}}
%    {\\setunit*{addcolon\\space}}% DELETED
    {\\setunit*{~:\\space}}% ADDED
  \\printlist{publisher}%
  \\setunit*{\\addcomma\\space}%
  \\usebibmacro{date}%
  \\newunit}

\\DeclareFieldFormat{edition}{%
  \\ifinteger{#1}
    {\\mkbibordedition{#1}~\\bibstring{edition}}% DELETED
%    {\\mkbibordedition{#1}\\bibstring{edition}}% ADDED
    {#1\\isdot}}

%Doppelpunkt statt Komma vor der Seitenangabe in der Zitierung, z.B. «(Gaukeley 2005: S. 387)»
\\renewcommand{\\postnotedelim}{\\addcolon\\addspace}

%Kein einleitendes «S.» vor der Seitenangabe in der Zitierung, z.B. «(Gaukeley 2005: 387)»
\\DeclareFieldFormat{postnote}{#1}

% Doppelpunkt statt Punkt vor dem Titel in der Literaturliste,
% z.B. «Gaukeley, Gundel (2005): Das kleine Einmaleins der Hexerei. [...]»
\\renewcommand{\\labelnamepunct}{\\addcolon\\addspace}

% Allfällige Angabe von Serie und Nummer in der Literaturliste eingeklammert und mit Gleichheitszeichen versehen,
% z.B. «[...] (= Schriftenreihe des Entenhausener Pfadfinderverbandes 13).»
\\renewbibmacro*{series+number}{%
  \\iffieldundef{series}
    {}
    {\\printtext[parens]{%
      \\iffieldundef{number}
        {}
        {=\\addhpthinspace}%
      \\printfield{series}%
      \\setunit*{\\addspace}%
      \\printfield{number}%
    }}\\newunit}

% Allfälliges Datum der Erstausgabe in der Literaturliste,
% z.B. «Duck, Tick u. a. (1966/2004): Ordens- und Abzeichenkunde für Fieselschweif‌linge. [...]»
%\\renewbibmacro*{date+extrayear}{
\\newbibmacro*{date+extrayear}{%
  \\iffieldundef{year}
    {}
    {\\printtext[parens]{%
      \\iffieldundef{origyear}
        {}
        {\\printfield{origyear}\\addslash}%
      \\printdateextra}}}

% Allfälliges Datum der Erstausgabe in Zitierungen, z.B. «(Duck u. a. 1966/2004: 37 f.)»
%\\renewbibmacro*{cite:labelyear+extrayear}{%
\\newbibmacro*{cite:labelyear+extrayear}{%
  \\iffieldundef{labelyear}
    {}
    {\\printtext[bibhyperref]{%
      \\iffieldundef{origyear}
        {}
        {\\printfield{origyear}\\addslash}%
      \\printfield{labelyear}%
      \\printfield{extrayear}}}}

% Hat es mehrere Werke derselben Person(en), den Strich durch eine entsprechende Abkürzung ersetzen (wie ders./dies.)
\\renewcommand*{\\bibnamedash}{%
      \\bibsentence\\bibstring{idem\\thefield{gender}}}
% Hat/haben die Person(en) eines der zusätzlichen Werke nur herausgegeben, vor der Abkürzung Komma und Leerschlag einfügen
% Erfordert Angabe des Geschlechts in .bib, gender={sf} sn, pp
%\\renewbibmacro*{bbx:editor}[1]{%
\\newbibmacro*{bbx:editor}[1]{%
  \\ifboolexpr{
    test \\ifuseeditor%
    and
    not test {\\ifnameundef{editor}}
  }
    {\\usebibmacro{bbx:dashcheck}
       {\\bibnamedash%
  \\setunit{\\addcomma\\space}}
       {\\printnames{editor}%
  \\setunit{\\addcomma\\space}%
  \\usebibmacro{bbx:savehash}}%
     \\usebibmacro{#1}%
     \\clearname{editor}%
     \\setunit{\\addspace}}%
    {\\global\\undef\\bbx@lasthash
     \\usebibmacro{labeltitle}%
     \\setunit*{\\addspace}}%
  \\usebibmacro{date+extrayear}}
\\addbibresource{references.bib}
"
  "Used in `my-org-article-latex-lang-template-plist'
points to references.bib")

(defvar my-org-article-latex-lang-template-plist
  (list
   :documentclass-en "english"
   :documentclass-de "ngerman"
   ;; FONTS
   :babel-en "\\usepackage[english]{babel}"
   :babel-de "\\usepackage[ngerman]{babel}"
   :fontspec-en ""
   :fontspec-ja "\\usepackage{luatexja-fontspec}  % add japanese support using lualatex compiler"
   :ruby-en ""
   :ruby-ja "\\usepackage[CJK,overlap]{ruby}  % support for FURIGANA - japanese"
   ;; REFERENCES
   :biblatex-en my-org-article-latex-header-biblatex
   :biblatex-de-rott ""
   :csquotes-en "\\usepackage[autostyle]{csquotes}"
   :csquotes-de "\\usepackage[autostyle,german=quotes]{csquotes}"
   ;; APPENDIX
   :mtcselectlanguage-en ""
   :mtcselectlanguage-de "\\mtcselectlanguage{german}"
   ;; LISTINGS
   :lstlistingname-en ""
   :lstlistingname-de "\\renewcommand{\\lstlistingname}{Programmausdruck}"
   )
  "
:documentclass-xx used in `my-org-article-latex-default-class-options'
all other in `my-org-article-latex-header'
template replacements in `my-org-article-latex-lang-template-value'
IMPORTANT en version must be defined")

(defcustom my-org-article-latex-default-class-options
  "[paper=a4,fontsize=11pt,DIV=12,BCOR=10mm,headsepline,<<documentclass>>,captions=tableheading,version=first,bibliography=totoc,dvipsnames]"
  "The default LaTeX class options.

`my-org-article-latex-lang-template-plist'"
  :group 'my-org-export-article
  :type '(string :tag "LaTeX class"))

(add-to-list 'org-latex-classes
             '("koma-article" "\\documentclass{scrartcl}"
               ("\\section{%s}" . "\\section*{%s}")
               ("\\subsection{%s}" . "\\subsection*{%s}")
               ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
               ("\\paragraph{%s}" . "\\paragraph*{%s}")
               ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))

(defcustom my-org-article-latex-header
  "
%%%
%%% ARTICLE
%%%
% provides \\isempty test
\\usepackage{xifthen}
%\\newcommand{\\optarg}[1][]{%
%  \\ifthenelse{\\isempty{#1}}%
%    {}% if #1 is empty
%    {(((#1)))}% if #1 is not empty
%}
\\makeatletter
\\newcommand{\\@scrartcl@loaded}{0}
\\AtBeginDocument{\\@ifpackageloaded{scrartcl}
  {\\renewcommand{\\@scrartcl@loaded}{1}}
  {\\renewcommand{\\@scrartcl@loaded}{0}}
}
\\makeatother

%%%
%%% COLORS
%%%
\\usepackage{xcolor}
\\usepackage{colortbl}
\\xdefinecolor{navyblue}{rgb}{0,0.35,0.62}
% links, \\everydisplay:
\\definecolor{darkblue}{rgb}{0,0.15,0.35}
\\definecolor{darkred}{rgb}{0.88,0.16,0.17}
\\definecolor{dkgreen}{rgb}{0,0.6,0}
\\definecolor{gray}{rgb}{0.5,0.5,0.5}
% listings:
\\definecolor{mauve}{rgb}{0.58,0,0.82}
\\definecolor{orange}{rgb}{0.8 0.4 0.2}
\\definecolor{dkorange}{rgb}{0.68 0.25 0.07}
\\definecolor{rouge}{rgb}{0.79 0.0 0.1}
\\definecolor{matlab1}{HTML}{0071BC}
\\definecolor{matlab2}{HTML}{D85218}
\\definecolor{matlab3}{HTML}{ECB01F}
\\definecolor{matlab4}{HTML}{7D2E8D}
\\definecolor{matlab5}{HTML}{76AB2F}
\\definecolor{matlab6}{HTML}{4CBDED}
\\definecolor{matlab7}{HTML}{A1132E}

%%%
%%% PAGE
%%%
\\newif\\iftwocol%
%\\twocoltrue
\\twocolfalse%

\\special{papersize=210mm,297mm}

% -----------------------------------------
%  Allgemeine Seiten-Abstände und Einstellungen
% -----------------------------------------
% Hälfte der Schriftgröße 12pt
\\setlength{\\parskip}{6pt}
% kein einrücken
\\setlength{\\parindent}{0pt}
\\setlength{\\textheight}{22.5cm}
%\\usepackage[a4paper, top=3cm, left=3.5cm, right=2.8cm]{geometry}
%\\setlength{\\marginparwidth}{1.5cm}    % Raum für Randnotiz
% Raum für Randnotiz
\\setlength{\\marginparwidth}{0pt}

% muss vor hyperref
\\usepackage{setspace}
% Zeilenabstand, \\doublespacing, \\singlespacing
\\onehalfspacing%

\\KOMAoptions{DIV=last}
% Nach ändern der Schriftart von KOMA-Script ganz bequem den Satzspiegel neu berechnen lassen.
\\recalctypearea%

%keine einzelnen Seiten eines Absatzes oben oder unten auf einer Seite
\\clubpenalty=10000
\\widowpenalty=10000
\\displaywidowpenalty=10000

% Fix overful hboxes automatically:
% allg., Stand. 200, defensiver 2000
%\\tolerance=2000
%10pt% im Fall, Stand. 0, besser als \\tolerance
\\emergencystretch=6pt
%\\hbadness=1000          % Warnungsausgabe, Stand. 1000
\\setlength{\\overfullrule}{5pt}

% global oder lokal Silbentrennung verbieten
%\\pretolerance=10000 % or/the same result? \\hyphenpenalty=10000

% Befehle:
%\\newline
%\\linebreak

% muss vor tocstyl
\\usepackage{pdfpages}
\\usepackage{pdflscape}

% Verzeichnis
% package tocstyle obsolete, possible supported packages like tocbasic or scrwfile
% https://tex.stackexchange.com/questions/565279/missing-tocstyle-sty-file
%\\usepackage{tocstyle}   % Obsolete, tocstyle
\\usepackage{tocbasic}
\\usepackage{scrwfile}
\\iftwocol%
  \\usepackage[toc]{multitoc}
  \\renewcommand*{\\multicolumntoc}{2}
  \\setlength{\\columnseprule}{0.5pt}
\\fi
%\\usetocstyle{allwithdot}   % Obsolete, tocstyle
\\usepackage{tocloft}
\\setlength{\\cftbeforefigskip}{0ex}
% first: pnumwidth, second: margin, default: 1.55em and 2.55em
\\cftlocalchange{toc}{2em}{2.55em}

%\\usepackage{bigfoot}  % footnote


% debug the box warnings
\\showboxdepth=\\maxdimen%
\\showboxbreadth=\\maxdimen%


% \\pdfminorversion=5 % to allow compression  ## LuaLatex does not understand this
% \\pdfobjcompresslevel=2                     ## LuaLatex does not understand this


\\usepackage{afterpage}
\\makeatletter
\\def\\mynobreakpar{\\par\\nobreak\\@afterheading}
\\def\\mynobreakline{\\par\\nobreak\\vspace{-\\parskip}\\@afterheading\\noindent}
\\makeatother
\\newenvironment{absolutelynopagebreak}
  {\\par\\nobreak\\vfil\\penalty0\\vfilneg%
   \\vtop\\bgroup}
  {\\par\\xdef\\tpd{\\the\\prevdepth}\\egroup%
   \\prevdepth=\\tpd}
%\\begin{absolutelynopagebreak}
%\\lipsum[1-3]\\lipsum*[4]
%\\end{absolutelynopagebreak}

%%%
%%% FONTS
%%%
% -----------------------------------------
%  Schrift
% -----------------------------------------
% Schöneres Schriftpacket für LateX
\\usepackage{lmodern}
% Dominanz hinten
<<babel>>
% \\usepackage[utf8]{inputenc} % latin1, utf8, ansinew, latin2
\\usepackage[utf8]{luainputenc}
\\usepackage[T1]{fontenc}
<<fontspec>>

\\DeclareUnicodeCharacter{2009}{\\,}  % convert unicode to latex command, thin-space

% bessere Schrifte
% sfmath,             % sans-serif slanted fonts
% slantedGreeks,      % Uppercase greeks are slanted
% do not load textcomp again
\\usepackage[notextcomp]{kpfonts}
\\usepackage[scale=0.95]{opensans}

% hyphenatable letterspacing, underlining and some derivatives such as overstriking and highlighting, soul
\\usepackage{soulutf8}
% \\so{letterspacing} l e t t e r s p a c i n g
% \\caps{CAPITALS, Small Capitals} like \\textsc{}
% \\ul{underlining}
% \\st{overstriking}
% \\hl{highlighting}

% Damit ich mir nicht immer neuen Text ausdenken muss
\\usepackage{blindtext}

% use: \\ce   IMPORTANT: mhchem must be load before sparse and/or xpatch: l3str: \\c_backslash_str
\\usepackage[version=3]{mhchem}
\\usepackage{xparse}

% Befehle:
% change family of the font. If possible other aspects – like the series or the shape – are preserved.
% \\textrm (\\rmfamily)       Normal font (default).
% \\textsf (\\sffamily)       Sans serif.
% \\texttt (\\ttfamily)       Typewriter.
% \\emph                     Emphasis (toggles between \\textit and \\textrm)

% \\textmd (\\mdseries)       Medium weight (default). The opposite of boldface.
% \\textbf (\\bfseries, \\bf)  Bold weight.

% \\textup (\\upshape)        Upright (default). The opposite of slanted.
% \\textit (\\itshape)        Italic.
% \\textsl (\\slshape)        Slanted.
% \\textsc (\\scshape)        Small caps.

% \\textnormal (\\normalfont) Main document font.

% \\tiny \\scriptsize \\footnotesize \\small
% \\normalsize (default)
% \\large \\Large \\LARGE \\huge \\Huge

%\\usepackage[normalem]{ulem}
% \\uline{...}   Underlined text, breaks over multiple lines
% \\uuline{...}  double-underlined text
% \\uwave{...}   wave-underlined text
% \\sout{...}    ------------
% \\xout{...}    //////////// 

% remap ulem command to soul: underline
%\\renewcommand{\\uline}[1]{\\ul{#1}}
% remap ulem command to soul: overstriking
% TODO uncomment?
\\renewcommand{\\sout}[1]{\\st{#1}}
<<ruby>>

%%%
%%% RUNNINGTITLE
%%%
% -----------------------------------------
%  Seitenstil für lebende Kolumnentitel
% -----------------------------------------
%\\pagestyle{headings}
\\usepackage{fancyhdr}
\\pagestyle{fancy}
\\fancyhead{}
\\fancyfoot{}
% for twoside option: LE,RO
\\fancyhead[RO]{\\slshape \\leftmark}%
\\fancyfoot[C]{--~\\thepage~--}
%\\fancyfoot[RO] {\\thepage}
\\renewcommand{\\headrulewidth}{0.4pt}
\\renewcommand{\\footrulewidth}{0pt}
\\newlength\\FHoffset%
% Offset des Headers 0: bündig mit text
\\setlength\\FHoffset{0cm}
\\addtolength\\headwidth{1\\FHoffset}
\\fancyheadoffset{\\FHoffset}
% these lengths will control the headrule trimming to the left and right
\\newlength\\FHleft%
\\newlength\\FHright%
% here the trimmings are controlled by the user
\\setlength\\FHleft{-1cm}
\\setlength\\FHright{-1cm}
% The new definition of headrule that will take into acount the trimming(s)
\\newbox\\FHline%
\\setbox\\FHline=\\hbox{\\hsize=\\paperwidth%
  \\hspace*{\\FHleft}%
  \\rule{\\dimexpr\\headwidth-\\FHleft-\\FHright\\relax}{\\headrulewidth}\\hspace*{\\FHright}%
}
\\renewcommand\\headrule{\\vskip-.7\\baselineskip\\copy\\FHline}

% keine Linien auf Bilderseiten!
\\renewcommand{\\headrulewidth}{\\iffloatpage{0pt}{0.4pt}}

\\renewcommand{\\sectionmark}[1]{
\\markboth{\\thesection{} #1}{\\thesection{} #1}
}
\\renewcommand{\\subsectionmark}[1]{
\\markright{\\thesubsection{} #1}
}

\\fancypagestyle{plain}{
\\fancyhead{}
\\fancyfoot{}
\\renewcommand{\\headrulewidth}{0.4pt}
\\fancyfoot[C]{--~\\thepage~--}
%\\fancyfoot[RO] {\\thepage}
}

% must be set between an header and text, direct before the first paragraph, and must be compiled at least twice
\\newcommand{\\sectionheader}{%
  \\thispagestyle{plain}%
  \\begin{tikzpicture}[remember picture, overlay]%
    \\node[shift={(0 cm,-2.8cm)}] at (current page.north west){%
      \\begin{tikzpicture}[remember picture, overlay]%
        \\node[shift={(2.8,0)},right] {\\TITLE\\ -- \\SUBTITLE};%
      \\end{tikzpicture}%
    };%
    \\node[shift={(0 cm,-2.8cm)}] at (current page.north east){%
      \\begin{tikzpicture}[remember picture, overlay]%
        \\node[shift={(-2.8,0)},left] {\\AUTHOR};%
      \\end{tikzpicture}%
    };%
  % Draw a page border
  % \\draw (current page.north west) rectangle (current page.south east);%
  \\end{tikzpicture}%
}

%%%
%%% REFERENCES
%%%
% -----------------------------------------
%  Literatur
% -----------------------------------------
<<biblatex>>

%babel,          % 'babel' depreciated - autostyle
<<csquotes>>

\\expandafter\\def\\expandafter\\quote\\expandafter{\\quote\\small} % Schriftverkleinerung in quote-Umgebung

% cite, key, page numbers
\\newcommand{\\zitat}[3]{
  \\begin{quote}\\small
    #1
    % \\psq: no suffixes/prefix
    \\hfill\\autocite[#3\\psq]{#2}
  \\end{quote}
}

%%%
%%% ACRONYMS
%%%
% -----------------------------------------
%  Listen: Aufzählende, Acronyms
% -----------------------------------------
\\setlength{\\leftmargini}{2\\parskip} % Listeneinzug
% how to use acronyms:
% \\ac = use acronym, first time write both, full name and acronym
% \\acf = use full name (text + acronym)
% \\acs = only use acronym
% \\acl = only use long text
% \\acp, acfp, acsp, aclp = use plural form for acronym (append 's')
% \\acsu, aclu = write + mark as used
% \\acfi = write full name in italics and acronym in normal style
% \\acused = mark acronym as used
% \\acfip = full, emphasized, plural, used
% \\iac and \\Iac = indefinite articles
\\usepackage[
   %footnote,       % die Langform als Fußnote ausgeben
   %nohyperlinks,   % wenn hyperref geladen ist, wird die Verlinkung unterbunden
   %printonlyused,  % nur Abkürzungen auflisten, die tatsächlich verwendet werden.
   %withpage,
   %smaller,        % Text soll kleiner erscheinen, das Paket relsize wird vorausgesetzt
   %dua,            % es wird immer die Langform ausgegeben
   %nolist,         % es wird keine Liste mit allen Abkürzungen ausgegeben
]{acronym}

\\renewcommand\\acsfont{\\normalfont}
\\makeatletter
\\def\\uplabel#1{{\\normalfont{\\textsf{#1}}\\hfill}}
\\renewenvironment{acronym}[1][1]{%
   \\singlespacing%
   \\setstretch{0.8}
   \\providecommand*{\\acro}{\\AC@acro}%
   \\providecommand*{\\acroplural}{\\AC@acroplural}%
   \\long\\def\\acroextra##1{##1}%
   \\def\\@tempa{1}\\def\\@tempb{#1}%
   \\ifx\\@tempa\\@tempb%
      \\global\\expandafter\\let\\csname ac@des@mark\\endcsname\\AC@used%
      \\ifAC@nolist%
      \\else%
         \\begin{list}{}%
% change according to your needs , 4.45
                {\\settowidth{\\labelwidth}{\\normalfont{\\textsf{#1}}\\hspace*{3.5em}}%
                \\setlength{\\leftmargin}{\\labelwidth+\\parskip}%
                \\addtolength{\\leftmargin}{\\labelsep}%
                \\renewcommand{\\makelabel}{\\uplabel}}
      \\fi%
   \\else%
      \\begin{AC@deflist}{#1}%
   \\fi%
  }%
  {%
   \\ifx\\AC@populated\\AC@used\\else%
      \\ifAC@nolist%
      \\else%
          \\item[]\\relax%
      \\fi%
   \\fi%
   \\expandafter\\ifx\\csname ac@des@mark\\endcsname\\AC@used%
      \\ifAC@nolist%
      \\else%
        \\end{list}%
      \\fi%
   \\else%
      \\end{AC@deflist}%
   \\fi}%
\\renewenvironment{AC@deflist}[1]%
        {\\ifAC@nolist%
         \\else%
            \\raggedright\\begin{list}{}%
% change according to your needs , 4.45
                {\\settowidth{\\labelwidth}{\\normalfont{\\textsf{#1}}\\hspace*{3.5em}}% 
                \\setlength{\\leftmargin}{\\labelwidth}%
                \\addtolength{\\leftmargin}{\\labelsep}%
                \\renewcommand{\\makelabel}{\\uplabel}}%
          \\fi}%
        {\\ifAC@nolist%
         \\else%
            \\end{list}%
         \\fi}%
 \\makeatother

%%%
%%% APPENDIX
%%%
% -----------------------------------------
%  Abschnittsverzeichnisse (Anhang)
% -----------------------------------------
\\usepackage{appendix}
\\setcounter{tocdepth}{3}
\\setcounter{secnumdepth}{3}

% hyperref must be loaded before minitoc
\\makeatletter
\\ifthenelse{\\@scrartcl@loaded=1}{
  \\usepackage[insection,nohints]{minitoc}
  \\mtcsetdepth{secttoc}{3}
  %\\setlength{\\stcindent}{-16.5pt}
  \\setlength{\\stcindent}{0pt}
  \\mtcsetformat{secttoc}{pagenumwidth}{2em} % more space for page numbers
  %\\renewcommand{\\stctitle}{}  % Leer: Keine Überschrift
  \\renewcommand{\\stcfont}{\\normalfont\\rmfamily\\upshape\\mdseries}
}{
  \\usepackage[nohints]{minitoc}
}
\\makeatother 

\\makeatletter
\\def\\mtc@CkFile#1{%
  \\@mtc@LItrue\\@mtc@FEtrue%
  \\if@mtc@checkfiles%
  \\IfFileExists{#1}{%
    \\immediate\\openin\\@inputcheck #1\\relax
    \\mtc@While{}{\\if@mtc@LI\\relax}{\\mtc@Body}\\mtc@EndWhile%
    %
    }%
   {\\@mtc@FEtrue}%
  \\else
   \\@mtc@FEfalse%
  \\fi
  %moved in the definition
  \\closein\\@inputcheck\\relax}%
\\makeatother

<<mtcselectlanguage>>
% \\sffamily
\\mtcsetfont{secttoc}{subsection}{\\normalfont\\rmfamily\\upshape\\mdseries}
\\mtcsetfont{secttoc}{subsubsection}{\\normalfont\\rmfamily\\upshape\\mdseries}
% local use: \\nostcrule
\\mtcsetrules{*}{off}
%\\mtcsetpagenumbers{mini-table|*}{on|off}

\\newcommand{\\pdfsection}[1]{
  \\addtocounter{section}{1}
  \\phantomsection\\addcontentsline{toc}{section}
    {\\protect\\numberline{\\thesection}#1}
}
\\newcommand{\\pdfsubsection}[1]{
  \\addtocounter{subsection}{1}
  \\phantomsection\\addcontentsline{toc}{subsection}
    {\\protect\\numberline{\\thesubsection}#1}
}
\\newcommand{\\pdfsubsubsection}[1]{
  \\addtocounter{subsubsection}{1}
  \\phantomsection\\addcontentsline{toc}{subsubsection}
    {\\protect\\numberline{\\thesubsubsection}#1}
}

\\newcommand{\\pdfsectiona}[1]{
% Den folgenden Inhalt nicht im großen Inhaltsverzeichnis zeigen
 \\begin{mtchideinmaintoc}[-1]
  \\addtocounter{section}{1}
  \\phantomsection\\addcontentsline{toc}{section}
    {\\protect\\numberline{\\thesection}#1}
 \\end{mtchideinmaintoc}
}
\\newcommand{\\pdfsubsectiona}[1]{
% Den folgenden Inhalt nicht im großen Inhaltsverzeichnis zeigen
 \\begin{mtchideinmaintoc}[-1]
  \\addtocounter{subsection}{1}
  \\phantomsection\\addcontentsline{toc}{subsection}
    {\\protect\\numberline{\\thesubsection}#1}
 \\end{mtchideinmaintoc}
}
\\newcommand{\\pdfsubsubsectiona}[1]{
% Den folgenden Inhalt nicht im großen Inhaltsverzeichnis zeigen
 \\begin{mtchideinmaintoc}[-1]
  \\addtocounter{subsubsection}{1}
  \\phantomsection\\addcontentsline{toc}{subsubsection}
    {\\protect\\numberline{\\thesubsubsection}#1}
 \\end{mtchideinmaintoc}
}

%%%
%%% INDEX
%%%
\\usepackage{imakeidx}
%\\usepackage{splitidx}
\\newcommand{\\Index}[1]{#1\\index{#1}}
% Formatiere Seitennummern im Index:
\\newcommand{\\indexpageno}[1]{%
	{\\bfseries\\hyperpage{#1}}%
}
\\makeindex
%\\makeindex[%
  %name=persons,
  %title=Index of names,
  %columns=3
%]

\\usepackage{idxlayout} % avoid LaTeX bug 3126 (\twocolumn interfering with \topskip)
\\usepackage{ragged2e}  % avoid the automatic loading of the ragged2e package failure

%\\index[persons]{Einstein, Albert}
\\indexsetup{%
  level=\\section*,
  toclevel=section,
  noclearpage,
  %firstpagestyle=plain,  % disabled when the package fancyhdr is loaded
  %headers={\\indexname}{\\indexname}   % Don’t use these keys if you use fancyhdr
}
%save as <filename>.mst:
%headings_flag	1
%heading_prefix	\"{\\\\bf ---~\"
%heading_suffix	\"~---}\"
%delim_0			\"\\\\dotfill\\\\indexpageno{\"
%delim_1			\"\\\\dotfill\\\\indexpageno{\"
%delim_2			\"\\\\dotfill\\\\indexpageno{\"
%delim_t			\"}\"
%delim_n			\"}, \\\\indexpageno{\"
%delim_r			\"} -- \\\\indexpageno{\"
%suffix_2p		\"}f.{\"
%suffix_3p		\"}ff.{\"
%symhead_negative \"Symbole\"
%symhead_positive \"Symbole\"
%numhead_negative \"Zahlen\"
%numhead_positive \"Zahlen\"
%quote			'+'
%line_max		255

%%%
%%% GLOSSARIES
%%%
\\usepackage[%
   %nowarn,
   %nomain,
   %toc=true,       % Eintrag im Inhaltsverzeichnis
   %style=altlist,  % altlist: Beschreibung beginnt in neuer Zeile
   nonumberlist,   % keine Seitenzahlen anzeigen
   nogroupskip,    % keine extra Abstand bei Buchstabenwechsel
   %acronym=true,   % ein Abkürzungsverzeichnis erstellen
   section=section, % im Inhaltsverzeichnis auf section-Ebene erscheinen, subsection ...
   %description,   % n changes the deﬁnition of \\newacronym to allow a description
   %makeindex,
   %xindy={language=german-duden,codepage=utf8} % mit makeglossaries.exe ?
   %hyperfirst=false, %
]{glossaries}

\\usepackage[nonumberlist, nogroupskip, section=section,]{glossaries}

%Den Punkt am Ende jeder Beschreibung deaktivieren
\\renewcommand*{\\glspostdescription}{}
% to refer \\ref{glo:...}
\\renewcommand*{\\glsautoprefix}{glo:}
%Allgemeine definition
%\\newglossary[⟨log-ext⟩]{⟨name⟩}{⟨in-ext⟩}{⟨out-ext⟩}{⟨title⟩}[⟨counter⟩]
\\newcommand{\\dictentry}[2]{%
  \\newglossaryentry{#1}{name=#1,description={#2}}%
  \\glslink{#1}{}%
}

%\\input{Glossary.tex}
%\\makeglossaries%

%%%
%%% FIGURES
%%%
% -----------------------------------------
%  Abbildungen & Tabellen
% -----------------------------------------
\\usepackage{float}
\\usepackage{floatflt}
\\usepackage[
    font=small,         % footnotesize, small
    labelfont={bf,up,sf},
    %textfont={it,up},
    justification=raggedright,  % justified
    singlelinecheck=false,
    %format=plain,
    %indention=0cm,
]{caption}
%\\addtokomafont{caption}{\\small}     % Bildunterschrift Größe \"small\"
%\\setkomafont{captionlabel}{\\sffamily\\bfseries} % das Label wird serifenlos und fett
\\usepackage{subcaption}
\\usepackage{tablefootnote}

%%%%%% THIS PASSAGE MAKES THE TABLE AND FIGURE COUNT TO 1.1 or 4.1 INSTEAD OF 1,2,3,4...
%\\usepackage{chngcntr}
%\\counterwithin{figure}{section}
\\counterwithin{table}{section}


% -----------------------------------------
%  Abbildungen
% -----------------------------------------
\\usepackage[%
    %draft,
    %dvips, % or dvipdfm, pdftex
]{graphicx}
%\\graphicspath{{path_to_images/}}
%\\graphicspath{{the/first/path/}{the/second/path/}}
\\graphicspath{{./figures/}}
% Grafik abschneiden (links unten rechts oben):
% \\includegraphics[trim=0 0 2cm 0,clip,width=\\textwidth]{Bild}
% with px units, where <dpi> is the resolution of the image:
% \\pdfpxdimen=\\dimexpr 1 in/<dpi>\\relax
% \\includegraphics[trim=0 0 20px 0,clip,width=\\textwidth]{Bild}
% or use defined dpi option:
\\makeatletter
  \\define@key{Gin}{dpi}{%
  \\pdfpxdimen=\\dimexpr 1in/(#1)\\relax }
\\makeatother
% \\includegraphics[dpi=600,clip,trim=0 100px 200px 100px]{Figure-a} % 600 dpi

	% um eps-Dateien einzubinden (\\epsfig{file=...})
%\\usepackage{epsfig}

\\makeatletter
\\renewcommand*\\l@figure{\\@dottedtocline{1}{0em}{2.8em}}
\\renewcommand*\\l@table{\\@dottedtocline{1}{0em}{2.3em}}
\\makeatother


%##############
% SVG Einbinden
%##############
\\usepackage{svg}
\\newcommand{\\executeiffilenewer}[3]{%
  \\ifnum\\pdfstrcmp{\\pdffilemoddate{#1}}%
  {\\pdffilemoddate{#2}}>0%
  {\\immediate\\write18{#3}}\\fi%
}
% set inkscape binary path according to operating-system
\\IfFileExists{/dev/null}{%
  \\newcommand{\\Inkscape}{inkscape}%
  }{%
  %\\newcommand{\\Inkscape}{\"/usr/bin/inkscape\" }% 
  \\newcommand{\\Inkscape}{inkscape}%
}
% includesvg[scale]{file} command
%\\newcommand{\\includesvg}[2][1]{%
%  \\executeiffilenewer{#2.svg}{#2.pdf}{%
%  \\Inkscape -z -D --file=\"#2.svg\" --export-pdf=\"#2.pdf\" --export-latex }%
%  \\scalebox{#1}{\\input{#2.pdf_tex}}%
%}

% usage example:
% \\begin{center}
% \\includesvg[2]{filename}
% \\end{center}

% the following eps function is unsure - copy from web !!!
%\\usepackage{epstopdf}
%\\newcommand{\\includeps}[2][\\undefined]{%
%	\\immediate\\write18{inkscape2tex.py -i #2 -m latex-eps}%
%	\\ifx#1\\undefined%
%		\\global\\let\\svgwidth\\undefined%
%	\\else%
%		\\def\\svgwidth{#1}%
%	\\fi%
%	\\IfFileExists{#2.eps_tex}{%
%		\\input{#2.eps_tex}%
%	}{%
%		{\\color{red} FILE #2.eps_tex NOT FOUND.}%
%	}%
%}%


% Diagramme
\\usepackage[all]{xy}

% -----------------------------------------
%  Tabellen
% -----------------------------------------
%\\usepackage{rotating}   % rotated text, vertical: \\begin{sideways} ... \\end{sideways}
% fuer Tabellen ueber mehrere Seiten
\\usepackage{longtable}
% fuer mehrspaltigen Text auf einer Seite
\\usepackage{multicol}
% fuer mehrreihigen Text auf einer Seite
\\usepackage{multirow}
\\usepackage{booktabs}
\\usepackage{array}
\\usepackage{eqnarray}
\\newcolumntype{P}[1]{>{\\raggedright\\arraybackslash}p{#1}}
\\newcolumntype{C}[1]{>{\\centering}p{#1}<{}}
%\\newcolumntype{L}[1]{>{\\raisebox{\\heightof{\\rule{0pt}{1cm}}}{}}p{#1}}
% Anzahl Zeilen, Weite, Inhalt
\\newcommand{\\multirowr}[3]{\\multirow{#1}{*}{\\parbox{#2}{\\raggedright #3}}}

%\\usepackage{fancybox}	% besondere Rahmen, Schatten

%\\begin{center}
%\\resizebox{0.95\\textwidth}{!}{%
%\\begin{tabular}
%...
%\\end{tabular}}
%\\end{center}
% Zahlenformatierung
\\usepackage[autolanguage]{numprint}
% Rechenmöglichkeit in Tabellen
\\usepackage{spreadtab}

%%%
%%% LISTS
%%%
% -----------------------------------------
%  Aufzählungen
% -----------------------------------------
\\makeatletter
\\newcommand*{\\rom}[1]{\\mathrm{\\romannumeral #1}}
\\newcommand*{\\Rom}[1]{\\mathrm{\\expandafter\\@slowromancap\\romannumeral #1@}}
\\makeatother

\\renewcommand{\\labelitemi}{--}
% \\times
\\renewcommand{\\labelitemii}{\\(\\boldsymbol\\cdot\\)}

% Verbesserte Enumerate-Umgebung
\\usepackage{enumerate}

\\usepackage{enumitem}
% noitemsep
\\setlist{nosep}
% Usually a good idea
\\setlist[1]{labelindent=\\parindent}
\\setlist[itemize]{parsep=0pt,itemsep=0pt,leftmargin=*}
\\setlist[enumerate]{parsep=0pt,itemsep=0pt,leftmargin=*}

%%%
%%% LISTINGS
%%%
\\usepackage{listingsutf8}
%\\begin{lstlisting}[numbersep=0pt,resetmargins=true]
<<lstlistingname>>
\\lstdefinestyle{custom}{
 %xleftmargin=2em,
}
\\lstdefinelanguage{example}{
}
\\lstdefinelanguage{org}{
}
\\lstdefinelanguage{calc}{
}
\\lstdefinelanguage{shell}{
}

% BEFORE loading tikz!?
\\lstdefinestyle{tex}{
  language=[LaTeX]tex,
  tabsize=4,
  breaklines=true,
  breakindent=0pt,
  columns=fullflexible,
% otherwise copy-and-paste won’t work
  basicstyle=\\ttfamily
}
\\lstset{literate=%
{Ö}{{\\\"O}}1
{Ä}{{\\\"A}}1
{Ü}{{\\\"U}}1
{ß}{{\\ss}}1
{ü}{{\\\"u}}1
{ä}{{\\\"a}}1
{ö}{{\\\"o}}1
}
\\lstset{
    extendedchars=\\true,
    inputencoding=utf8/latin1,
    style=custom,
    language=Matlab,
 % small, footnotesize
    basicstyle=\\small\\ttfamily,
  % \\bfseries
    keywordstyle=\\color{blue}, 
 % \\itshape
    commentstyle=\\color{dkgreen},
   %identifierstyle=\\color{blue},
    stringstyle=\\color{mauve},
 % \\ttfamily
    numberstyle=\\tiny\\color{gray},
    numbers=left,
    numbersep=5pt,
   %stepnumber=2,
   %backgroundcolor=\\color{white},
   %frame=single,%trblTRBL,none|leftline|topline|bottomline|lines|single|shadowbox
   %frameround=ffff,   % tf|rf|rf|rf NE,SE,SW,NW
   %rulecolor=\\color{black},
   %showspaces=false,
   %showstringspaces=false,
   %showtabs=false,
   %float,
    breaklines=true,
    breakatwhitespace=true,
   %breakindent=20pt,
    tabsize=2,
 % 2\\parskip
    xleftmargin=2em,
   %title=\\lstname,
   %captionpos=b,       % b: bottom
    captionpos=t,
   %belowcaptionskip=1\\baselineskip,
   %texcl=true,                   % not with inputencoding utf/latin1 LATEX comment lines, for äöü...
   %escapebegin=\\begin{arab},escapeend=\\end{arab},
    escapeinside={\\%*}{*)},
   %morekeywords={*,...},
   %deletekeywords={...},
% auto: Listings with identical names (case sensitive!) share a line counter / or number
    firstnumber=auto,
}
\\newcommand{\\includecode}[2][c]{
  \\lstinputlisting[
    caption=#2,
    escapechar=,
    style=#1,
    %label=DescriptiveLabel,
]{#2}}
% \\includecode{sched.c}
% \\includecode[asm]{sched.s}
% \\lstlistoflistings

%%%
%%% MATH
%%%
% -----------------------------------------
%  Zusatzzeichen, Mathematik, Chemie
% -----------------------------------------
% fette Schrift, z.B. $\\boldsymbol{\\pi}$
% Zusammenrücken: \\!, \\negmedspace, \\negthickspace
% Platz einfügen: \\, \\: \\; ~ oder \\quad und \\qquad
% mehrzeilige Grenzen, \\substack{...\\\\...}
% \\overset{}{} und \\underset{}{} setzte Formelbestandteile über- oder untereinander
% \\underbrace{a+b}_\\text{Schritt 1}
% \\overbrace{e^2 - \\pi}^\\text{Schritt 2}
\\numberwithin{equation}{section}
% Manuelle Nummerierung, z. B. 1.2 a
%\\begin{equation*} \\tag{} \\end{equation*}
%\\allowdisplaybreaks    % global und lokal Anwendbar, z. B. bei underful vboxes

%\\usepackage{fourier}
\\usepackage{mathtools}
% linie unterhalb mit text \\underbracket[1pt][0pt]{bla}_\\text{blo}

\\newcommand\\Dfrac[2]{\\dfrac{\\displaystyle #1}{\\displaystyle #2}}
\\newcommand{\\slfrac}[2]{\\left.#1\\middle/#2\\right.}
\\usepackage{xfrac}
\\usepackage{nicefrac}
\\usepackage{faktor}
%
% http://tex.stackexchange.com/questions/27591/extending-the-faktor-package/27735#27735
% \\newfaktor[*]{#2}[#3]{#4}[#5] -> #2/#4
\\DeclareDocumentCommand{\\Faktor}{s m O{0.5} m O{-0.5}}{%
  % Store numerator
  \\setbox0=\\hbox{\\scalebox{0.8}{\\ensuremath{#2\\vphantom{1}}}}%
  % Store slash /
  \\setbox1=\\hbox{\\ensuremath{\\diagup}}%
  % Store denominator
  \\setbox2=\\hbox{\\scalebox{0.8}{\\ensuremath{#4}}}%
  % Numerator
  \\raisebox{#3\\ht1}{\\usebox0}%
  % Slash /
  \\mkern-5mu\\ifthenelse{\\equal{#1}{\\BooleanTrue}}%
    % regular \\faktor slash
    {\\diagup}%
    % tilted rule as a slash
    {\\rotatebox{-44}{\\rule[#5\\ht2]{0.4pt}{-#5\\ht2+#3\\ht0+\\ht0}}}%
  \\mkern-4mu%
  % Denominator
  \\raisebox{#5\\ht2}{\\usebox2}%
}

% another slanted fration below at tikz

\\usepackage{eurosym}	% fuer das Eurosymbol
\\DeclareUnicodeCharacter{20AC}{\\euro{}}  % convert unicode character to latex command

% \\usepackage[            % kann nicht mit amssymb zusammenlaufen
%    thinspace,
%    thinqspace,         % use of \\, (thin math space) as spacing
%    %mediumqspace,      % use of \\: (medium math space) as spacing
%    %thickqspace,       % use of \\; (thick math space) as spacing
%    squaren,            % defines a new command \\squaren that can be used instead of the SIunits command \\square, to prevent errors with the defined \\square command of the amssymb package. Or use amssymb to redefine \\sqare
%    Gray,               % defines a new command \\gray that can be used instead of the SIunits command \\gray, to prevent errors with the defined \\gray command of the amssymb package. Or use pstricks to redefine \\gray
%    %textstyle,
% ]{SIunits}

% siunitx is written by Joseph Wright who did, for a time, maintain SIunits. siunitx replaces SIunits and another package called SIstyle. It is a complete reimplementation of the basic idea.
\\usepackage[]{siunitx}
\\DeclareSIUnit{\\EUR}{\\text{\\euro}}
%obsolete \\usepackage[thinspace, thinqspace, squaren, Gray,]{SIunits}

% tiefstellen, Index
\\newcommand{\\ti}[1]{_\\mathrm{#1}}
% hochstellen
\\newcommand{\\ho}[1]{^\\mathrm{#1}}
%\\usepackage{mathrsfs}   % use \\mathscr, Ralph Smith’s Formal Script Font
%\\usepackage{ziffer}

%Mathematische Schrifterweiterungen
% use \\mathds{A} alternative zu mathbb
\\usepackage{dsfont}
% for tensori; incompatible with the amssymb and amsfonts, automatically loads the amsmath and textcomp
\\usepackage{MnSymbol}

% Mengensymbole
% Grundkörper in mathds
\\newcommand{\\field}[1]{\\ensuremath{\\mathds{#1}} }
% Affines A
\\newcommand{\\fA}{\\field{A}}
% Complexes C
\\newcommand{\\fC}{\\field{C}}
% Endlicher Koerper
\\newcommand{\\fFp}{\\ensuremath{\\field{F}_{\\!p}} }
% Endlicher Koerper
\\newcommand{\\fFq}{\\ensuremath{\\field{F}_{\\!q}} }
% Add Gruppenschema
\\newcommand{\\fGa}{\\ensuremath{\\field{G}_{a}} }
% Generischer Koerper
\\newcommand{\\fK}{\\field{K}}
% Nat Zahlen
\\newcommand{\\fN}{\\field{N}}
% Projektives P
\\newcommand{\\fPj}{\\field{P}}
% Reelle Zahlen
\\newcommand{\\fR}{\\field{R}}
% Rationale Zahlen
\\newcommand{\\fQ}{\\field{Q}}
% Irrationale Zahlen I=R\\Q
\\newcommand{\\fI}{\\field{I}}
% Ganze Zahlen
\\newcommand{\\fZ}{\\field{Z}}
% fuer die gilt
\\newcommand{\\fdg}{\\;|\\;}
% Definitionsbereich
\\newcommand{\\Def}{\\field{D}}
% Lösungsmenge
\\newcommand{\\LM}{\\field{L}}
\\newcommand*{\\qed}{\\hfill\\ensuremath{\\blacksquare}}
\\newcommand*\\euler{\\mathrm{e}}
\\renewcommand{\\deg}{\\ensuremath{^{\\circ}}\\xspace}
\\newcommand\\degC{{\\,^{\\circ}\\mathrm{C}}}
% short sin: s
\\newcommand\\sins{{\\mathrm{s}}}
% short cos: c
\\newcommand\\coss{{\\mathrm{c}}}

% Transpose operator
\\newcommand{\\T}{{\\mathrm{T}}\\!}
% sign for transfomed values: low tilde
\\newcommand{\\TF}{{\\raisebox{-0.5ex}{$\\sim$}}}
% Adjoint operator
\\newcommand{\\adj}{{\\mathrm{H}}}
\\newcommand*\\dif{\\mathop{}\\!\\mathrm{d}}
\\newcommand*\\E{\\ensuremath{\\mathrm{E}}}

% ||x||
\\providecommand{\\norm}[1]{\\lVert #1 \\rVert}
% |x|
\\providecommand{\\abs}[1]{\\lvert #1 \\rvert}
% <x,y>
\\providecommand{\\innerProd}[2]{\\langle #1, #2\\rangle}

% Bild einer Funktion 
\\DeclareMathOperator{\\Bild}{Bild}
% Rank of a matrix 
\\DeclareMathOperator{\\rank}{rank}
% Matrix trace
\\DeclareMathOperator{\\tr}{tr}
% Matrix deviation
\\DeclareMathOperator{\\dev}{dev}
% Variance
\\DeclareMathOperator{\\var}{var} 
% $\\grad u$ = grad u
\\DeclareMathOperator{\\grad}{grad}
% $\\div u$ = div u
\\DeclareMathOperator{\\divergence}{div}
% $\\rot u$ = rot u
\\DeclareMathOperator{\\rot}{rot}
% Diagonal matrix
\\DeclareMathOperator{\\diag}{diag}
% Classical adjoint (adjugate) 
\\DeclareMathOperator{\\adjugate}{adj}

%\\newcommand{\\corresponds}{\\ensuremath{\\stackrel{\\wedge}{=} \\hat{=} \\mathop{\\hat{=}} \\substack{\\wedge\\\\=} \\mathrel{\\widehat{=}} } \\^{=} }
\\newcommand*\\corresponds{%
  \\mbox{\\kern0em
    \\raisebox{-.5ex}{\\Large\\^{}}\\kern-.55em%
    \\raisebox{-.1ex}{=}%
  }\\ %
}

\\newcommand*{\\dt}[1]{%
  \\overset{\\mbox{\\large\\bfseries .}}{#1}}
\\newcommand*{\\ddt}[1]{%
  \\overset{\\mbox{\\large\\bfseries .\\hspace{-0.1ex}.}}{#1}}

\\newcommand*{\\Eval}[3]{%
  {\\left.#1\\phantom{\\Big|}\\!\\!\\right\\rvert_{#2}^{#3}}}

% both for tensor
\\usepackage{accents}
\\usepackage{ushort}
%\\usepackage{ulem}    % not for math mode, too much space below with uuline; for tensor

\\newcommand{\\tensor}[1]{    \\ensuremath{ {\\boldsymbol{#1}} } }

\\newcommand{\\tensorI}[1]{   \\ensuremath{ \\ushort{ {\\boldsymbol{#1}} } } }
\\newcommand{\\tensorII}[1]{  \\ensuremath{ \\ushortd{{\\boldsymbol{#1}} } } }
\\newcommand{\\tensorIII}[1]{ \\ensuremath{ \\underaccent{3}{ \\underaccent{\\tilde}{ {\\boldsymbol{#1}} } } } }
\\newcommand{\\tensorIV}[1]{  \\ensuremath{ \\underaccent{4}{ \\underaccent{\\tilde}{ {\\boldsymbol{#1}} } } } }
% bm variant
%\\usepackage{bm}   % load bm after amsmath and after your font packages!; for tensor
%\\newcommand{\\tensorI}[1]{   \\ensuremath{ \\uline{  \\bm{#1} } } }
%\\newcommand{\\tensorII}[1]{  \\ensuremath{ \\uuline{ \\bm{#1} } } }
%\\newcommand{\\tensorIII}[1]{ \\ensuremath{ \\underaccent{3}{ \\underaccent{\\tilde}{ \\bm{#1} } } } }
%\\newcommand{\\tensorIV}[1]{  \\ensuremath{ \\underaccent{4}{ \\underaccent{\\tilde}{ \\bm{#1} } } } }

%needs MnSymbol
\\newcommand{\\tensori}[1]{
	\\tikz[baseline, anchor=base,inner sep=0pt]{
		\\node{\\ensuremath{\\phantom{#1\\vphantom{\\overrightharpoon{b}}}}};
		\\node[overlay]{ \\ensuremath{ \\overrightharpoon{ \\mbox{\\ensuremath{#1}\\vphantom{b}} } } };
  }
}
\\newcommand{\\tensorii}[1]{
	\\tikz[baseline, anchor=base,inner sep=0pt]{
		\\node{\\ensuremath{\\phantom{#1\\vphantom{\\overrightharpoon{b}}}}};
		\\node[overlay]{ \\ensuremath{ \\overrightharpoon{ \\mbox{\\ensuremath{#1}\\vphantom{b}} } } };
		\\node[overlay]{ \\reflectbox{ \\ensuremath{ \\overrightharpoon{ \\phantom{ \\mbox{\\ensuremath{#1}\\vphantom{b}} } } } } };
  }
}
\\newcommand{\\tensoriii}[1]{
	\\tikz[baseline, anchor=base,inner sep=0pt]{
		\\node{\\ensuremath{\\phantom{#1\\vphantom{\\overrightharpoon{b}}}}};
		\\node[overlay]{ \\ensuremath{ \\overrightarrow{ \\mbox{\\ensuremath{#1}\\vphantom{b}} } } };
		\\node[overlay]{ \\reflectbox{ \\ensuremath{ \\overrightharpoon{ \\phantom{ \\mbox{\\ensuremath{#1}\\vphantom{b}} } } } } };
  }
}
\\newcommand{\\tensoriv}[1]{
	\\tikz[baseline, anchor=base,inner sep=0pt]{
		\\node{\\ensuremath{\\phantom{#1\\vphantom{\\overrightharpoon{b}}}}};
		\\node[overlay]{ \\ensuremath{ \\overrightarrow{ \\mbox{\\ensuremath{#1}\\vphantom{b}} } } };
		\\node[overlay]{ \\reflectbox{ \\ensuremath{ \\overrightarrow{ \\phantom{ \\mbox{\\ensuremath{#1}\\vphantom{b}} } } } } };
  }
}

\\usepackage{amsthm}
\\theoremstyle{definition}
% nummeriert
\\newtheorem{tDef}{Def}
\\newtheorem{tBsp}{Bsp}
% unnummeriert
\\newtheorem*{tDef*}{Def}
\\newtheorem*{tBsp*}{Bsp}

\\newcommand{\\undertab}[1]{\\clap{%
  \\scriptsize\\begin{tabular}{@{}c@{}}#1\\end{tabular}}}
% underbrace, centered, space corrected
\\newcommand{\\ubspace}[2]{% Correct \\underbrace spacing
  \\mathrlap{\\underbrace{\\phantom{\\scalebox{0.95}{$#1$}\\strut}}_{\\undertab{#2}}}#1}
% underbrace, left aligned, space corrected
\\newcommand{\\ubspacel}[2]{% Correct \\underbrace spacing
  \\mathrlap{\\underbracket[0pt][0pt]{\\phantom{\\scalebox{0.95}{$#1$}\\strut}}_{\\vphantom{\\big\\mid}\\text{#2}}}\\underbrace{#1}}
% underbrace line, left aligned, space corrected
\\newcommand{\\ubspacell}[2]{
  \\mathrlap{\\underbracket[0pt][0pt]{\\phantom{#1\\strut}}_{\\text{#2}}}\\underbracket[0.5pt][0pt]{#1}}

\\usepackage{cancel}


%\\begin{pmatrix}[1.5]  -> \\arraystretch{1.5}
\\makeatletter
\\renewcommand*\\env@matrix[1][\\arraystretch]{%
  \\edef\\arraystretch{0.8}%
  \\edef\\arraystretch{#1}%
  \\edef\\arraycolsep{2pt}%
  \\hskip -\\arraycolsep%
  \\let\\@ifnextchar\\new@ifnextchar%
  \\array{*\\c@MaxMatrixCols c}}
\\makeatother

\\newenvironment{Array}[1]{
  \\begingroup
  \\arraycolsep=1pt\\def\\arraystretch{1}
  \\begin{array}{@{}#1@{}}
}{\\end{array}\\endgroup}


% -----------------------------------------
%  Eigene Befehle
% -----------------------------------------
 % öffnende Winkelklammer \"\"
\\newcommand{\\<}{\\(\\langle\\)}
% schliessende Winkelklammer \"\"
\\renewcommand{\\>}{\\(\\rangle\\)}

\\newcommand{\\bsufont}{\\normalfont\\sffamily\\upshape\\bfseries}

\\newcommand\\TikZ{Ti\\textit kZ}
\\newcommand\\PGF{\\textsc{pgf}}

% Technische Zeichen
\\newcommand{\\bohrtiefe}{\\scalebox{1}[0.75]{\\rotatebox[origin=ct]{-90}{\\hspace{0.2ex}$\\mapsto$}}}

%%%
%%% TIKZ
%%%
% -----------------------------------------
%  Zeichnungen
% -----------------------------------------
\\usepackage{tikz}
\\usepackage{gnuplot-lua-tikz}
% ,pgfmath
\\usepackage{pgfplots}
\\usepgflibrary{shapes.geometric}
\\usepackage{tabularx}
\\usetikzlibrary{
    % for arrow heads
    arrows,
    % for manimulation of coordinates
    calc,
    positioning,
    shapes.multipart,
    %shadings,
    decorations.pathmorphing,
    % need package pgfplots
    backgrounds,
    %after pgfplots
    pgfplotsclickable,
    shadows,
    shadows.blur,
    mindmap,
}

% based on soul
% \\highlight[tikz-opts]{...} like:
% \\highlight{}
% \\highlight[red]{}
% \\highlight[green, draw=blue]{}
\\makeatletter
\\newcommand{\\defhighlighter}[3][]{%
  \\tikzset{every highlighter/.style={color=#2, fill opacity=#3, #1}}%
}
\\defhighlighter{yellow}{.5}
\\newcommand{\\highlight@DoHighlight}{
  \\fill [ decoration = {random steps, amplitude=1pt, segment length=15pt}
        , outer sep = -15pt, inner sep = 0pt, decorate
        , every highlighter, this highlighter ]
        ($(begin highlight)+(0,8pt)$) rectangle ($(end highlight)+(0,-3pt)$) ;
}
\\newcommand{\\highlight@BeginHighlight}{
  \\coordinate (begin highlight) at (0,0) ;
}
\\newcommand{\\highlight@EndHighlight}{
  \\coordinate (end highlight) at (0,0) ;
}
\\newdimen\\highlight@previous%
\\newdimen\\highlight@current%
\\DeclareRobustCommand*\\highlight[1][]{%
  \\tikzset{this highlighter/.style={#1}}%
  \\SOUL@setup%
  %
  \\def\\SOUL@preamble{%
    \\begin{tikzpicture}[overlay, remember picture]
      \\highlight@BeginHighlight
     \\highlight@EndHighlight
    \\end{tikzpicture}%
  }%
  %
  \\def\\SOUL@postamble{%
    \\begin{tikzpicture}[overlay, remember picture]
      \\highlight@EndHighlight
      \\highlight@DoHighlight
    \\end{tikzpicture}%
  }%
  %
  \\def\\SOUL@everyhyphen{%
    \\discretionary{%
      \\SOUL@setkern\\SOUL@hyphkern%
      \\SOUL@sethyphenchar%
      \\tikz[overlay, remember picture] \\highlight@EndHighlight ;%
    }{%
    }{%
      \\SOUL@setkern\\SOUL@charkern%
    }%
  }%
  %
  \\def\\SOUL@everyexhyphen##1{%
    \\SOUL@setkern\\SOUL@hyphkern%
    \\hbox{##1}%
    \\discretionary{%
      \\tikz[overlay, remember picture] \\highlight@EndHighlight ;%
    }{%
    }{%
      \\SOUL@setkern\\SOUL@charkern%
    }%
  }%
  %
  \\def\\SOUL@everysyllable{%
    \\begin{tikzpicture}[overlay, remember picture]
      \\path let \\p0 = (begin highlight), \\p1 = (0,0) in \\pgfextra
        \\global\\highlight@previous=\\y0
        \\global\\highlight@current =\\y1
      \\endpgfextra (0,0) ;
      \\ifdim\\highlight@current < \\highlight@previous
        \\highlight@DoHighlight
        \\highlight@BeginHighlight
      \\fi
    \\end{tikzpicture}%
    \\the\\SOUL@syllable%
    \\tikz[overlay, remember picture] \\highlight@EndHighlight ;%
  }%
  \\SOUL@%
}
\\makeatother


\\pgfplotsset{
 % or newest,
    compat=1.17,
   % Komma statt Punkt als Dezimaltrennzeichen
    x tick label style={/pgf/number format/use comma},
    y tick label style={/pgf/number format/use comma},
    every node near coord/.style={/pgf/number format/use comma},
    /pgfplots/annot/js fillColor={[\"RGB\",1,1,1]},
    every semilogy axis/.append style={/pgfplots/annot/point format={(\\%.1f,\\%.1e)}},
    every semilogx axis/.append style={/pgfplots/annot/point format={(\\%.1e,\\%.1f)}},
    every loglog axis/.append style={/pgfplots/annot/point format={(\\%.1e,\\%.1e)}}
}
\\usepackage{pgfplotstable}
    \\colorlet{darkgreen}{green!50!black}
    \\colorlet{lightgreen}{green!80!black}
    \\colorlet{darkred}{red!50!black}
    \\colorlet{lightred}{red!80!black}

% this must be under the configuration of x tick label
% legend position outer south
\\makeatletter
\\pgfplotsset{
    every axis x label/.append style={
        alias=current axis xlabel
    },
    legend pos/outer south/.style={
        /pgfplots/legend style={
            at={%
                (%
                \\@ifundefined{pgf@sh@ns@current axis xlabel}%
                {xticklabel cs:0.5}%
                {current axis xlabel.south}%
                )%
            },
            anchor=north
        }
    }
}
\\makeatother


% !!!! in tikzset sind keine Leerzeilen erlaubt !!!!
\\tikzset{
    %scale a tikzpicture including texts
    global scale/.style={
           scale=#1,
           every node/.style={scale=#1}
    },
    %Define standard arrow tip
    >=stealth',
    %Define standard node
    %every text node part/.style={align=left},
    % Colors
}
% Funktionsstruktur
\\tikzset{
    %Define style for boxes
    punkt/.style={
           rectangle,
           %rounded corners,
%very thick,
           draw=black,
% gray
           left color=navyblue!0,
           right color=navyblue!30,
           text width=6em,
           minimum height=4em,
           text centered},
    dummyPunkt/.style={
           rectangle,
           text width=6em,
           minimum height=4em},
    dummy/.style={
           rectangle,
           text width=0.1em,
           minimum height=4em},
    %
    %Define style for node
    aboveOf/.style={
           above=0.75cm of #1},
    belowOf/.style={
           below=0.75cm of #1},
% node input
    ni/.style={
           above right,
           xshift=2mm},
% node output
    no/.style={
           above left,
           xshift=-2mm},
    %
    % Define arrow style
    trans/.style={
           ->,
           thick,
           shorten >=0pt,
           shorten <=0pt,
           >=stealth},
    classical/.style={
           ->,
% semithick
           thick,
           double distance=1pt,
           shorten >=0pt,
           shorten <=0pt,
           >=stealth},
    virtual/.style={
           ->,
           thick,
           densely dashed,
           >=stealth},
}
% Linien
\\tikzset{
    line1/.style={
           line width = 3,
           line cap=round,
           NavyBlue},
    line2/.style={
           line width = 3,
           line cap=round,
           loosely dashed,
           red},
    axis/.style={thick, ->, >=stealth'},
    graph1/.style={
           thick,
           line cap=round,
           NavyBlue},
}
% Graphen
\\tikzset{
    draw0/.style={
           gray},
    draw1/.style={
           very thick,
           NavyBlue},
    draw2/.style={
           very thick,
           red},
    draw3/.style={
           very thick,
           dkgreen},
    draw4/.style={
           very thick,
           orange},
    draw10/.style={
           very thick,
           black},
    fill0/.style={
          fill=gray!100,
          draw=none,
           very nearly transparent},
    fill1/.style={
           fill=MidnightBlue!20,
           draw=none},
    fill2/.style={
           fill=red!20,
           draw=none},
}
\\tikzset{
    every pin/.style={fill=white,rectangle,rounded corners=3pt,font=\\small},
    small dot/.style={fill=black,circle,scale=0.3},
}
\\tikzset{color0/.style={color=black}}

\\newcommand{\\FB}[7]{%
  \\begin{tikzpicture}[auto, node distance=2cm,>=latex']
    \\setstretch{0.8}
    \\begin{scope}[xscale=1, yscale=1, xshift=7.8cm]\\small
      \\ifthenelse{\\isempty{#2}}%
% if #2 is empty
        {}%
% if #2 is not empty
        {\\draw[trans] (0,0.85) node[above right,yshift=-1mm,text width=2.5cm] {#2\\(_{}\\)} --(2.5,0.85) ;}%
      \\ifthenelse{\\isempty{#4}} {}
    	{\\draw[classical] (0,0) node[above right,yshift=-1mm,text width=2.5cm] {#4\\(_{}\\)}--(2.5,0);}
      \\ifthenelse{\\isempty{#6}} {}
    	{\\draw[virtual] (0,-0.85) node[above right,yshift=-1mm,text width=2.5cm] {#6\\(_{}\\)}--(2.5,-0.85);}

      \\ifthenelse{\\isempty{#3}} {}
    	{\\draw[trans] (6.25,0.85) node[above right,xshift=1mm,yshift=-1mm,text width=2.5cm] {#3\\(_{}\\)}--(8.75,0.85);}
      \\ifthenelse{\\isempty{#5}} {}
    	{\\draw[classical] (6.25,0) node[above right,xshift=1mm,yshift=-1mm,text width=2.5cm] {#5\\(_{}\\)}--(8.75,0);}
      \\ifthenelse{\\isempty{#7}} {}
    	{\\draw[virtual] (6.25,-0.85)node[above right,xshift=1mm,yshift=-1mm,text width=2.5cm] {#7\\(_{}\\)}--(8.75,-0.85) ;}

      \\ifthenelse{\\isempty{#1}} {}
 % gray!30
    	{\\node[draw=black,left color=navyblue!0,right color=navyblue!30,text width=3.5cm,minimum height=2.5cm,text centered,right=2.5cm] (f){\\normalsize#1};}
    \\end{scope}
  \\end{tikzpicture}
}
%%
% x axis and y axis in first quadrant
% x 0...1, 1 = 100%
% y 0...1, 1 = 100%
% \\tikzAxesQ1{x}{y}{labelX}{labelY}
\\newcommand{\\tikzAxesQi}[4]{
    \\draw[axis] (-0.1,0) -- ($(#1+.1,0)$) node(xline)[right]
        {$#3$};
    \\draw[axis] (0,-0.1) -- ($(0,#2+.1)$) node(yline)[above] {$#4$};
}
%%
% x axis and y axis
% x 0...1, 1 = 100%
% y 0...1, 1 = 100%
% \\tikzAxes{x}{y}{labelX}{labelY}
\\newcommand{\\tikzAxes}[4]{
    \\draw[axis] ($(-#1-.2,0)$) -- ($(#1+.2,0)$) node(xline)[below]
        {$#3$};
    \\draw[axis] ($(0,-#2-.2)$) -- ($(0,#2+.2)$) node(yline)[left] {$#4$};
}
%%
% x axis and y axis
% x 0...1, 1 = 100%
% y 0...1, 1 = 100%
% \\tikzAxes{x}{y}{delta x,y}{labelX}{labelY}
\\newcommand{\\tikzAxesD}[5]{
    \\draw[axis] ($(-#1-#3,0)$) -- ($(#1+#3,0)$) node(xline)[below]
       {$#4$};
    \\draw[axis] ($(0,-#2-#3)$) -- ($(0,#2+#3)$) node(yline)[left] {$#5$};
}
%%
% at given position 'x,y' an x marker with a label 'text' in math mode
% \\tikzMarkerX{x,y}{text}
\\newcommand{\\tikzMarkerX}[2]{
    \\draw($(#1)-(0,.025)$) node[below]{$#2$\\vphantom{b}} -- ($(#1)+(0,.025)$);
}
%%
% multiple x markers with labels
% \\tikzMarkersX{coordinate1/text1,coordinate2/text2,...}
\\newcommand{\\tikzMarkersX}[1]{
    \\foreach \\pos/\\text in {#1} {
        \\tikzMarkerX{\\pos}{\\text}
    }
}
%%
% at given position 'x,y' an y marker with a label 'text' in math mode
% \\tikzMarkerY{x,y}{text}
\\newcommand{\\tikzMarkerY}[2]{
    \\draw($(#1)-(.025,0)$) node[left]{$#2$\\vphantom{b}} -- ($(#1)+(.025,0)$);
}
%%
% multiple y markers with labels
% \\tikzMarkersY{coordinate1/text1,coordinate2/text2,...}
\\newcommand{\\tikzMarkersY}[1]{
    \\foreach \\pos/\\text in {#1} {
        \\tikzMarkerX{\\pos}{\\text}
    }
}
%%
% point marker at given position
% \\tikzPoint{x,y}
\\newcommand{\\tikzPoint}[1]{
    \\fill[red] (#1) circle (.4pt);
}
%%
% point markers at given positions
% \\tikzPoint{coordinate1,coordinate2,...}
\\newcommand{\\tikzPoints}[1]{
    \\foreach \\pos in {#1} {
        \\tikzPoint{\\pos}
    }
}

\\def\\tikzoverlay{%
  \\tikz[baseline,overlay]\\node[every overlay node]
}%
% usage:
%\\tikzoverlay[text width=6cm] at (9.3cm,5cm) {... content ...}

%%%
%%% HYPHENATION
%%%
% -----------------------------------------
%  Silbentrennung
% -----------------------------------------
\\hyphenation{}
% wird nach \\selectlanguage{ngerman} zurückgesetzt
% \\allowhyphens setzen reicht?
% und \\allowbreak nach einem hyphen?

"
  "Preamble options.
`my-org-article-latex-lang-template-plist'"
  :group 'my-org-export-article)

(defcustom my-org-article-latex-header-extra ""
  "Preamble extra options."
  :group 'my-org-export-article)

(defcustom my-org-article-latex-default-packages-alist
  '(("AUTO" "inputenc"  t ("pdflatex"))
    ("T1"   "fontenc"   t ("pdflatex"))
    (""     "graphicx"  t)
    (""     "grffile"   t)
    (""     "longtable" nil)
    (""     "wrapfig"   nil)
    (""     "rotating"  nil)
    ("normalem" "ulem"  t)
    (""     "amsmath"   t)
    (""     "textcomp"  t)
    (""     "amssymb"   t)
    (""     "capt-of"   nil)
    (""     "hyperref"  nil))
  "See `org-latex-default-packages-alist'."
  :group 'my-org-export-article
  ;;:set 'org-set-packages-alist
  ;;:get 'org-get-packages-alist
  :version "26.1"
  :package-version '(Org . "8.3")
  :type '(repeat
	  (choice
	   (list :tag "options/package pair"
		 (string :tag "options")
		 (string :tag "package")
		 (boolean :tag "Snippet")
		 (choice
		  (const :tag "For all compilers" nil)
		  (repeat :tag "Allowed compiler" string)))
	   (string :tag "A line of LaTeX"))))

(defcustom my-org-article-latex-packages-alist nil
  "See `org-latex-packages-alist'."
  :group 'my-org-export-article
  ;;:set 'org-set-packages-alist
  ;;:get 'org-get-packages-alist
  :type '(repeat
	  (choice
	   (list :tag "options/package pair"
		 (string :tag "options")
		 (string :tag "package")
		 (boolean :tag "Snippet"))
	   (string :tag "A line of LaTeX"))))

;;;; Document

(defcustom my-org-article-latex-opening
  ""
  "Article opening."
  :group 'my-org-export-article)

(defcustom my-org-article-latex-closing
  ""
  "Article closing."
  :group 'my-org-export-article)


;;; Template
(defun my-org-article-latex-lang-template-value (property lang)
  "Return lang version of property if in
`my-org-article-latex-lang-template-plist' defined, else use en as
default."
  (let ((value (plist-get
                my-org-article-latex-lang-template-plist
                (intern (concat (symbol-name property) "-" lang)))))
    (if value
        value
      (plist-get
       my-org-article-latex-lang-template-plist
       (intern (concat (symbol-name property) "-en"))))))

;;;###autoload
(defun my-org-article-latex-make-preamble (info &optional template snippet?)
  "See `org-latex-make-preamble'"
  (let* ((class (plist-get info :latex-class))
   (lang (plist-get info :language))
	 (class-template
	  (or template
	      (let* ((class-options
                (string-replace
                 "<<documentclass>>"
                 (my-org-article-latex-lang-template-value :documentclass lang)
                 (plist-get info :latex-class-options)))
		     (header (nth 1 (assoc class (plist-get info :latex-classes)))))
		(and (stringp header)
		     (if (not class-options) header
		       (replace-regexp-in-string
			"^[ \t]*\\\\documentclass\\(\\(\\[[^]]*\\]\\)?\\)"
			class-options header t nil 1))))
	      (user-error "Unknown LaTeX class `%s'" class))))
    (org-latex-guess-polyglossia-language
     (org-latex-guess-babel-language
      (org-latex-guess-inputenc
       (org-element-normalize-string
	(org-splice-latex-header
	 class-template
	 (org-latex--remove-packages my-org-article-latex-default-packages-alist info)
	 (org-latex--remove-packages my-org-article-latex-packages-alist info)
	 snippet?
	 (mapconcat #'org-element-normalize-string
		 (list (s-replace-all
            (list (cons "<<babel>>"
                        (my-org-article-latex-lang-template-value :babel lang))
                  (cons "<<fontspec>>"
                        (my-org-article-latex-lang-template-value :fontspec lang))
                  (cons "<<ruby>>"
                        (my-org-article-latex-lang-template-value :ruby lang))
                  (cons "<<biblatex>>"
                        (my-org-article-latex-lang-template-value :biblatex lang))
                  (cons "<<csquotes>>"
                        (my-org-article-latex-lang-template-value :csquotes lang))
                  (cons "<<mtcselectlanguage>>"
                        (my-org-article-latex-lang-template-value :mtcselectlanguage lang))
                  (cons "<<lstlistingname>>"
                        (my-org-article-latex-lang-template-value :lstlistingname lang)))
            (plist-get info :latex-header))
			  (and (not snippet?)
			       (plist-get info :latex-header-extra)))
		    ""))))
      info)
     info)))

(defun my-org-article-latex-template (contents info)
  "See `org-latex-template'"
  (let ((title (org-export-data (plist-get info :title) info))
	(spec (org-latex--format-spec info)))
    (concat
     ;; Time-stamp.
     (and (plist-get info :time-stamp-file)
	  (format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
     ;; LaTeX compiler.
     (org-latex--insert-compiler info)
     ;; Document class and packages.
     (my-org-article-latex-make-preamble info)
     ;; Possibly limit depth for headline numbering.
     (let ((sec-num (plist-get info :section-numbers)))
       (when (integerp sec-num)
	 (format "\\setcounter{secnumdepth}{%d}\n" sec-num)))
     ;; Author.
     (let ((author (and (plist-get info :with-author)
			(let ((auth (plist-get info :author)))
			  (and auth (org-export-data auth info)))))
	   (email (and (plist-get info :with-email)
		       (org-export-data (plist-get info :email) info))))
       (cond ((and author email (not (string= "" email)))
	      (format "\\author{%s\\thanks{%s}}\n" author email))
	     ((or author email) (format "\\author{%s}\n" (or author email)))))
     ;; Date.
     (let ((date (and (plist-get info :with-date) (org-export-get-date info))))
       (format "\\date{%s}\n" (org-export-data date info)))
     ;; Title and subtitle.
     (let* ((subtitle (plist-get info :subtitle))
	    (formatted-subtitle
	     (when subtitle
	       (format (plist-get info :latex-subtitle-format)
		       (org-export-data subtitle info))))
	    (separate (plist-get info :latex-subtitle-separate)))
       (concat
	(format "\\title{%s%s}\n" title
		(if separate "" (or formatted-subtitle "")))
	(when (and separate subtitle)
	  (concat formatted-subtitle "\n"))))
     ;; Hyperref options.
     (let ((template (plist-get info :latex-hyperref-template)))
       (and (stringp template)
            (format-spec template spec)))
     ;; Document start.
     "\\begin{document}\n\n"
     ;; Title command.
     (let* ((title-command (plist-get info :latex-title-command))
            (command (and (stringp title-command)
                          (format-spec title-command spec))))
       (org-element-normalize-string
	(cond ((not (plist-get info :with-title)) nil)
	      ((string= "" title) nil)
	      ((not (stringp command)) nil)
	      ((string-match "\\(?:[^%]\\|^\\)%s" command)
	       (format command title))
	      (t command))))
     ;; Table of contents.
     (let ((depth (plist-get info :with-toc)))
       (when depth
	 (concat (when (integerp depth)
		   (format "\\setcounter{tocdepth}{%d}\n" depth))
		 (plist-get info :latex-toc-command))))
     ;; Document's body.
     (concat (plist-get info :article-opening) "\n")
     contents
     (concat (plist-get info :article-closing) "\n")
     ;; references
     ;; Creator.
     (and (plist-get info :with-creator)
	  (concat (plist-get info :creator) "\n"))
     ;; Document end.
     "\\end{document}")))

;;;###autoload
(defun my-org-article-latex-export-to-latex
  (&optional async subtreep visible-only body-only ext-plist)
  "See `org-latex-export-to-latex'"
  (interactive)
  (let ((outfile (org-export-output-file-name ".tex" subtreep)))
    (org-export-to-file 'article-latex outfile
      async subtreep visible-only body-only ext-plist)))

;;;###autoload
(defun my-org-article-latex-export-to-pdf
  (&optional async subtreep visible-only body-only ext-plist)
  "See `org-latex-export-to-pdf'"
  (interactive)
  (let ((outfile (org-export-output-file-name ".tex" subtreep)))
    (org-export-to-file 'article-latex outfile
      async subtreep visible-only body-only ext-plist
      (lambda (file) (org-latex-compile file)))))


;; HTML
(org-export-define-derived-backend 'article-html 'tufte-html

  :menu-entry
  '(?h ?a
       ((?a "To HTML file" my-org-article-html-export-to-html)
        (?A "To HTML file and open"
            (lambda (a s v b)
	            (if a (my-org-article-html-export-to-html t s v b)
		            (org-open-file (my-org-article-html-export-to-html nil s v b)))))))
  
  :options-alist
  '((:html-doctype "HTML_DOCTYPE" nil my-org-article-html-doctype)
    (:html-head "HTML_HEAD" nil my-org-article-html-head newline))

  ;;:translate-alist
  ;;'((template . my-org-article-html-template))
  )


;;; User Configuration Variables

;;;; Template :: Generic

(defcustom my-org-article-html-doctype "html5"
  "See `org-html-doctype'."
  :group 'my-org-export-article
  :version "24.4"
  :package-version '(Org . "8.0")
  :type (append
	 '(choice)
	 (mapcar (lambda (x) `(const ,(car x))) org-html-doctype-alist)
	 '((string :tag "Custom doctype" ))))

;;;; Template :: Styles

(defcustom my-org-article-html-head "
   <style type=\"text/css\">
    /*<![CDATA[*/
/*
/* HTML-STYLE
 */
/* use calc with spaces! */
body {                                  /* default pixel size: 19px */
  background:       #292b2e;
  color:            #b2b2b2;
  padding-left:     12.5%;
  counter-reset:    sidenote-counter;
}
h1, h2, h3 {
  font-weight:      400;
}
.title {
  text-align:       left;
}
#content p, #content dl, .org-src-container, div>.MathJax_Display, #postamble {
  width:            55%;
}
pre.example {
  width:            calc(55% - 4.2em);
}
div>.org-ul {                           /* total width 55% */
  padding-left:     2.5%;
  width:            52.5%;
}
div>.org-ul ul {                        /* total width 100% (nasted) */
  padding-left:     5%;
  width:            95%;
}
div .org-ol {                           /* all list blocks */
  list-style:       inside decimal;
  text-indent:      -1em;
  padding-left:     1em;
}
div>.org-ol {                           /* only 1st list block, total width 55% */
  padding-left:     1em;
  width:            calc(55% - 1em);
}
a:link {                                /* unvisited link */
  color:            #2aa1ae;
}
a:visited {                             /* visited link */
  color:            #4f97d7;
}
a:hover {                               /* mouse over link */
  color:            #ce537a;
}
a:active {                              /* selected link */
  color:            #ECEFF1;
}
/* strong {
  color:            #bc6ec5;
} */
#table-of-contents ul {
  list-style:       none;
}
#table-of-contents>div>ul {
  padding-left:     0;
}
#table-of-contents>div>ul>li>ul {
  padding-left:     1em;                /* 0.8em #. + 0.4em space */
}
#table-of-contents>div>ul>li>ul>li>ul {
  padding-left:     2em;                /* 2*0.8em #.#. + 0.4em space */
}
.figure>p, pre.src, .MathJax_Display {
  overflow-x:       auto;
  overflow-y:       hidden;
}
pre.src::before {
  background-color: #292b2e;
  border:           1px solid #b2b2b2;
  top:              -5px;
}
#postamble {
  border-top:       1px solid #b2b2b2;
}
@media (max-width: 760px) {
  body {
    padding-left:   0;
  }
  div>.org-ul, div>.org-ul ul {
    padding-left:   1em;
    width:          auto;
  }
  div>.org-ol {
    width:          auto;
  }
}
@media print {
  body {
    padding-left:   0;
  }
  #content p, .org-src-container, pre.example, #postamble {
    width:          auto;
  }
  div>.org-ul, div>.org-ul ul {
    padding-left:   1em;
    width:          auto;
  }
  div>.org-ol {
    width:          auto;
  }
  h1, h2, h3, h4, h5 {
    page-break-after: avoid;
    page-break-inside: avoid;
  }
  h2 {
    page-break-before: always;
  }
  #table-of-contents>h2, #list-of-tables>h2, #list-of-listings>h2, #list-of-symbols {
    page-break-before: auto;
  }
  h2+div>p, h3+div>p, h4+div>p {
    page-break-before: avoid;
  }
  h2+div>p~p, h3+div>p~p, h4+div>p~p {
    page-break-before: auto;
  }
  a {
    page-break-inside: avoid;
  }
  a[href^=http]:after {
    page-break-inside: avoid;
    content:        \" <\" attr(href) \"> \";
  }
}

/*
/* HTML-STYLE-TUFTE
 */
@charset \"UTF-8\";

/* Import ET Book styles
   adapted from https://github.com/edwardtufte/et-book/blob/gh-pages/et-book.css */
/*
@font-face { font-family: \"et-book\";
             src: url(\"et-book/et-book-roman-line-figures/et-book-roman-line-figures.eot\");
             src: url(\"et-book/et-book-roman-line-figures/et-book-roman-line-figures.eot?#iefix\") format(\"embedded-opentype\"), url(\"et-book/et-book-roman-line-figures/et-book-roman-line-figures.woff\") format(\"woff\"), url(\"et-book/et-book-roman-line-figures/et-book-roman-line-figures.ttf\") format(\"truetype\"), url(\"et-book/et-book-roman-line-figures/et-book-roman-line-figures.svg#etbookromanosf\") format(\"svg\");
             font-weight: normal;
             font-style: normal; }

@font-face { font-family: \"et-book\";
             src: url(\"et-book/et-book-display-italic-old-style-figures/et-book-display-italic-old-style-figures.eot\");
             src: url(\"et-book/et-book-display-italic-old-style-figures/et-book-display-italic-old-style-figures.eot?#iefix\") format(\"embedded-opentype\"), url(\"et-book/et-book-display-italic-old-style-figures/et-book-display-italic-old-style-figures.woff\") format(\"woff\"), url(\"et-book/et-book-display-italic-old-style-figures/et-book-display-italic-old-style-figures.ttf\") format(\"truetype\"), url(\"et-book/et-book-display-italic-old-style-figures/et-book-display-italic-old-style-figures.svg#etbookromanosf\") format(\"svg\");
             font-weight: normal;
             font-style: italic; }

@font-face { font-family: \"et-book\";
             src: url(\"et-book/et-book-bold-line-figures/et-book-bold-line-figures.eot\");
             src: url(\"et-book/et-book-bold-line-figures/et-book-bold-line-figures.eot?#iefix\") format(\"embedded-opentype\"), url(\"et-book/et-book-bold-line-figures/et-book-bold-line-figures.woff\") format(\"woff\"), url(\"et-book/et-book-bold-line-figures/et-book-bold-line-figures.ttf\") format(\"truetype\"), url(\"et-book/et-book-bold-line-figures/et-book-bold-line-figures.svg#etbookromanosf\") format(\"svg\");
             font-weight: bold;
             font-style: normal; }

@font-face { font-family: \"et-book-roman-old-style\";
             src: url(\"et-book/et-book-roman-old-style-figures/et-book-roman-old-style-figures.eot\");
             src: url(\"et-book/et-book-roman-old-style-figures/et-book-roman-old-style-figures.eot?#iefix\") format(\"embedded-opentype\"), url(\"et-book/et-book-roman-old-style-figures/et-book-roman-old-style-figures.woff\") format(\"woff\"), url(\"et-book/et-book-roman-old-style-figures/et-book-roman-old-style-figures.ttf\") format(\"truetype\"), url(\"et-book/et-book-roman-old-style-figures/et-book-roman-old-style-figures.svg#etbookromanosf\") format(\"svg\");
             font-weight: normal;
             font-style: normal; }
*/

/* Tufte CSS styles */
html { font-size: 15px; }

body { width: 87.5%;
       margin-left: auto;
       margin-right: auto;
       padding-left: 12.5%;
       font-family: et-book, Palatino, \"Palatino Linotype\", \"Palatino LT STD\", \"Book Antiqua\", Georgia, serif;
       background-color: #fffff8;
       color: #111;
       max-width: 1400px;
       counter-reset: sidenote-counter; }

h1 { font-weight: 400;
     margin-top: 4rem;
     margin-bottom: 1.5rem;
     font-size: 3.2rem;
     line-height: 1; }

h2 { font-style: italic;
     font-weight: 400;
     margin-top: 2.1rem;
     margin-bottom: 1.4rem;
     font-size: 2.2rem;
     line-height: 1; }

h3 { font-style: italic;
     font-weight: 400;
     font-size: 1.7rem;
     margin-top: 2rem;
     margin-bottom: 1.4rem;
     line-height: 1; }

hr { display: block;
     height: 1px;
     width: 55%;
     border: 0;
     border-top: 1px solid #ccc;
     margin: 1em 0;
     padding: 0; }

p.subtitle { font-style: italic;
             margin-top: 1rem;
             margin-bottom: 1rem;
             font-size: 1.8rem;
             display: block;
             line-height: 1; }

.numeral { font-family: et-book-roman-old-style; }

.danger { color: red; }

article { position: relative;
          padding: 5rem 0rem; }

section { padding-top: 1rem;
          padding-bottom: 1rem; }

p, ol, ul { font-size: 1.4rem;
            line-height: 2rem; }

p { margin-top: 1.4rem;
    margin-bottom: 1.4rem;
    padding-right: 0;
    vertical-align: baseline; }

/* Chapter Epigraphs */
div.epigraph { margin: 5em 0; }

div.epigraph > blockquote { margin-top: 3em;
                            margin-bottom: 3em; }

div.epigraph > blockquote, div.epigraph > blockquote > p { font-style: italic; }

div.epigraph > blockquote > footer { font-style: normal; }

div.epigraph > blockquote > footer > cite { font-style: italic; }
/* end chapter epigraphs styles */

blockquote { font-size: 1.4rem; }

blockquote p { width: 55%;
               margin-right: 40px; }

blockquote footer { width: 55%;
                    font-size: 1.1rem;
                    text-align: right; }

section > p, section > footer, section > table { width: 55%; }

/* 50 + 5 == 55, to be the same width as paragraph */
section > ol, section > ul { width: 50%;
                             -webkit-padding-start: 5%; }

li:not(:first-child) { margin-top: 0.25rem; }

figure { padding: 0;
         border: 0;
         font-size: 100%;
         font: inherit;
         vertical-align: baseline;
         max-width: 55%;
         -webkit-margin-start: 0;
         -webkit-margin-end: 0;
         margin: 0 0 3em 0; }

figcaption { float: right;
             clear: right;
             margin-top: 0;
             margin-bottom: 0;
             font-size: 1.1rem;
             line-height: 1.6;
             vertical-align: baseline;
             position: relative;
             max-width: 40%; }

figure.fullwidth figcaption { margin-right: 24%; }

/* Links: replicate underline that clears descenders */
a:link, a:visited { color: inherit; }

a:link { text-decoration: none;
         background: -webkit-linear-gradient(#fffff8, #fffff8), -webkit-linear-gradient(#fffff8, #fffff8), -webkit-linear-gradient(#333, #333);
         background: linear-gradient(#fffff8, #fffff8), linear-gradient(#fffff8, #fffff8), linear-gradient(#333, #333);
         -webkit-background-size: 0.05em 1px, 0.05em 1px, 1px 1px;
         -moz-background-size: 0.05em 1px, 0.05em 1px, 1px 1px;
         background-size: 0.05em 1px, 0.05em 1px, 1px 1px;
         background-repeat: no-repeat, no-repeat, repeat-x;
         text-shadow: 0.03em 0 #fffff8, -0.03em 0 #fffff8, 0 0.03em #fffff8, 0 -0.03em #fffff8, 0.06em 0 #fffff8, -0.06em 0 #fffff8, 0.09em 0 #fffff8, -0.09em 0 #fffff8, 0.12em 0 #fffff8, -0.12em 0 #fffff8, 0.15em 0 #fffff8, -0.15em 0 #fffff8;
         background-position: 0% 93%, 100% 93%, 0% 93%; }

@media screen and (-webkit-min-device-pixel-ratio: 0) { a:link { background-position-y: 87%, 87%, 87%; } }

a:link::selection { text-shadow: 0.03em 0 #b4d5fe, -0.03em 0 #b4d5fe, 0 0.03em #b4d5fe, 0 -0.03em #b4d5fe, 0.06em 0 #b4d5fe, -0.06em 0 #b4d5fe, 0.09em 0 #b4d5fe, -0.09em 0 #b4d5fe, 0.12em 0 #b4d5fe, -0.12em 0 #b4d5fe, 0.15em 0 #b4d5fe, -0.15em 0 #b4d5fe;
                    background: #b4d5fe; }

a:link::-moz-selection { text-shadow: 0.03em 0 #b4d5fe, -0.03em 0 #b4d5fe, 0 0.03em #b4d5fe, 0 -0.03em #b4d5fe, 0.06em 0 #b4d5fe, -0.06em 0 #b4d5fe, 0.09em 0 #b4d5fe, -0.09em 0 #b4d5fe, 0.12em 0 #b4d5fe, -0.12em 0 #b4d5fe, 0.15em 0 #b4d5fe, -0.15em 0 #b4d5fe;
                         background: #b4d5fe; }

/* Sidenotes, margin notes, figures, captions */
img { max-width: 100%; }

.sidenote, .marginnote { float: right;
                         clear: right;
                         margin-right: -60%;
                         width: 50%;
                         margin-top: 0;
                         margin-bottom: 0;
                         font-size: 1.1rem;
                         line-height: 1.3;
                         vertical-align: baseline;
                         position: relative; }

.sidenote-number { counter-increment: sidenote-counter; }

.sidenote-number:after, .sidenote:before { font-family: et-book-roman-old-style;
                                           position: relative;
                                           vertical-align: baseline; }

.sidenote-number:after { content: counter(sidenote-counter);
                         font-size: 1rem;
                         top: -0.5rem;
                         left: 0.1rem; }

.sidenote:before { content: counter(sidenote-counter) \" \";
                   font-size: 1rem;
                   top: -0.5rem; }

blockquote .sidenote, blockquote .marginnote { margin-right: -82%;
                                               min-width: 59%;
                                               text-align: left; }

div.fullwidth, table.fullwidth { width: 100%; }

div.table-wrapper { overflow-x: auto;
                    font-family: \"Trebuchet MS\", \"Gill Sans\", \"Gill Sans MT\", sans-serif; }

.sans { font-family: \"Gill Sans\", \"Gill Sans MT\", Calibri, sans-serif;
        letter-spacing: .03em; }

code { font-family: Consolas, \"Liberation Mono\", Menlo, Courier, monospace;
       font-size: 1.0rem;
       line-height: 1.42; }

.sans > code { font-size: 1.2rem; }

h1 > code, h2 > code, h3 > code { font-size: 0.80em; }

.marginnote > code, .sidenote > code { font-size: 1rem; }

pre.code { font-size: 0.9rem;
           width: 52.5%;
           margin-left: 2.5%;
           overflow-x: auto; }

pre.code.fullwidth { width: 90%; }

.fullwidth { max-width: 90%;
             clear:both; }

span.newthought { font-variant: small-caps;
                  font-size: 1.2em; }

input.margin-toggle { display: none; }

label.sidenote-number { display: inline; }

label.margin-toggle:not(.sidenote-number) { display: none; }

.iframe-wrapper { position: relative;
                  padding-bottom: 56.25%; /* 16:9 */
                  padding-top: 25px;
                  height: 0; }

.iframe-wrapper iframe { position: absolute;
                         top: 0;
                         left: 0;
                         width: 100%;
                         height: 100%; }

@media (max-width: 760px) { body { width: 84%;
                                   padding-left: 8%;
                                   padding-right: 8%; }
                            hr, section > p, section > footer, section > table { width: 100%; }
                            pre.code { width: 97%; }
                            section > ol { width: 90%; }
                            section > ul { width: 90%; }
                            figure { max-width: 90%; }
                            figcaption, figure.fullwidth figcaption { margin-right: 0%;
                                                                      max-width: none; }
                            blockquote { margin-left: 1.5em;
                                         margin-right: 0em; }
                            blockquote p, blockquote footer { width: 100%; }
                            label.margin-toggle:not(.sidenote-number) { display: inline; }
                            .sidenote, .marginnote { display: none; }
                            .margin-toggle:checked + .sidenote,
                            .margin-toggle:checked + .marginnote { display: block;
                                                                   float: left;
                                                                   left: 1rem;
                                                                   clear: both;
                                                                   width: 95%;
                                                                   margin: 1rem 2.5%;
                                                                   vertical-align: baseline;
                                                                   position: relative; }
                            label { cursor: pointer; }
                            div.table-wrapper, table { width: 85%; }
                            img { width: 100%; } }

/*
/* HTML-STYLE-MOD
 */
html {
  font-size: 12px;
}
.subtitle {
  text-align: left;
}
h4 {
  font-style: italic;
  font-weight: 400;
  font-size: 1.45rem;
  margin-top: 2rem;
  margin-bottom: 1.4rem;
  line-height: 1;
}
h5 {
  font-style: italic;
  font-weight: 400;
  font-size: 1.2rem;
  margin-top: 2rem;
  margin-bottom: 1.4rem;
  line-height: 1;
}
h6 {
  font-style: italic;
  font-weight: 400;
  font-size: 1.1rem;
  margin-top: 2rem;
  margin-bottom: 1.4rem;
  line-height: 1;
}
#content p {
  text-align: justify;
  word-break: break-word;
  -webkit-hyphens: auto;
  -moz-hyphens: auto;
  -ms-hyphens: auto;
  hyphens: auto;
}
#content table {
  margin-bottom: 1.2rem;
}
#content table, dl, div>.MathJax_Display {
  font-size: 1.4rem;
}
#content table colgroup {
  border-top-width: 2px;
  border-top-style: outset;
  border-bottom-width: 2px;
  border-bottom-style: inset;
}
#content table colgroup {
  border-right-width: 1px;
  border-right-style: inset;
}
#content table colgroup:last-of-type {
  border-right-width: 0px;
  border-right-style: unset;
}
#content thead {
  border-bottom-width: 1px;
  border-bottom-style: solid;
}
#content tbody:not(:last-child) {
  border-bottom-width: 1px;
  border-bottom-style: solid;
}
#content td {
  padding-top: 0.1rem;
  padding-bottom: 0.1rem;
}
#content td, #content th {
  padding-right: 0.5rem;
}
#content td:last-child, #content th:last-child {
  padding-right: 0;
}
#content table th {
  vertical-align: text-bottom;
}
#content ul, #content ol {
  line-height: 1.8rem;
}
#content li p {
  width: unset;
}
caption.t-above, .figure p:nth-child(2), .org-src-name {
  font-size: 1.1rem;
}
.table-number, .figure-number, .listing-number {
  font-weight: bold;
}
#table-of-contents ul, #list-of-tables ul, #list-of-listings ul {
  line-height: normal;
}
#content figure {
  display: inline-table;
  vertical-align: top;
  max-width: unset;
  margin: 0 0 2rem 0;
}
#content figcaption {
  float: unset;
  clear: unset;
  max-width: unset;
  display: table-caption;
  caption-side: bottom;
}
.org-svg {
  width: auto;
}
#text-list-of-tables .table-number {
  display: none;
}
#text-list-of-tables ul {
  list-style: decimal;
  padding-left: 2rem;
}
#text-list-of-listings .listing-number {
  display: none;
}
#text-list-of-listings ul {
  list-style: decimal;
  padding-left: 2rem;
}
#text-list-of-symbols table colgroup {
  border: none;
}
.org-src-container {
  margin: 1.2rem;
}
.org-src-container {
  width: calc(55% - 2.4rem);
}
pre.src {
  margin: 0;
}
div.epigraph {
  margin: unset;
}
div.epigraph>blockquote {
  margin-top: 1em;
  margin-bottom: 1em;
}
.todo, .done {
  font-size: 80%;
  font-style: normal;
}
.tag {
  float: right;
  background-color: unset;
  font-size: .7em;
  font-style: normal;
  line-height: 1;
}
.tag span {
  background-color: #333;
  border: 1px solid #bbb;
  border-radius: 3px;
  background-clip: padding-box;
  padding: .2em;
  margin-right: .5em;
}
#postamble p {
  line-height: 1;
}
#bibliography {
  margin-bottom: 1.4rem;
  width: 55%;
}
/*
.org-ref-reference {
  vertical-align: super;
  font-size: .83em;
}
*/
.org-ref-reference::before {
  content: \"[\";
}
.org-ref-reference::after {
  content: \"]\";
}

@media (max-width: 760px) {
  body {
    padding-left: 0;
    padding-right: 0;
    width: 94%;
  }
  #content p, .org-src-container, pre.example, pre.code, #postamble {
    width: auto;
  }
  #content table {
    display: block;
    overflow-x: auto;
  }
  .figure {
    padding-left: 0;
    padding-right: 0;
  }
  #content figure {
    display: inline-block;
    overflow-x: auto;
  }
  #content figcaption {
    display: unset;
  }
  div.table-wrapper, table, #content dl {
    width: auto;
  }
  div>.MathJax_Display {
    width: auto;
  }
  #bibliography {
    width: auto;
  }
}

/* colors */
html {
  background-color: #293b3e;
  background-image: linear-gradient(to right, #292b2e, #293b3e);
  background-repeat: repeat-y;
}
body {
  /* background-color: #293b3e; */
  /* background-image: linear-gradient(to right, #292b2e, #293b3e); */
  /* background-repeat: no-repeat; */
  background-color: transparent;
  color: #b2b2b2;
}
.outline-2 a, #bibliography a, #table-of-contents a, #list-of-tables a, #list-of-listings a {
  color: #5799b9;
}
a:link {
  background: -webkit-linear-gradient(#292b2e, #292b2e), -webkit-linear-gradient(#292b2e, #292b2e), -webkit-linear-gradient(#333, #333);
  background: linear-gradient(#292b2e, #292b2e), linear-gradient(#292b2e, #292b2e), linear-gradient(#333, #333);
  /* delete the other to background entries? */
  background: transparent;
  text-shadow: 0.03em 0 #292b2e, -0.03em 0 #292b2e, 0 0.03em #292b2e, 0 -0.03em #292b2e, 0.06em 0 #292b2e, -0.06em 0 #292b2e, 0.09em 0 #292b2e, -0.09em 0 #292b2e, 0.12em 0 #292b2e, -0.12em 0 #292b2e, 0.15em 0 #292b2e, -0.15em 0 #292b2e;
}
a:link::selection, a:link::-moz-selection {
  text-shadow: 0.03em 0 #b4d5fe, -0.03em 0 #b4d5fe, 0 0.03em #b4d5fe, 0 -0.03em #b4d5fe, 0.06em 0 #b4d5fe, -0.06em 0 #b4d5fe, 0.09em 0 #b4d5fe, -0.09em 0 #b4d5fe, 0.12em 0 #b4d5fe, -0.12em 0 #b4d5fe, 0.15em 0 #b4d5fe, -0.15em 0 #b4d5fe;
  background: #b4d5fe;
}
    /*]]>*/
   </style>
"
  "See `org-html-head'."
  :group 'my-org-export-article
  :version "24.4"
  :package-version '(Org . "8.0")
  :type 'string)
;;;###autoload
(put 'org-html-head 'safe-local-variable 'stringp)


;;; Export functions

;;;###autoload
(defun my-org-article-html-export-to-html (&optional async subtreep visible-only body-only ext-plist)
  "See `org-tufte-export-to-file' and `org-html-export-to-html'."
  (interactive)
  (let* ((extension (concat
		     (when (> (length org-html-extension) 0) ".")
		     (or (plist-get ext-plist :html-extension)
			 org-html-extension
			 "html")))
   (file (org-export-output-file-name extension subtreep))
   ;; need to bind this because tufte treats footnotes specially, so we
   ;; don't want to display them at the bottom
   (org-html-footnotes-section (if org-tufte-include-footnotes-at-bottom
                                   org-html-footnotes-section
                                 "<!-- %s --><!-- %s -->")))
    (org-export-to-file 'article-html file async subtreep
                        visible-only body-only ext-plist)))

(provide 'my-org-article)
;;; my-org-article.el ends here
