literate-dotfiles/emacs-snippets.org

15 KiB

Doom Emacs Configuration

LaTeX

Coordinate

#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :coordinate
# --
\coordinate[${1:->}] (${2:name}) at (${3:pointcoordinate});
$0

Draw

#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :draw
# --
\draw[${1:->}] (${2:point1}) -- (${3:point2});
$0

Node

#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :node
# --
node[${1:below right}] (${2:name}) {${3:label}};
$0

Path

#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :path
# --
\path[${1}] (${2:point1}) -- (${3:point2});
$0

Matlab

Clear

#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :clear and close all
# --
clear; close all; clc;
$0

Function

#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :function
# --
function [${4:outputs}] = ${1:functionName}(${2:inputs}, ${3:opts_param})
% $1 - Description
%
% Syntax: $1($2, $3)
%
% Inputs:
%    - $2 -
%    - $3 - Optionals parameters: structure with the following fields:
%        -
%
% Outputs:
%    - $4 -

%% Default value for opts
opts = struct(...
    '${5:outputs}', ${6:default_value} ...
);

if exist('opts_param','var')
    for opt = fieldnames($3)'
        if sum(strcmp(fieldnames(opts), opt{1})) == 1
            opts.(opt{1}) = $3.(opt{1});
        else
            warning(sprintf('%s is not a valid option.', opt{1}));
        end
    end
end

$0

Org Mode

Begin

#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :LaTeX Environment
# --
\begin{${1:equation}}
$0
\end{$1}

Caption

#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Caption
# --
#+caption: $0

Block

