#+TITLE: PhD Thesis
:DRAWER:
#+SUBTITLE: My subtitle

#+LANGUAGE: en
#+EMAIL: dehaeze.thomas@gmail.com
#+AUTHOR: Dehaeze Thomas

#+STARTUP: overview
#+DATE: {{{time(%Y-%m-%d)}}}

#+LATEX_CLASS: scrreprt
#+LATEX_CLASS_OPTIONS: [a4paper, twoside, 11pt, onecolumn, bibliography=totoc, openright, appendixprefix=true]

#+OPTIONS: num:t toc:nil ':t *:t -:t ::t <:nil author:t date:t tags:nil todo:nil |:t H:4 title:nil

#+SELECT_TAGS: export
#+EXCLUDE_TAGS: noexport

#+BIND: org-latex-bib-compiler "biber"

#+LATEX_HEADER: \input{config.tex}
#+LATEX_HEADER_EXTRA: \input{config_extra.tex}
#+LATEX_HEADER_EXTRA: \addbibresource{ref.bib}

#+PROPERTY: header-args:latex  :headers '("\\usepackage{tikz}" "\\usepackage{import}" "\\import{$HOME/Cloud/tikz/org/}{config.tex}")
#+PROPERTY: header-args:latex+ :imagemagick t :fit yes
#+PROPERTY: header-args:latex+ :iminoptions -scale 100% -density 150
#+PROPERTY: header-args:latex+ :imoutoptions -quality 100
#+PROPERTY: header-args:latex+ :results file raw replace
#+PROPERTY: header-args:latex+ :buffer no
#+PROPERTY: header-args:latex+ :eval no-export
#+PROPERTY: header-args:latex+ :exports results
#+PROPERTY: header-args:latex+ :mkdirp yes
#+PROPERTY: header-args:latex+ :output-dir figs
#+PROPERTY: header-args:latex+ :post pdf2svg(file=*this*, ext="png")
:END:

* Build                                                             :noexport:
#+NAME: startblock
#+BEGIN_SRC emacs-lisp :results none
(add-to-list 'org-latex-classes
             '("scrreprt"
               "\\documentclass{scrreprt}"
               ("\\chapter{%s}" . "\\chapter*{%s}")
               ("\\section{%s}" . "\\section*{%s}")
               ("\\subsection{%s}" . "\\subsection*{%s}")
               ("\\paragraph{%s}" . "\\paragraph*{%s}")
               ))


