From 0cc5ad5eb22571cf361e4b92f3472ca0891aefba Mon Sep 17 00:00:00 2001 From: Thomas Dehaeze Date: Thu, 16 Apr 2020 15:33:59 +0200 Subject: [PATCH] Add library of babel --- dotfiles/doom.org | 2 +- dotfiles/emacs-library-babel.org | 71 ++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 dotfiles/emacs-library-babel.org diff --git a/dotfiles/doom.org b/dotfiles/doom.org index 528c4cb..274cabd 100644 --- a/dotfiles/doom.org +++ b/dotfiles/doom.org @@ -1791,7 +1791,7 @@ Add all named source blocks to =org-babel-library-of-babel=. #+begin_src emacs-lisp (after! org - (org-babel-lob-ingest "~/Cloud/thesis/org-mode/org-babel-tutorial/org-babel-library.org")) + (org-babel-lob-ingest "~/.config/literate-dotfiles/dotfiles/emacs-library-babel.org")) #+end_src diff --git a/dotfiles/emacs-library-babel.org b/dotfiles/emacs-library-babel.org new file mode 100644 index 0000000..49dbd88 --- /dev/null +++ b/dotfiles/emacs-library-babel.org @@ -0,0 +1,71 @@ +#+TITLE: My Own Library of Babel + +* =get-password= - Get Password from =pass= + +#+name: get-password +#+begin_src bash :var passname=""" + pass $passname | sed -n 1p +#+end_src + +* =pdf2svg= - Export to pdf/png/svg at the same time + +#+name: pdf2svg +#+begin_src sh :var file="" :var ext="svg" :results output + _mydir="$(pwd)"; + file=$(echo "$file" | cut -f 2- -d ':'); + _figdir=$(dirname "$file"); + cd $_figdir; + filename=$(echo "${file##*/}" | cut -f 1 -d '.'); + pdftocairo -png -transp -singlefile "$filename.pdf"; + pdftocairo -svg "$filename.pdf"; + cd "$_mydir"; + echo "[[file:$_figdir/$filename.$ext]]" +#+end_src + +* =addhdr= - Add hline to tables + +#+name: addhdr +#+begin_src emacs-lisp :var tbl="" + (cons (car tbl) (cons 'hline (cdr tbl))) +#+end_src + +* Matlab Related +** =matlab-dir= Go to current directory + +#+name: matlab-dir +#+begin_src matlab :tangle no :results none :exports none :var current_dir="" + %% Go to current Directory + cd(current_dir); + + %% Initialize ans with org-babel + ans = 0; +#+end_src + +** =matlab-init= Initialize matlab + +#+name: matlab-init +#+begin_src matlab :results none :exports none + %% Clear Workspace and Close figures + clear; close all; clc; + + %% Intialize Laplace variable + s = zpk('s'); +#+end_src + +** =plt-matlab= Plot figures +Some variable can be set by block that expands this org source code block: +- =path=: specify the path of the figure including the file extension. Can be relative or absolute. If not provided, it will create the figure in the =/tmp= folder +- =fig_size=: can specify the size of the figure. If not specify, default will be applied. + +#+name: plt-matlab +#+begin_src matlab :results value raw replace :exports code :var filepath="" :var figsize="normal-normal" + if ~exist('filepath') || length(filepath) < 2 + symbols = ['a':'z' 'A':'Z' '0':'9']; + random_string = symbols(randi(numel(symbols),[1 5])); + filepath = ['/tmp/matlab-fig-', random_string]; + end + + size_strings = strsplit(figsize, '-'); + + ans = exportFig(filepath, 'width', size_strings{1}, 'height', size_strings{2}); +#+end_src