#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Org-Mode Block
#key: block
# --
#+begin_${1:$$(let ((type (yas-choose-value '("src" "example" "quote" "verse" "center" "latex" "html" "ascii"))))
               (if type (concat type (if (equal type "src")
                                         (concat " " (yas-choose-value '("emacs-lisp" "latex" "python" "sh" "matlab")))))))}
$0
#+end_${1:$(car (split-string yas-text))}

Custom Box

#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Custom Box
# --
#+attr_latex: :options [$1]{${2:blue}}{${3:ams nodisplayskip}}
#+begin_cbox
$0
#+end_cbox

Latex Class

#name: latex-class
#key: lc
#expand-env: ((classes (mapcar 'car org-latex-classes)))
# --
#+latex_class: ${1:$$(yas-choose-value classes)}
$0

Bibliography with completion

#name: bibliography with completion
#key: bib
# --
bibliography:${1:$$(yas-choose-value (org-ref-find-bibliography))}

Cite

#name: org-ref cite link
#key: cite
# --
cite:${1:$$(completing-read
       "bibtex key: "
       (let ((bibtex-files (org-ref-find-bibliography)))(bibtex-global-key-alist)))}

Ref

#name: org-ref ref link with completion
#key: ref
# --
ref:${1:$$(completing-read "label: " (org-ref-get-labels))}

Beamer - CBOX

#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Beamer Custom Box
# --
,*** ${1:@@latex:@@}           :B_cbox:
,:PROPERTIES:
:BEAMER_env: cbox
:BEAMER_opt: {${2:blue}}{${3:ams nodisplayskip}}
:END:

$0

HTML Details

#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :details
# --

#+HTML: <details><summary>${1:Figure}</summary>
$0
#+HTML: </details>

Code

#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Code
# --
#+caption: ${1:Listing Caption}
#+label: lst:${2:listing_name}
,#+begin_src ${3:listing_language}
$0
,#+end_src

Equation

#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Equation
# --
#+name: eq:${1:equation_name}
\begin{equation}
$0
\end{equation}

Figure

#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Figure
# --
#+name: fig:${1:figure_name}
#+caption: ${2:Figure caption}
[[file:${3:figs/}$1.${4:pdf}]]
$0

Frac

#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :LaTeX Fraction
# --
\frac{$1}{$2} $0

Left

#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Left Right mathematical delimitations
# --
\left$1 $0 \right$2

Minipage

#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :minipage
# --
#+BEGIN_EXPORT latex
\begin{figure}[htbp]
\centering
\begin{minipage}[t]{0.49\linewidth}
#+END_EXPORT
#+attr_latex: :float nil :width 0.95\linewidth
$0
#+BEGIN_EXPORT latex
\end{minipage}%
\hfill%
\begin{minipage}[t]{0.49\linewidth}
#+END_EXPORT
#+attr_latex: :float nil :width 0.95\linewidth

#+BEGIN_EXPORT latex
\end{minipage}
\end{figure}
#+END_EXPORT

Minipage Figures

#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Minipage with Figures
# --
#+attr_latex: :options [t]{${3:0.5\linewidth}}
#+begin_minipage
#+name: fig:$1
#+caption: ${2:Caption}
#+attr_latex: ${4::width \linewidth} :float nil
[[file:figs/${1:figure_name}.pdf]]
#+end_minipage
\hfill
#+attr_latex: :options [t]{${7:0.5\linewidth}}
#+begin_minipage
#+name: fig:$5
#+caption: ${6:Caption}
#+attr_latex: ${8::width \linewidth} :float nil
[[file:figs/${5:figure_name}.pdf]]
#+end_minipage
$0

Wrap Figure

#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Wrap Figure
# --
,#+attr_latex: :options {${1:rl}}{${2:0.45\textwidth}}
,#+begin_wrapfigure
,#+attr_latex: :${3:width \linewidth}
[[file:figs/${4:figure_name.pdf}]]
,#+end_wrapfigure
$0

Multicolumn

#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Multcolumn
# --
#+attr_latex: :float multicolumn
$0

Subfigure

#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Subfigure
# --
#+name: fig:${1:figure_name}
#+caption: ${2:figure caption}
#+attr_latex: :environment subfigure :width 0.49\linewidth :align c
| file:${3:sub_fig_name}.${4:pdf}       | file:${5:sub_fig_name}.${6:pdf} |
| <<fig:$3>> ${7:sub figure caption}    | <<fig:$5>> ${8:sub figure caption}    |
$0

Table

#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Table
# --
#+name: tab:${1:table_name}
#+caption: ${2:Table caption}
#+attr_latex: :environment tabularx :width ${3:\linewidth} :align ${4:lXX}
#+attr_latex: :center t :booktabs t :float t
| $0  |   |   |
|---+---+---|
|   |   |   |

Tikz

#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Tikz figure
# --
,#+begin_src latex :file ${1:figure_name}.pdf :post pdf2svg(file=*this*, ext="png") :exports both
\begin{tikzpicture}
  $0
\end{tikzpicture}
,#+end_src

Tikzfig

#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Tikz Figure
# --
#+NAME: fig:${1:figure_name}
#+HEADER: :headers '("\\\\usepackage{tikz}" "\\\\usepackage{import}" "\\\\import{$HOME/Cloud/thesis/LaTeX/}{config.tex}")
#+HEADER: :imagemagick t :fit yes :iminoptions -scale 100% -density 150 :imoutoptions -quality 100
#+HEADER: :results raw replace :buffer no :eval no-export :exports both :mkdirp yes
#+HEADER: :output-dir ${2:figs}
,#+begin_src latex :file $1.pdf :post pdf2svg(file=*this*, ext="png") :exports both
\begin{tikzpicture}
  $0
\end{tikzpicture}
,#+end_src

#+NAME: fig:$1
#+CAPTION: ${3:Caption}
#+RESULTS:

Tikzheader

#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Tikz Header
# --
,* ${1:Title/Description of the figure}
,#+begin_src latex :file ${2:figure_name}.pdf :tangle figs/$2.tex :exports ${3:both}
\begin{tikzpicture}
  $0
\end{tikzpicture}
,#+end_src

#+name: fig:$2
#+caption: $1 ([[./figs/$2.png][png]], [[./figs/$2.pdf][pdf]], [[./figs/$2.tex][tex]]).
#+RESULTS:
[[file:./figs/$2.png]]

User-config

# -*- mode: snippet -*-
# name: user-config
# key: uc
# --
,#+begin_src emacs-lisp :tangle user-config.el
$1
,#+end_src

User-init

# -*- mode: snippet -*-
# name: user-init
# key: ui
# --
,#+begin_src emacs-lisp :tangle user-init.el
$1
,#+end_src
#+end_Sec

** Wrap
#+begin_src conf :tangle ~/.config/doom/snippets/org-mode/wrap
#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Wrap
# --
#+attr_latex: :float wrap
$0

Matlab Specific

Mconfig

#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Matlab-Configuration-Header
# --
#+PROPERTY: header-args:matlab  :session *MATLAB*
#+PROPERTY: header-args:matlab+ :tangle ${1:filename}.m
#+PROPERTY: header-args:matlab+ :comments org
#+PROPERTY: header-args:matlab+ :exports both
#+PROPERTY: header-args:matlab+ :results none
#+PROPERTY: header-args:matlab+ :eval no-export
#+PROPERTY: header-args:matlab+ :noweb yes
#+PROPERTY: header-args:matlab+ :mkdirp yes
#+PROPERTY: header-args:matlab+ :output-dir ${2:figs}
$0

Mdescription

#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Measurement-Description
# --
,* Measurement description
,** Setup                                                             :ignore:
*Setup*:

,** Goal                                                              :ignore:
*Goal*:

,** Measurements                                                      :ignore:
*Measurements*:

Three measurements are done:
| Measurement File        | Description                  |
|-------------------------+------------------------------|
| =mat/data_${1:001}.mat= | $2                           |

Each of the measurement =mat= file contains one =data= array with 3 columns:
| Column number | Description       |
|---------------+-------------------|
|             1 | $3                |
|             2 | $4                |
|             3 | Time              |

$0

Mfigure

#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Matlab-Figure
# --
,#+begin_src matlab :tangle no :exports results :results file replace
   exportFig('figs/${1:filename}.pdf', 'width', '${2:full}', 'height', '${3:full}');
,#+end_src

,#+name: fig:$1
,#+caption: $0
,#+RESULTS:
[[file:figs/$1.png]]

Mfunction

#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Matlab-Function
# --
,* ${1:Function Name}
:PROPERTIES:
:header-args:matlab+: :tangle src/${2:matlab_file_name}.m
:header-args:matlab+: :comments none :mkdirp yes :eval no
:END:
<<sec:$2>>

This Matlab function is accessible [[file:src/$2.m][here]].

,#+begin_src matlab
function [${4:in_data}] = $2(${3:in_data})
% $2 - $0
%
% Syntax: [$4] = $2($3)
%
% Inputs:
%    - $3 -
%
% Outputs:
%    - $4 -

end
,#+end_src

Mheader

#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Matlab-Header
# --
,* ${1:Heading Name}
:PROPERTIES:
:header-args:matlab+: :tangle matlab/${2:matlab_file_name}.m
:header-args:matlab+: :comments org :mkdirp yes
:END:
<<sec:$2>>

,** ZIP file containing the data and matlab files                     :ignore:
,#+begin_src bash :exports none :results none
if [ matlab/$2.m -nt data/$2.zip ]; then
  cp matlab/$2.m $2.m;
  zip data/$2 \
      mat/data.mat \
      $2.m
  rm $2.m;
fi
,#+end_src

,#+begin_note
All the files (data and Matlab scripts) are accessible [[file:data/$2.zip][here]].
,#+end_note

$0

Minit

#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Matlab-Init
# --
,** 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

$0

Mtable

#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Matlab-Table
# --
,#+begin_src matlab :exports results :results value table replace :tangle no :post addhdr(*this*)
data2orgtable(${1:data}, {${2:'rowlabel'}}, {${3:'collabel'}}, ' %.1f ');
,#+end_src
$0

Mvalue

#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Matlab-Value
# --
,#+begin_src matlab :results value replace :exports results :tangle no
sprintf('x = %.2g', x);
,#+end_src
$0

Binary

#contributor : Thomas Dehaeze <dehaeze.thomas@gmail.com>
#name :Binary
# --
,* =${1:binary-name}= - ${2:Description}
:PROPERTIES:
:CUSTOM_ID: $1
:END:

,#+begin_src bash :tangle ~/.local/bin/$1
$0
,#+end_src