;; Remove automatic org heading labels
(defun my-latex-filter-removeOrgAutoLabels (text backend info)
  "Org-mode automatically generates labels for headings despite explicit use of `#+LABEL`. This filter forcibly removes all automatically generated org-labels in headings."
  (when (org-export-derived-backend-p backend 'latex)
    (replace-regexp-in-string "\\\\label{sec:org[a-f0-9]+}\n" "" text)))
(add-to-list 'org-export-filter-headline-functions
             'my-latex-filter-removeOrgAutoLabels)

;; Remove all org comments in the output LaTeX file
(defun delete-org-comments (backend)
  (loop for comment in (reverse (org-element-map (org-element-parse-buffer)
                                    'comment 'identity))
        do
        (setf (buffer-substring (org-element-property :begin comment)
                                (org-element-property :end comment))
              "")))
(add-hook 'org-export-before-processing-hook 'delete-org-comments)

;; Use no package by default
(setq org-latex-packages-alist nil)
(setq org-latex-default-packages-alist nil)

;; Do not include the subtitle inside the title
(setq org-latex-subtitle-separate t)
(setq org-latex-subtitle-format "\\subtitle{%s}")

(setq org-export-before-parsing-hook '(org-ref-glossary-before-parsing
                                       org-ref-acronyms-before-parsing))
#+END_SRC

* Glossary and Acronyms - Tables                                      :ignore:

#+name: glossary
| label | name              | description           |
|-------+-------------------+-----------------------|
| ka    | \ensuremath{k_a}  | Actuator Stiffness in |
| phi   | \ensuremath{\phi} | A woody bush          |

#+name: acronyms
| key  | abbreviation | full form                        |
|------+--------------+----------------------------------|
| mimo | MIMO         | Multiple-Inputs Multiple-Outputs |
| siso | SISO         | Single-Input Single-Output       |
| nass | NASS         | Nano Active Stabilization System |
| lti  | LTI          | Linear Time Invariant            |

* Title Page                                                          :ignore:

#+begin_export latex
\begin{titlepage}
  \vspace*{5cm}
  \makeatletter
  \begin{center}
    \begin{Huge}
      \@title
    \end{Huge}\\[0.1cm]
    %
    \begin{Large}
      \@subtitle
    \end{Large}\\
    %
    \emph{by}\\
    \@author
    %
    \vfill
    A document submitted in partial fulfillment
    of the requirements for the degree of\\
    \emph{Technical Report}\\
    at\\
    \textsc{Miskatonic University}
  \end{center}
  \makeatother
\end{titlepage}

\newpage
\null
\thispagestyle{empty}
\newpage
#+end_export

* Abstract
:PROPERTIES:
:UNNUMBERED: notoc
:END:

* Résumé
:PROPERTIES:
:UNNUMBERED: notoc
:END:

* Acknowledgments
:PROPERTIES:
:UNNUMBERED: notoc
:END:

* Table of Contents                                                   :ignore:

#+begin_export latex
\dominitoc
\tableofcontents

\listoftables
\listoffigures
#+end_export

* Introduction
* Test
\minitoc
**** Abstract

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

** Test
A list:
- acronyms acrshort:nass acrshort:mimo acrshort:lti [[acrfull:siso][Single-Input Single-Output (SISO)]]
- glossary terms gls:ka, gls:phi.
- Bibliography citations: [[cite:&dehaeze21_activ_dampin_rotat_platf_using;&dehaeze21_mechat_approac_devel_nano_activ_stabil_system]].

A definition list:
- this :: means that
- that :: means this

Some Footnote[fn:1]

** Section
*** Sub section

This is a sub section.

*** Sub section
Start of the sub section
**** Paragraph
This is a paragraph
**** lksdfjasd

**** lksdfjasd

** blabla
* Source Blocks
\minitoc
** Matlab Init                                             :noexport:ignore:
#+begin_src matlab :tangle no :exports none :results silent :noweb yes :var current_dir=(file-name-directory buffer-file-name)
<<matlab-dir>>
#+end_src

#+begin_src matlab :exports none :results silent :noweb yes
<<matlab-init>>
#+end_src

** Figures
#+begin_src matlab
t = 0:0.01:5; % Time [s]
x = sin(2*pi*t); % Output Voltage [V]
#+end_src

#+begin_src matlab
figure;
plot(t, x);
xlabel('Time [s]'); ylabel('Voltage [V]');
#+end_src

#+begin_src matlab :tangle no :exports results :results file replace
exportFig('figs/matlab_fig_example.pdf', 'width', 'wide', 'height', 'normal');
#+end_src

#+name: fig:matlab_fig_example
#+caption: Matlab Figure
#+RESULTS:
[[file:figs/matlab_fig_example.png]]

** Table Result

#+begin_src matlab
x = 1:10;
y = x.^2;
#+end_src

#+begin_src matlab :exports results :results value table replace :tangle no :post addhdr(*this*)
data2orgtable([x', y'], {}, {'$x$', '$y = x^2$'}, ' %.0f ');
#+end_src

#+name: tab:table_name
#+caption: Table caption
#+RESULTS:
| $x$ | $y = x^2$ |
|-----+-----------|
|   1 |         1 |
|   2 |         4 |
|   3 |         9 |
|   4 |        16 |
|   5 |        25 |
|   6 |        36 |
|   7 |        49 |
|   8 |        64 |
|   9 |        81 |
|  10 |       100 |

** Inline Results

Results can be automatically outputed as shown below.

#+begin_src matlab :results value replace
sqrt(2)
#+end_src

#+RESULTS:
: 1.4142


#+begin_src matlab :results output replace
y
#+end_src

#+RESULTS:
: y =
:      1     4     9    16    25    36    49    64    81   100

** Caption and Reference

Captions can be added to code blocks.
Moreover, we can link to specific bode blocks (Listing [[lst:matlab_figure]] or [[lst:matlab_svd]]).

#+name: lst:matlab_figure
#+caption: Code to produce a nice contour plot
#+begin_src matlab
figure;
[X,Y,Z] = peaks;
contour(X,Y,Z,20)
#+end_src

#+begin_src matlab :tangle no :exports results :results file replace
exportFig('figs/matlab_logo.pdf', 'width', 'small', 'height', 'normal');
#+end_src

#+name: fig:matlab_logo
#+caption: Obtained Contour Plot
#+RESULTS:
[[file:figs/matlab_logo.png]]

#+name: lst:matlab_svd
#+caption: Code to compute the Singular Value Decomposition
#+begin_src matlab :results output replace
A = [1 2; 3 4; 5 6; 7 8]
[U,S,V] = svd(A)
#+end_src

#+RESULTS:
#+begin_example
A = [1 2; 3 4; 5 6; 7 8]
A =
     1     2
     3     4
     5     6
     7     8
[U,S,V] = svd(A)
U =
        -0.152483233310201         -0.82264747222566        -0.394501022283829        -0.379959133877596
        -0.349918371807964         -0.42137528768458         0.242796545704357         0.800655879510063
        -0.547353510305727       -0.0201031031435029         0.697909975442776        -0.461434357387336
         -0.74478864880349         0.381169081397575        -0.546205498863303        0.0407376117548695
S =
          14.2690954992615                         0
                         0         0.626828232417541
                         0                         0
                         0                         0
V =
        -0.641423027995072         0.767187395072177
        -0.767187395072177        -0.641423027995072
#+end_example

** Source Blocks with Line Numbers

Citation [[cite:&taghirad13_paral;&dehaeze21_activ_dampin_rotat_platf_using]]

The Listing [[lst:matlab_line_numbers]] has line numbers as the =-n= option was used.

Specific lines of codes can be referenced.
For instance, the code used to specify the wanted the vertical label is on line [[(test)]].

#+name: lst:matlab_line_numbers
#+caption: Specify Labels
#+begin_src matlab +n -r
figure;
plot(t, x)
xlabel('Time [s]');
ylabel('Output [V]'); (ref:test)
#+end_src

Numbering can be continued by using =+n= option as shown below.
#+begin_src matlab +n
figure;
plot(t, u)
xlabel('Time [s]');
ylabel('Input [V]');
#+end_src

* Images
\minitoc
** Normal Image

Figure [[fig:general_control_names]] shows the results of the Tikz code of listing [[lst:tikz_test]].

#+name: lst:tikz_test
#+caption: Tikz code that is used to generate Figure [[fig:general_control_names]]
#+begin_src latex :file general_control_names.pdf :exports both
  \begin{tikzpicture}

    % Blocs
    \node[block={2.0cm}{2.0cm}] (P) {$P$};
    \node[block={1.5cm}{1.5cm}, below=0.7 of P] (K) {$K$};

    % Input and outputs coordinates
    \coordinate[] (inputw)  at ($(P.south west)!0.75!(P.north west)$);
    \coordinate[] (inputu)  at ($(P.south west)!0.25!(P.north west)$);
    \coordinate[] (outputz) at ($(P.south east)!0.75!(P.north east)$);
    \coordinate[] (outputv) at ($(P.south east)!0.25!(P.north east)$);

    % Connections and labels
    \draw[<-] (inputw) -- ++(-1.5, 0);
    \draw[<-] (inputu) -- ++(-0.8, 0) |- (K.west);

    \draw[->] (outputz) -- ++(1.5, 0);
    \draw[->] (outputv) -- ++(0.8, 0) |- (K.east);
  \end{tikzpicture}
#+end_src

#+name: fig:general_control_names
#+caption: General Control Configuration
#+RESULTS: lst:tikz_test
[[file:figs/general_control_names.png]]

** Sub Images

Link to subfigure [[fig:general_control_names_1]].

#+name: fig:subfigure
#+caption: Subfigure Caption
#+attr_latex: :environment subfigure :width 0.49\linewidth :align c
| file:figs/general_control_names.png                | file:figs/general_control_names.png                |
| <<fig:general_control_names_1>> sub figure caption | <<fig:general_control_names_2>> sub figure caption |

* Tables
\minitoc

Table [[tab:table_with_equations]] shows a table with some mathematics inside.

#+name: tab:table_with_equations
#+caption: A Simple table with included math
| $N$ | $N^2$ | $N^3$ | $N^4$ | $\sqrt n$ | $\sqrt[4]N$ |
|-----+-------+-------+-------+-----------+-------------|
|   1 |     1 |     1 |     1 |         1 |           1 |
|   2 |     4 |     8 |    16 | 1.4142136 |   1.1892071 |
|   3 |     9 |    27 |    81 | 1.7320508 |   1.3160740 |
#+TBLFM: $2=$1^2::$3=$1^3::$4=$1^4::$5=sqrt($1)::$6=sqrt(sqrt(($1)))

#+name: tab:table_without_head
#+caption: Table without Head
|     | *1* | *2* | *3* | *4* | *5* |
| *1* |   1 |   2 |   3 |   4 |   5 |
| *2* |   2 |   4 |   6 |   8 |  10 |
| *3* |   3 |   6 |   9 |  12 |  15 |
| *4* |   4 |   8 |  12 |  16 |  20 |
| *5* |   5 |  10 |  15 |  20 |  25 |

#+name: tab:table_multiple_heads
#+ATTR_LATEX: :font \footnotesize
#+caption: Table with multiples groups
|                         |        *Classical Control*         |           *Modern Control*           |
| <l>                     |                <c>                 |                 <c>                  |
|-------------------------+------------------------------------+--------------------------------------|
| *Date*                  |               1930-                |                1960-                 |
|-------------------------+------------------------------------+--------------------------------------|
| *Tools*                 |         Transfer Functions         |       State Space formulation        |
|                         |           Nyquist Plots            |          Riccati Equations           |
|                         |             Bode Plots             |                                      |
|                         |       Phase and Gain margins       |                                      |
|-------------------------+------------------------------------+--------------------------------------|
| *Control Architectures* | Proportional, Integral, Derivative |         Full State Feedback          |
|                         |            Leads, Lags             |               LQR, LQG               |
|                         |                                    |            Kalman Filters            |
|-------------------------+------------------------------------+--------------------------------------|
| *Advantages*            |          Study Stability           |         Automatic Synthesis          |
|                         |               Simple               |                 MIMO                 |
|                         |              Natural               |         Optimization Problem         |
|                         |                                    |                                      |
|                         |                                    |                                      |
|-------------------------+------------------------------------+--------------------------------------|
| *Disadvantages*         |           Manual Method            |       No Guaranteed Robustness       |
|                         |             Only SISO              | Difficult Rejection of Perturbations |


* Appendix                                                            :ignore:
#+latex: \appendix

* Mathematical formulas
* Comments on something
* Bibliography                                                        :ignore:
#+latex: \printbibliography[heading=bibintoc,title={Bibliography}]

* List of Publications
:PROPERTIES:
:UNNUMBERED: notoc
:END:

#+begin_export latex
\begin{refsection}[ref.bib]
  % List all papers even if not cited
  \nocite{*}
  % Sort by year
  \newrefcontext[sorting=ynt]
  % Articles
  \printbibliography[keyword={publication},heading={subbibliography},title={Articles},env=mypubs,type={article}]
  % Proceedings
  \printbibliography[keyword={publication},heading={subbibliography},title={In Proceedings},env=mypubs,type={inproceedings}]
\end{refsection}
#+end_export

* Glossary                                                            :ignore:
#+latex: \printglossary[type=\acronymtype]
#+latex: \printglossary

* Footnotes

[fn:1]this is a footnote with citation [[cite:&dehaeze21_mechat_approac_devel_nano_activ_stabil_system]].
