diff --git a/dotfiles/doom.org b/dotfiles/doom.org index 394c64b..ef28e3f 100644 --- a/dotfiles/doom.org +++ b/dotfiles/doom.org @@ -273,16 +273,16 @@ Display the real size of images and not the one set with =attr_latex: :width \li (after! org ;; Tags with fast selection keys (setq org-todo-keywords '( - (sequence "TODO(t)" "NEXT(n)" "MAIL(m)" "|" "DONE(d)") - (sequence "READ(r)" "BKMK(b)" "EXER(x)" "|" "DONE(d)") - (sequence "WAIT(w@/!)" "SDAY(s)" "|" "CANC(c@/!)") - (sequence "QUES(q)" "|" "ANSW(a)") - (sequence "EXAM(e)" "IDEA(i)" "|") - )) + (sequence "TODO(t)" "NEXT(n)" "MAIL(m)" "|" "DONE(d)") + (sequence "READ(r)" "BKMK(b)" "EXER(x)" "|" "DONE(d)") + (sequence "WAIT(w@/!)" "SDAY(s)" "|" "CANC(c@/!)") + (sequence "QUES(q)" "|" "ANSW(a)") + (sequence "EXAM(e)" "IDEA(i)" "|") + )) ;; Display of the keywords (setq org-todo-keyword-faces - '(("TODO" . (:foreground "#cc241d" :weight bold)) ;; red + '(("TODO" . (:foreground "#cc241d" :weight bold)) ;; red ("EXER" . (:foreground "#cc241d" :weight bold)) ;; red ("NEXT" . (:foreground "#cc241d" :weight bold)) ;; red ("MAIL" . (:foreground "#cc241d" :weight bold)) ;; red @@ -305,48 +305,48 @@ https://gist.github.com/Fuco1/e86fb5e0a5bb71ceafccedb5ca22fcfb #+begin_src emacs-lisp (after! org (defadvice org-archive-subtree (around fix-hierarchy activate) - (let* ((fix-archive-p (and (not current-prefix-arg) - (not (use-region-p)))) - (location (org-archive--compute-location org-archive-location)) - (afile (car location)) - (offset (if (= 0 (length (cdr location))) - 1 - (1+ (string-match "[^*]" (cdr location))))) - (buffer (or (find-buffer-visiting afile) (find-file-noselect afile)))) + (let* ((fix-archive-p (and (not current-prefix-arg) + (not (use-region-p)))) + (location (org-archive--compute-location org-archive-location)) + (afile (car location)) + (offset (if (= 0 (length (cdr location))) + 1 + (1+ (string-match "[^*]" (cdr location))))) + (buffer (or (find-buffer-visiting afile) (find-file-noselect afile)))) ad-do-it (when fix-archive-p - (with-current-buffer buffer + (with-current-buffer buffer (goto-char (point-max)) (while (> (org-current-level) offset) (org-up-heading-safe)) (let* ((olpath (org-entry-get (point) "ARCHIVE_OLPATH")) - (path (and olpath (split-string olpath "/"))) - (level offset) - tree-text) - (when olpath + (path (and olpath (split-string olpath "/"))) + (level offset) + tree-text) + (when olpath (org-mark-subtree) (setq tree-text (buffer-substring (region-beginning) (region-end))) (let (this-command) (org-cut-subtree)) (goto-char (point-min)) (save-restriction - (widen) - (-each path + (widen) + (-each path (lambda (heading) - (if (re-search-forward - (rx-to-string + (if (re-search-forward + (rx-to-string `(: bol (repeat ,level "*") (1+ " ") ,heading)) nil t) - (org-narrow-to-subtree) + (org-narrow-to-subtree) (goto-char (point-max)) (unless (looking-at "^") - (insert "\n")) + (insert "\n")) (insert (make-string level ?*) " " heading "\n")) - (cl-incf level))) - (widen) - (org-end-of-subtree t t) - (org-paste-subtree level tree-text)))))))) - ) + (cl-incf level))) + (widen) + (org-end-of-subtree t t) + (org-paste-subtree level tree-text)))))))) + ) #+end_src ** Org Agenda @@ -375,12 +375,12 @@ https://gist.github.com/Fuco1/e86fb5e0a5bb71ceafccedb5ca22fcfb (setq org-agenda-window-setup 'current-window) (setq org-agenda-prefix-format - '((agenda . " %-12:c %?-12t% s") - (todo . "") ;; Don't show the filename for reading agenda - (tags . " %-12:c") - (search . " %-12:c")) + '((agenda . " %-12:c %?-12t% s") + (todo . "") ;; Don't show the filename for reading agenda + (tags . " %-12:c") + (search . " %-12:c")) + ) ) - ) #+end_src *** Org Agenda Custom Views @@ -482,21 +482,21 @@ https://emacs.stackexchange.com/questions/3844/good-methods-for-setting-up-alarm (after! org-agenda (setq appt-message-warning-time 5) (defun tdh-org-agenda-to-appt () - (interactive) - (setq appt-time-msg-list nil) - (org-agenda-to-appt)) + (interactive) + (setq appt-time-msg-list nil) + (org-agenda-to-appt)) (tdh-org-agenda-to-appt) - ; Display appointments as a window manager notification + ; Display appointments as a window manager notification (setq appt-disp-window-function 'tdh-appt-display) (setq appt-delete-window-function (lambda () t)) (setq tdh-appt-notification-app (concat (getenv "HOME") "/bin/appt-notification")) (defun tdh-appt-display (min-to-app new-time msg) - (if (atom min-to-app) - (start-process "tdh-appt-notification-app" nil tdh-appt-notification-app min-to-app msg) - (dolist (i (number-sequence 0 (1- (length min-to-app)))) - (start-process "tdh-appt-notification-app" nil tdh-appt-notification-app (nth i min-to-app) (nth i msg))))) + (if (atom min-to-app) + (start-process "tdh-appt-notification-app" nil tdh-appt-notification-app min-to-app msg) + (dolist (i (number-sequence 0 (1- (length min-to-app)))) + (start-process "tdh-appt-notification-app" nil tdh-appt-notification-app (nth i min-to-app) (nth i msg))))) ) #+end_src @@ -595,10 +595,24 @@ Documentation: ;; Authorize BIND to set local variables (setq org-export-allow-bind-keywords t) + ;; Use doc instead of odt (setq org-odt-preferred-output-format "doc") ) #+end_src +*** Defaults +#+begin_src emacs-lisp + (after! org + (setq org-export-with-author t) + (setq org-export-with-creator nil) + (setq org-export-with-date t) + (setq org-export-with-toc t) + (setq org-export-with-drawers nil) + (setq org-export-with-sub-superscripts nil) + (setq org-export-with-todo-keywords nil) + ) +#+end_src + *** Do not export headline with the =:ignore:= tag #+begin_src emacs-lisp ;; Used to not export headings with :ignore: tag @@ -607,221 +621,201 @@ Documentation: (ox-extras-activate '(ignore-headlines))) #+end_src -*** Ox Latex Subfigure package -#+begin_src emacs-lisp - (use-package! ox-latex-subfigure - :after org - :config (require 'ox-latex-subfigure)) -#+end_src - -*** Clear page before heading -https://emacs.stackexchange.com/questions/30575/adding-latex-newpage-before-a-heading/30892 - +** HTML Export +*** HTML Defaults #+begin_src emacs-lisp (after! org - (defun org/get-headline-string-element (headline backend info) - (let ((prop-point (next-property-change 0 headline))) - (if prop-point (plist-get (text-properties-at prop-point headline) :parent)))) + ;; (setq org-html-head-extra (concat + ;; "\n" + ;; "\n" + ;; "\n" + ;; "\n" + ;; "\n" + ;; "\n" + ;; "\n")) - (defun org/ensure-latex-clearpage (headline backend info) - (when (org-export-derived-backend-p backend 'latex) - (let ((elmnt (org/get-headline-string-element headline backend info))) - (when (and elmnt (org-element-property :CLEARPAGE elmnt)) - (concat "\\clearpage\n" headline))))) + ;; cleans up anything that would have been in there. + (setq org-html-head nil) + (setq org-html-head-include-default-style nil) + (setq org-html-head-include-scripts nil) - (add-to-list 'org-export-filter-headline-functions - 'org/ensure-latex-clearpage) + (setq org-html-viewport nil) + + (setq org-html-html5-fancy t) + (setq org-html-doctype "xhtml-strict") + + (setq org-html-wrap-src-lines nil) + + ;; Export with css class instead of inline css + (setq org-html-htmlize-output-type 'css) ) #+end_src -*** HTML Export -**** MathJax +*** MathJax #+begin_src emacs-lisp (after! org (setq org-html-mathjax-template - " - ") - ) -#+end_src + ") -#+begin_src emacs-lisp - (after! org (setq org-html-mathjax-options - '((path "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js") - (scale "100") - (align "center") - (font "TeX") - (linebreaks "false") - (autonumber "AMS") - (indent "0em") - (multlinewidth "85%") - (tagindent ".8em") - (tagside "right"))) - ) + '((path "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js") + (scale "100") + (align "center") + (font "TeX") + (linebreaks "false") + (autonumber "AMS") + (indent "0em") + (multlinewidth "85%") + (tagindent ".8em") + (tagside "right"))) + ) #+end_src -**** Export with css class instead of inline css -#+begin_src emacs-lisp - (after! org - (setq org-html-htmlize-output-type 'css)) -#+end_src - -**** TODO MP4 movies -#+begin_src emacs-lisp :tangle no - (after! org - (setq org-html-html5-fancy t) - (setq org-html-doctype "xhtml-strict") - ) -#+end_src - -**** TODO Ensuring useful HTML Anchors +*** TODO Ensuring useful HTML Anchors - [ ] https://github.com/alhassy/emacs.d - [ ] https://github.com/alphapapa/unpackaged.el#export-to-html-with-useful-anchors This is not working #+begin_src emacs-lisp :tangle no -(define-minor-mode unpackaged/org-export-html-with-useful-ids-mode - "Attempt to export Org as HTML with useful link IDs. -Instead of random IDs like \"#orga1b2c3\", use heading titles, -made unique when necessary." - :global t - (if unpackaged/org-export-html-with-useful-ids-mode - (advice-add #'org-export-get-reference :override #'unpackaged/org-export-get-reference) - (advice-remove #'org-export-get-reference #'unpackaged/org-export-get-reference))) + (define-minor-mode unpackaged/org-export-html-with-useful-ids-mode + "Attempt to export Org as HTML with useful link IDs. + Instead of random IDs like \"#orga1b2c3\", use heading titles, + made unique when necessary." + :global t + (if unpackaged/org-export-html-with-useful-ids-mode + (advice-add #'org-export-get-reference :override #'unpackaged/org-export-get-reference) + (advice-remove #'org-export-get-reference #'unpackaged/org-export-get-reference))) -(defun unpackaged/org-export-get-reference (datum info) - "Like `org-export-get-reference', except uses heading titles instead of random numbers." - (let ((cache (plist-get info :internal-references))) - (or (car (rassq datum cache)) - (let* ((crossrefs (plist-get info :crossrefs)) - (cells (org-export-search-cells datum)) - ;; Preserve any pre-existing association between - ;; a search cell and a reference, i.e., when some - ;; previously published document referenced a location - ;; within current file (see - ;; `org-publish-resolve-external-link'). - ;; - ;; However, there is no guarantee that search cells are - ;; unique, e.g., there might be duplicate custom ID or - ;; two headings with the same title in the file. - ;; - ;; As a consequence, before re-using any reference to - ;; an element or object, we check that it doesn't refer - ;; to a previous element or object. - (new (or (cl-some - (lambda (cell) - (let ((stored (cdr (assoc cell crossrefs)))) - (when stored - (let ((old (org-export-format-reference stored))) - (and (not (assoc old cache)) stored))))) - cells) - (when (org-element-property :raw-value datum) - ;; Heading with a title - (unpackaged/org-export-new-title-reference datum cache)) - ;; NOTE: This probably breaks some Org Export - ;; feature, but if it does what I need, fine. - (org-export-format-reference - (org-export-new-reference cache)))) - (reference-string new)) - ;; Cache contains both data already associated to - ;; a reference and in-use internal references, so as to make - ;; unique references. - (dolist (cell cells) (push (cons cell new) cache)) - ;; Retain a direct association between reference string and - ;; DATUM since (1) not every object or element can be given - ;; a search cell (2) it permits quick lookup. - (push (cons reference-string datum) cache) - (plist-put info :internal-references cache) - reference-string)))) + (defun unpackaged/org-export-get-reference (datum info) + "Like `org-export-get-reference', except uses heading titles instead of random numbers." + (let ((cache (plist-get info :internal-references))) + (or (car (rassq datum cache)) + (let* ((crossrefs (plist-get info :crossrefs)) + (cells (org-export-search-cells datum)) + ;; Preserve any pre-existing association between + ;; a search cell and a reference, i.e., when some + ;; previously published document referenced a location + ;; within current file (see + ;; `org-publish-resolve-external-link'). + ;; + ;; However, there is no guarantee that search cells are + ;; unique, e.g., there might be duplicate custom ID or + ;; two headings with the same title in the file. + ;; + ;; As a consequence, before re-using any reference to + ;; an element or object, we check that it doesn't refer + ;; to a previous element or object. + (new (or (cl-some + (lambda (cell) + (let ((stored (cdr (assoc cell crossrefs)))) + (when stored + (let ((old (org-export-format-reference stored))) + (and (not (assoc old cache)) stored))))) + cells) + (when (org-element-property :raw-value datum) + ;; Heading with a title + (unpackaged/org-export-new-title-reference datum cache)) + ;; NOTE: This probably breaks some Org Export + ;; feature, but if it does what I need, fine. + (org-export-format-reference + (org-export-new-reference cache)))) + (reference-string new)) + ;; Cache contains both data already associated to + ;; a reference and in-use internal references, so as to make + ;; unique references. + (dolist (cell cells) (push (cons cell new) cache)) + ;; Retain a direct association between reference string and + ;; DATUM since (1) not every object or element can be given + ;; a search cell (2) it permits quick lookup. + (push (cons reference-string datum) cache) + (plist-put info :internal-references cache) + reference-string)))) -(defun unpackaged/org-export-new-title-reference (datum cache) - "Return new reference for DATUM that is unique in CACHE." - (cl-macrolet ((inc-suffixf (place) - `(progn - (string-match (rx bos - (minimal-match (group (1+ anything))) - (optional "--" (group (1+ digit))) - eos) - ,place) - ;; HACK: `s1' instead of a gensym. - (-let* (((s1 suffix) (list (match-string 1 ,place) - (match-string 2 ,place))) - (suffix (if suffix - (string-to-number suffix) - 0))) - (setf ,place (format "%s--%s" s1 (cl-incf suffix))))))) - (let* ((title (org-element-property :raw-value datum)) - (ref (url-hexify-string (substring-no-properties title))) - (parent (org-element-property :parent datum))) - (while (--any (equal ref (car it)) - cache) - ;; Title not unique: make it so. - (if parent - ;; Append ancestor title. - (setf title (concat (org-element-property :raw-value parent) - "--" title) - ref (url-hexify-string (substring-no-properties title)) - parent (org-element-property :parent parent)) - ;; No more ancestors: add and increment a number. - (inc-suffixf ref))) - ref))) + (defun unpackaged/org-export-new-title-reference (datum cache) + "Return new reference for DATUM that is unique in CACHE." + (cl-macrolet ((inc-suffixf (place) + `(progn + (string-match (rx bos + (minimal-match (group (1+ anything))) + (optional "--" (group (1+ digit))) + eos) + ,place) + ;; HACK: `s1' instead of a gensym. + (-let* (((s1 suffix) (list (match-string 1 ,place) + (match-string 2 ,place))) + (suffix (if suffix + (string-to-number suffix) + 0))) + (setf ,place (format "%s--%s" s1 (cl-incf suffix))))))) + (let* ((title (org-element-property :raw-value datum)) + (ref (url-hexify-string (substring-no-properties title))) + (parent (org-element-property :parent datum))) + (while (--any (equal ref (car it)) + cache) + ;; Title not unique: make it so. + (if parent + ;; Append ancestor title. + (setf title (concat (org-element-property :raw-value parent) + "--" title) + ref (url-hexify-string (substring-no-properties title)) + parent (org-element-property :parent parent)) + ;; No more ancestors: add and increment a number. + (inc-suffixf ref))) + ref))) #+end_src -**** TODO Folded Drawers +*** TODO Folded Drawers Adapt this from https://github.com/alhassy/emacs.d to do something similar for source blocks. #+begin_src emacs-lisp :tangle no -(defun my/org-drawer-format (name contents) - "Export to HTML the drawers named with prefix ‘fold_’, ignoring case. + (defun my/org-drawer-format (name contents) + "Export to HTML the drawers named with prefix ‘fold_’, ignoring case. -The resulting drawer is a ‘code-details’ and so appears folded; -the user clicks it to see the information therein. -Henceforth, these are called ‘fold drawers’. + The resulting drawer is a ‘code-details’ and so appears folded; + the user clicks it to see the information therein. + Henceforth, these are called ‘fold drawers’. -Drawers without such a prefix may be nonetheless exported if their -body contains ‘:export: t’ ---this switch does not appear in the output. -Thus, we are biased to generally not exporting non-fold drawers. + Drawers without such a prefix may be nonetheless exported if their + body contains ‘:export: t’ ---this switch does not appear in the output. + Thus, we are biased to generally not exporting non-fold drawers. -One may suspend export of fold drawers by having ‘:export: nil’ -in their body definition. + One may suspend export of fold drawers by having ‘:export: nil’ + in their body definition. -Fold drawers naturally come with a title. -Either it is specfied in the drawer body by ‘:title: ⋯’, -or otherwise the drawer's name is used with all underscores replaced -by spaces. -" - (let* ((contents′ (replace-regexp-in-string ":export:.*\n?" "" contents)) - (fold? (s-prefix? "fold_" name 'ignore-case)) - (export? (string-match ":export:\s+t" contents)) - (not-export? (string-match ":export:\s+nil" contents)) - (title′ (and (string-match ":title:\\(.*\\)\n" contents) - (match-string 1 contents)))) + Fold drawers naturally come with a title. + Either it is specfied in the drawer body by ‘:title: ⋯’, + or otherwise the drawer's name is used with all underscores replaced + by spaces. + " + (let* ((contents′ (replace-regexp-in-string ":export:.*\n?" "" contents)) + (fold? (s-prefix? "fold_" name 'ignore-case)) + (export? (string-match ":export:\s+t" contents)) + (not-export? (string-match ":export:\s+nil" contents)) + (title′ (and (string-match ":title:\\(.*\\)\n" contents) + (match-string 1 contents)))) - ;; Ensure we have a title. - (unless title′ (setq title′ (s-join " " (cdr (s-split "_" name))))) + ;; Ensure we have a title. + (unless title′ (setq title′ (s-join " " (cdr (s-split "_" name))))) - ;; Output - (cond - ((and export? (not fold?)) contents′) - (not-export? nil) - (fold? - (thread-last contents′ - (replace-regexp-in-string ":title:.*\n" "") - (format "
- %s - %s
" title′)))))) + ;; Output + (cond + ((and export? (not fold?)) contents′) + (not-export? nil) + (fold? + (thread-last contents′ + (replace-regexp-in-string ":title:.*\n" "") + (format "
+ %s + %s
" title′)))))) -(setq org-html-format-drawer-function 'my/org-drawer-format) + (setq org-html-format-drawer-function 'my/org-drawer-format) #+end_src ** Org LaTeX @@ -829,7 +823,7 @@ by spaces. #+begin_src emacs-lisp (after! org ;; Highligh latex parts in org mode - (setq org-highlight-latex-and-related '(native)) + (setq org-highlight-latex-and-related '(latex script entities)) ;; Use F9 to globally generate all the latex fragments (map! :map org-mode-map @@ -871,7 +865,7 @@ by spaces. ;; Use imagemagick/dvisvgm to generate png from pdf (setq org-preview-latex-default-process 'dvisvgm) - + ;; Don't change the font size for subscripts and superscripts in latex fragments. ;; This cause the orgmode tables not to be well aligned. (setq font-latex-fontify-script nil) @@ -879,7 +873,7 @@ by spaces. ;; Colors of latex fragments (setq org-format-latex-options (plist-put org-format-latex-options :foreground 'default)) (setq org-format-latex-options (plist-put org-format-latex-options :background (face-background 'fringe))) - ) + ) #+end_src *** LaTeX Classes @@ -943,17 +937,43 @@ by spaces. ) #+end_src +*** Ox Latex Subfigure package +#+begin_src emacs-lisp + (use-package! ox-latex-subfigure + :after org + :config (require 'ox-latex-subfigure)) +#+end_src + +*** Clear page before heading +https://emacs.stackexchange.com/questions/30575/adding-latex-newpage-before-a-heading/30892 + +#+begin_src emacs-lisp + (after! org + (defun org/get-headline-string-element (headline backend info) + (let ((prop-point (next-property-change 0 headline))) + (if prop-point (plist-get (text-properties-at prop-point headline) :parent)))) + + (defun org/ensure-latex-clearpage (headline backend info) + (when (org-export-derived-backend-p backend 'latex) + (let ((elmnt (org/get-headline-string-element headline backend info))) + (when (and elmnt (org-element-property :CLEARPAGE elmnt)) + (concat "\\clearpage\n" headline))))) + + (add-to-list 'org-export-filter-headline-functions + 'org/ensure-latex-clearpage) + ) +#+end_src + *** Default added packages #+begin_src emacs-lisp (after! org - ;; Add packages by default (add-to-list 'org-latex-packages-alist '("" "siunitx" t)) (add-to-list 'org-latex-packages-alist '("" "array" t)) (add-to-list 'org-latex-packages-alist '("" "tabularx" t)) (add-to-list 'org-latex-packages-alist '("" "booktabs" t)) (add-to-list 'org-latex-packages-alist '("" "bm" t)) (add-to-list 'org-latex-packages-alist '("most" "tcolorbox" t)) - ) + ) #+end_src *** Some configurations @@ -976,8 +996,8 @@ by spaces. ;; Command used when exporting to pdf (setq org-latex-pdf-process - '("latexmk -cd -pdflatex=\"pdflatex -synctex=1 -shell-escape -interaction nonstopmode -output-directory %o\" -pdf -bibtex -f %f")) - ) + '("latexmk -cd -pdflatex=\"pdflatex -synctex=1 -shell-escape -interaction nonstopmode -output-directory %o\" -pdf -bibtex -f %f")) + ) #+end_src *** Beamer @@ -985,14 +1005,14 @@ Bold Text #+begin_src emacs-lisp (after! org (defun tdh-my-beamer-bold (contents backend info) - (when (eq backend 'beamer) + (when (eq backend 'beamer) (replace-regexp-in-string - (concat "\\`\\\\" "[A-Za-z0-9]+") ;; If not, orgmode is crazy... - "\\\\textbf" - contents))) + (concat "\\`\\\\" "[A-Za-z0-9]+") ;; If not, orgmode is crazy... + "\\\\textbf" + contents))) (add-to-list 'org-export-filter-bold-functions 'tdh-my-beamer-bold) - ) + ) #+end_src @@ -1000,17 +1020,17 @@ Special Environments - [ ] Make some comment those special environments #+begin_src emacs-lisp (after! org - (add-to-list 'org-beamer-environments-extra - '("cbox" ;; Name of environment - "m" ;; Selection key - "\\onslide%a{\\begin{cbox}[%h]%O" - "\\end{cbox}}\\vspace{0.5em}")) - (add-to-list 'org-beamer-environments-extra - '("csubbox" ;; Name of environment - "M" ;; Selection key - "\\onslide%a{\\tcbsubtitle{%h}" - "}")) - ) + (add-to-list 'org-beamer-environments-extra + '("cbox" ;; Name of environment + "m" ;; Selection key + "\\onslide%a{\\begin{cbox}[%h]%O" + "\\end{cbox}}\\vspace{0.5em}")) + (add-to-list 'org-beamer-environments-extra + '("csubbox" ;; Name of environment + "M" ;; Selection key + "\\onslide%a{\\tcbsubtitle{%h}" + "}")) + ) #+end_src *** TODO Custom Export - Add Page and Label for LaTeX export @@ -1080,48 +1100,48 @@ https://emacs.stackexchange.com/questions/156/emacs-function-to-convert-an-arbit #+begin_src emacs-lisp (after! org (defun org-renumber-environment (orig-func &rest args) - "A function to inject numbers in LaTeX fragment previews." - (let ((results '()) - (counter -1) - (numberp)) + "A function to inject numbers in LaTeX fragment previews." + (let ((results '()) + (counter -1) + (numberp)) (setq results (loop for (begin . env) in - (org-element-map (org-element-parse-buffer) 'latex-environment - (lambda (env) - (cons - (org-element-property :begin env) - (org-element-property :value env)))) - collect - (cond - ((and (string-match "\\\\begin{equation}" env) - (not (string-match "\\\\tag{" env))) - (incf counter) - (cons begin counter)) - ((string-match "\\\\begin{align}" env) - (prog2 - (incf counter) - (cons begin counter) - (with-temp-buffer - (insert env) - (goto-char (point-min)) - ;; \\ is used for a new line. Each one leads to a number - (incf counter (count-matches "\\\\$")) - ;; unless there are nonumbers. - (goto-char (point-min)) - (decf counter (count-matches "\\nonumber"))))) - (t - (cons begin nil))))) + (org-element-map (org-element-parse-buffer) 'latex-environment + (lambda (env) + (cons + (org-element-property :begin env) + (org-element-property :value env)))) + collect + (cond + ((and (string-match "\\\\begin{equation}" env) + (not (string-match "\\\\tag{" env))) + (incf counter) + (cons begin counter)) + ((string-match "\\\\begin{align}" env) + (prog2 + (incf counter) + (cons begin counter) + (with-temp-buffer + (insert env) + (goto-char (point-min)) + ;; \\ is used for a new line. Each one leads to a number + (incf counter (count-matches "\\\\$")) + ;; unless there are nonumbers. + (goto-char (point-min)) + (decf counter (count-matches "\\nonumber"))))) + (t + (cons begin nil))))) (when (setq numberp (cdr (assoc (point) results))) - (setf (car args) - (concat - (format "\\setcounter{equation}{%s}\n" numberp) - (car args))))) + (setf (car args) + (concat + (format "\\setcounter{equation}{%s}\n" numberp) + (car args))))) - (apply orig-func args)) + (apply orig-func args)) (advice-add 'org-create-formula-image :around #'org-renumber-environment) - ) + ) #+end_src ** LaTeX macro both for LaTeX and HTML export @@ -1150,165 +1170,6 @@ https://www.reddit.com/r/orgmode/comments/7u2n0h/tip_for_defining_latex_macros_f #+end_src -** TODO View PDF in org mode -#+begin_src emacs-lisp :tangle no -(defun tdh-org-include-img-from-pdf (&rest _) - "Convert pdf files to image files in org-mode bracket links. - # ()convertfrompdf:t # This is a special comment; tells that the upcoming - # link points to the to-be-converted-to file. - # If you have a foo.pdf that you need to convert to foo.png, use the - # foo.png file name in the link. - [[./foo.png]] -" - (interactive) - (if (executable-find "convert") - (save-excursion - (goto-char (point-min)) - (while (re-search-forward "^[ \t]*#\\s-+()convertfrompdf\\s-*:\\s-*t" - nil :noerror) - ;; Keep on going to the next line till it finds a line with bracketed - ;; file link. - (while (progn - (forward-line 1) - (not (looking-at org-bracket-link-regexp)))) - ;; Get the sub-group 1 match, the link, from `org-bracket-link-regexp' - (let ((link (match-string-no-properties 1))) - (when (stringp link) - (let* ((imgfile (expand-file-name (file-name-sans-extension link))) - (pdffile (expand-file-name - (concat imgfile - "." "pdf"))) - (cmd (concat "pdftocairo -png -transp -singlefile " - pdffile " " imgfile))) - - (message "%s" imgfile) - (when (and (file-readable-p pdffile) - (file-newer-than-file-p pdffile imgfile)) - ;; This block is executed only if pdffile is newer than - ;; imgfile or if imgfile does not exist. - (shell-command cmd) - (message "%s" cmd))))))) - (user-error "`convert' executable (part of Imagemagick) is not found"))) - (add-hook 'org-export-before-processing-hook #'tdh-org-include-img-from-pdf) -#+end_src - -#+begin_src emacs-lisp :tangle no - (add-to-list 'image-type-file-name-regexps '("\\.pdf\\'" . imagemagick)) - (add-to-list 'image-file-name-extensions "pdf") - (setq imagemagick-types-inhibit (remove 'PDF imagemagick-types-inhibit)) -#+end_src - -#+begin_src emacs-lisp :tangle no - (defun tdh-latex-filter-nobreaks (text backend info) - "Ensure \" \" are properly handled in LaTeX export." - (when (org-export-derived-backend-p backend 'latex) - (replace-regexp-in-string " " "~" text))) - - (add-to-list 'org-export-filter-plain-text-functions - 'tdh-latex-filter-nobreaks) -#+end_src - -#+begin_src emacs-lisp :tangle no -(setq image-file-name-extensions - (quote - ("png" "jpeg" "jpg" "gif" "tiff" "tif" "xbm" "xpm" "pbm" "pgm" "ppm" "pnm" "svg" "pdf" "bmp"))) - -(setq org-imagemagick-display-command "convert -density 600 \"%s\" -thumbnail \"%sx%s>\" \"%s\"") -(defun org-display-inline-images (&optional include-linked refresh beg end) - "Display inline images. -Normally only links without a description part are inlined, because this -is how it will work for export. When INCLUDE-LINKED is set, also links -with a description part will be inlined. This -can be nice for a quick -look at those images, but it does not reflect what exported files will look -like. -When REFRESH is set, refresh existing images between BEG and END. -This will create new image displays only if necessary. -BEG and END default to the buffer boundaries." - (interactive "P") - (unless refresh - (org-remove-inline-images) - (if (fboundp 'clear-image-cache) (clear-image-cache))) - (save-excursion - (save-restriction - (widen) - (setq beg (or beg (point-min)) end (or end (point-max))) - (goto-char beg) - (let ((re (concat "\\[\\[\\(\\(file:\\)\\|\\([./~]\\)\\)\\([^]\n]+?" - (substring (org-image-file-name-regexp) 0 -2) - "\\)\\]" (if include-linked "" "\\]"))) - old file ov img) - (while (re-search-forward re end t) - (setq old (get-char-property-and-overlay (match-beginning 1) - 'org-image-overlay) - file (expand-file-name - (concat (or (match-string 3) "") (match-string 4)))) - (when (file-exists-p file) - (let ((file-thumb (format "%s%s_thumb.png" (file-name-directory file) (file-name-base file)))) - (if (file-exists-p file-thumb) - (let ((thumb-time (nth 5 (file-attributes file-thumb 'string))) - (file-time (nth 5 (file-attributes file 'string)))) - (if (time-less-p thumb-time file-time) - (shell-command (format org-imagemagick-display-command - file org-image-actual-width org-image-actual-width file-thumb) nil nil))) - (shell-command (format org-imagemagick-display-command - file org-image-actual-width org-image-actual-width file-thumb) nil nil)) - (if (and (car-safe old) refresh) - (image-refresh (overlay-get (cdr old) 'display)) - (setq img (save-match-data (create-image file-thumb))) - (when img - (setq ov (make-overlay (match-beginning 0) (match-end 0))) - (overlay-put ov 'display img) - (overlay-put ov 'face 'default) - (overlay-put ov 'org-image-overlay t) - (overlay-put ov 'modification-hooks - (list 'org-display-inline-remove-overlay)) - (push ov org-inline-image-overlays)))))))))) -#+end_src - -Two options: -- work with =.png= file extension and only replace with =.pdf= when exporting to LaTeX if the corresponding file exists -- work with =.pdf= file, add a special function to display =.pdf= files (using =convert= or =pdftocairo=). Change to =.png= when exporting to html - -Let's try the first solution. - -#+begin_src emacs-lisp :tangle no -(defun tdh-change-png-to-pdf (text backend info) - "Change png images to pdf images when existing" - (when (org-export-derived-backend-p backend 'latex) - (let ((text (replace-regexp-in-string "[^\\w]\\(:\\)[^\n\t\r]+\\(:\\)[^\\w]" "" text nil nil 1 nil))) - (replace-regexp-in-string "[^\\w]\\(\\)[^\n\t\r]+\\(:\\)[^\\w]" "" text nil nil 2 nil)))) - -(add-to-list 'org-export-filter-plain-text-fucntions 'tdh-html-mark-tag) -#+end_src - -#+begin_src emacs-lisp :tangle no -(save-excursion - (goto-char (point-min)) - (while (re-search-forward "^[ \t]*#\\s-+()convertfrompdf\\s-*:\\s-*t" - nil :noerror) - ;; Keep on going to the next line till it finds a line with bracketed - ;; file link. - (while (progn - (forward-line 1) - (not (looking-at org-bracket-link-regexp)))) - ;; Get the sub-group 1 match, the link, from `org-bracket-link-regexp' - (let ((link (match-string-no-properties 1))) - (when (stringp link) - (let* ((imgfile (expand-file-name link)) - (pdffile (expand-file-name - (concat (file-name-sans-extension imgfile) - "." "pdf"))) - (cmd (concat "convert -density 96 -quality 85 " - pdffile " " imgfile))) - (when (and (file-readable-p pdffile) - (file-newer-than-file-p pdffile imgfile)) - ;; This block is executed only if pdffile is newer than - ;; imgfile or if imgfile does not exist. - (shell-command cmd) - (message "%s" cmd))))))) -#+end_src - ** Org Ref Ressources: - https://github.com/tmalsburg/helm-bibtex @@ -1430,8 +1291,8 @@ Nice Functions: ) #+end_src -** Org Projects -#+begin_src emacs-lisp +** TODO Org Projects +#+begin_src emacs-lisp :tangle no (setq org-publish-project-alist '(("config" :base-directory "~/.config/literate-dotfiles/dotfiles/" @@ -1465,7 +1326,7 @@ Nice Functions: :recursive nil :publishing-function org-html-publish-to-html :auto-preamble t - :auto-sitemap nil + :auto-sitemap t :html-link-up "index.html" :html-link-home "index.html" :with-todo-keywords nil @@ -1503,20 +1364,47 @@ Nice Functions: :table-of-contents nil))) #+end_src +** TODO Org big org-project +#+begin_src emacs-lisp + (setq org-publish-project-alist + '(("website" + :components ("nass-simscape" "nass-simscape-images")) + ("nass-simscape" + :base-directory "~/Cloud/thesis/matlab/nass-simscape/org/" + :base-extension "org" + :publishing-directory "~/Cloud/website/nass-simscape/" + :publishing-function org-html-publish-to-html + + :html-link-up "./index.html" + :html-link-home "~/Cloud/website/index.html" + + :html-footnotes-section "
%s
" + + :recursive nil + :auto-sitemap nil + :language en) + ("nass-simscape-images" + :base-directory "~/Cloud/thesis/matlab/nass-simscape/docs/figs/" + :base-extension "png" + :publishing-directory "~/Cloud/website/nass-simscape/figs/" + :publishing-function org-publish-attachment) + )) +#+end_src + ** Automatically run =startblock= when opening org-mode files #+begin_src emacs-lisp (after! org (defun tdh-eval-startblock () - (if (member "startblock" (org-babel-src-block-names)) - (save-excursion + (if (member "startblock" (org-babel-src-block-names)) + (save-excursion (org-babel-goto-named-src-block "startblock") (org-babel-execute-src-block)) nil ) - ) + ) (add-hook 'org-mode-hook 'tdh-eval-startblock) - ) + ) #+end_src ** TODO Insert ScreenShot or Picture from Phone @@ -1581,67 +1469,62 @@ http://pragmaticemacs.com/emacs/a-workflow-to-quickly-add-photos-to-org-mode-not (org-display-inline-images t t))) #+end_src -** TODO Render Tables +** Render Tables https://www.reddit.com/r/emacs/comments/d3a8or/pretty_org_tables_in_the_buffer_chapter_2_it/ #+begin_src emacs-lisp (after! org (defun tdh-render-org-table-at-point () - (interactive) - (save-excursion + (interactive) + (save-excursion (beginning-of-line) ;; removes the overlay is already there (if (overlays-at (point)) (delete-overlay (car (overlays-at (point)))) - (let* ((element-type (org-element-type (org-element-at-point)))) + (let* ((element-type (org-element-type (org-element-at-point)))) (if (and (not (eq element-type 'table)) - (not (eq element-type 'table-row))) + (not (eq element-type 'table-row))) (error "not at an org table") - (while (not (eq 'table (org-element-type (org-element-at-point)))) + (while (not (eq 'table (org-element-type (org-element-at-point)))) (forward-line -1)) - (tdh-render-org-table (org-element-at-point)) - ))))) + (tdh-render-org-table (org-element-at-point)) + ))))) (defun tdh-render-org-table (table) - (interactive) - (let* ((begin (org-element-property :begin table)) - (end (let ((pos (org-element-property :end table))) + (interactive) + (let* ((begin (org-element-property :begin table)) + (end (let ((pos (org-element-property :end table))) (goto-char pos) (beginning-of-line) ;; skip possible space after table (while (not (looking-at " *[|#]")) - (setq pos (point)) - (forward-line -1)) + (setq pos (point)) + (forward-line -1)) pos)) - (tabletxt (buffer-substring-no-properties begin end)) - (img (with-temp-buffer + (tabletxt (buffer-substring-no-properties begin end)) + (img (with-temp-buffer (insert tabletxt) (mark-whole-buffer) (org-latex-convert-region-to-latex) (org-latex-preview) (goto-char (point-min)) (overlay-get (car (overlays-at (point))) 'display))) - (overlay (make-overlay begin end))) + (overlay (make-overlay begin end))) (overlay-put overlay 'display img) (forward-line -1)) - ) + ) (defun tdh-render-org-tables-in-buffer () - (save-excursion + (save-excursion (org-element-map (org-element-parse-buffer) 'table 'tdh-render-org-table))) ;; Use F9 to globally generate tables (map! :map org-mode-map :n "" (lambda () (interactive) (tdh-render-org-table-at-point))) - ) -#+end_src - -** Org Download -#+begin_src emacs-lisp - + ) #+end_src ** Org Gcal @@ -1746,6 +1629,16 @@ Take Screenshot and insert a link: ) #+end_src +Insert link to next figure: +#+begin_src emacs-lisp + (defun tdh-insert-link-to-next-figure () + (interactive) + (save-excursion + (re-search-forward "^#\\+name:\s*\\(fig:.*\\)" nil t 1)) + (insert (concat "[[" (match-string 1) "]]")) + ) +#+end_src + Map Keys #+begin_src emacs-lisp (after! org @@ -1756,6 +1649,7 @@ Map Keys :n "f" 'tdh-insert-image-org-link :n "F" 'tdh-insert-image-org-link-sxiv :n "i" 'tdh-insert-phone-picture + :n "l" 'tdh-insert-link-to-next-figure :n "s" 'tdh-insert-screenshot-org-link))) #+end_src @@ -1806,11 +1700,11 @@ Map Keys :n "F" 'tdh-automatic-latex-fragment-deactivate))) #+end_src -*** Bibtex =,n= +*** Bibtex =,r= #+begin_src emacs-lisp (after! org (map! :map org-mode-map - (:prefix (",b" . "BibTeX") + (:prefix (",r" . "References") :n "b" 'helm-bibtex :n "f" 'helm-bibtex-favorites :n "r" 'helm-resume))) @@ -1860,7 +1754,7 @@ Open HTML output externally Don't ask for confirmation when evaluating following blocs #+begin_src emacs-lisp (defun tdh-org-confirm-babel-evaluate (lang body) - (not (member lang '("emacs-lisp" "latex" "matlab" "sh" "latex-macros" "python")))) + (not (member lang '("emacs-lisp" "latex" "matlab" "sh" "latex-macros" "python")))) (after! org (setq org-confirm-babel-evaluate 'tdh-org-confirm-babel-evaluate)) @@ -1886,23 +1780,6 @@ Use the current window for C-c ' source editing (add-hook 'org-mode-hook #'tdh-org-prettify-symbols) #+end_src -#+begin_src emacs-lisp - (after! org - (set-face-attribute 'org-block nil :background (face-background 'fringe)) - (set-face-attribute 'org-block-begin-line nil :background (face-background 'fringe)) - (set-face-attribute 'org-block-end-line nil :background (face-background 'fringe)) -) -#+end_src - -If required, it is possible to set custom colors for different source blocks -#+begin_src emacs-lisp - ;; (after! org - ;; (setq org-src-block-faces - ;; '(("emacs-lisp" (:background (face-background 'org-block))) - ;; ("matlab" (:background (face-background 'fringe))))) - ;; ) -#+end_src - ** Indentation #+begin_src emacs-lisp (after! org @@ -1927,7 +1804,7 @@ Add all named source blocks to =org-babel-library-of-babel=. (setq org-babel-matlab-shell-command "/home/thomas/.local/bin/matlab -softwareopengl -nodesktop -nosplash") (setq org-babel-matlab-emacs-link-wrapper-method - "%s + "%s if ischar(ans); echo('test'); fid = fopen('%s', 'w'); @@ -1952,7 +1829,7 @@ Default options for Matlab code (:cache . "no") (:noweb . "no") (:hlines . "no") - (:tangle . "no") + (:tangle . "yes") (:mkdir . "yes") (:eval . "no-export"))) ) @@ -2015,7 +1892,6 @@ Org-Babel Tangle File and Execute with Matlab (error "Cannot open tangle file %S" file))))) #+end_src - Map Functions #+begin_src emacs-lisp (after! org @@ -2226,7 +2102,12 @@ Map Functions - https://tex.stackexchange.com/questions/52179/what-is-your-favorite-emacs-and-or-auctex-command-trick - https://tex.stackexchange.com/questions/20843/useful-shortcuts-or-key-bindings-or-predefined-commands-for-emacsauctex -** Basic LaTeX configuration +** Master file +#+begin_src emacs-lisp + (setq-default TeX-master nil) +#+end_src + +** Clean Output Files #+begin_src emacs-lisp (defun latex/clean () "Clean LaTeX output using latexmk" @@ -2236,25 +2117,14 @@ Map Functions "latexmk -c " (shell-quote-argument buffer-file-name) " &" - )) + )) - (map! :map LaTeX-mode-map :n ",C" 'latex/clean) + (map! :map LaTeX-mode-map + :n ",C" 'latex/clean) (add-hook 'TeX-mode-hook #'TeX-fold-mode) #+end_src -** Face Attributes -#+begin_src emacs-lisp - (with-eval-after-load 'font-latex - (set-face-attribute 'font-latex-math-face nil :foreground (face-foreground 'org-meta-line)) - ) -#+end_src - -** Master file -#+begin_src emacs-lisp - (setq-default TeX-master nil) -#+end_src - ** PDF Viewer #+begin_src emacs-lisp (setq TeX-view-program-selection '((output-pdf "Zathura"))) @@ -2298,7 +2168,7 @@ Map Functions ;; Display of bibtex entries with helm (setq bibtex-completion-display-formats - '((t . "${author:36} ${title:*} ${year:4} ${=type=:7} ${=has-note=:1}"))) + '((t . "${author:36} ${title:*} ${year:4} ${=type=:7} ${=has-note=:1}"))) ;; Special symbols for notes and pdf (setq bibtex-completion-pdf-symbol "⌘") @@ -2306,62 +2176,62 @@ Map Functions ;; Template used when creating new Note file (setq bibtex-completion-notes-template-multiple-files (concat "#+TITLE: ${title}\n" - ":DRAWER:\n" - "#+LATEX_CLASS: biblioreport\n" - "\n" - "#+OPTIONS: toc:nil title:nil\n" - "#+OPTIONS: ':t -:t\n" - "\n" - "#+LATEX_HEADER: \\newcommand{\\refType}{${=type=}}\n" - "#+LATEX_HEADER: \\newcommand{\\refKey}{${=key=}}\n" - "#+LATEX_HEADER: \\newcommand{\\refTitle}{${title}}\n" - "#+LATEX_HEADER: \\newcommand{\\refAuthor}{${author-or-editor}}\n" - "#+LATEX_HEADER: \\newcommand{\\refJournal}{${journal}}\n" - "#+LATEX_HEADER: \\newcommand{\\refYear}{${year}}\n" - "#+LATEX_HEADER: \\newcommand{\\refDoi}{${DOI}}\n" - "#+LATEX_HEADER: \\newcommand{\\refUrl}{${url}}\n" - "#+LATEX_HEADER: \\newcommand{\\refKeywords}{${tags}}\n" - "#+LATEX_HEADER: \\input{config.tex}\n" - "#+LATEX_HEADER: \\graphicspath{{./figs/${=key=}/}}\n" - "# #+TOC: headlines 2\n" - ":END:\n" - "\n" - "#+BEGIN_abstract\n" - "\n" - "#+END_abstract\n" - "\n" - "* ${title} :${=type=}:ignore:\n" - ":PROPERTIES:\n" - ":CUSTOM_ID: ${=key=}\n" - ":AUTHOR: ${author}\n" - ":TYPE: ${=type=}\n" - ":JOURNAL: ${journal}\n" - ":YEAR: ${year}\n" - ":VOLUME: ${volume}\n" - ":PAGES: ${pages}\n" - ":DOI: ${DOI}\n" - ":URL: ${url}\n" - ":NOTER_DOCUMENT: ../pdfs/${=key=}.pdf\n" - ":END:\n" - "\n")) + ":DRAWER:\n" + "#+LATEX_CLASS: biblioreport\n" + "\n" + "#+OPTIONS: toc:nil title:nil\n" + "#+OPTIONS: ':t -:t\n" + "\n" + "#+LATEX_HEADER: \\newcommand{\\refType}{${=type=}}\n" + "#+LATEX_HEADER: \\newcommand{\\refKey}{${=key=}}\n" + "#+LATEX_HEADER: \\newcommand{\\refTitle}{${title}}\n" + "#+LATEX_HEADER: \\newcommand{\\refAuthor}{${author-or-editor}}\n" + "#+LATEX_HEADER: \\newcommand{\\refJournal}{${journal}}\n" + "#+LATEX_HEADER: \\newcommand{\\refYear}{${year}}\n" + "#+LATEX_HEADER: \\newcommand{\\refDoi}{${DOI}}\n" + "#+LATEX_HEADER: \\newcommand{\\refUrl}{${url}}\n" + "#+LATEX_HEADER: \\newcommand{\\refKeywords}{${tags}}\n" + "#+LATEX_HEADER: \\input{config.tex}\n" + "#+LATEX_HEADER: \\graphicspath{{./figs/${=key=}/}}\n" + "# #+TOC: headlines 2\n" + ":END:\n" + "\n" + "#+BEGIN_abstract\n" + "\n" + "#+END_abstract\n" + "\n" + "* ${title} :${=type=}:ignore:\n" + ":PROPERTIES:\n" + ":CUSTOM_ID: ${=key=}\n" + ":AUTHOR: ${author}\n" + ":TYPE: ${=type=}\n" + ":JOURNAL: ${journal}\n" + ":YEAR: ${year}\n" + ":VOLUME: ${volume}\n" + ":PAGES: ${pages}\n" + ":DOI: ${DOI}\n" + ":URL: ${url}\n" + ":NOTER_DOCUMENT: ../pdfs/${=key=}.pdf\n" + ":END:\n" + "\n")) (setq bibtex-completion-notes-template-one-file (concat "\n" - "* ${author-abbrev} (${year}): ${title} :${=type=}:ignore:\n" - ":PROPERTIES:\n" - ":CUSTOM_ID: ${=key=}\n" - ":EXPORT_FILE_NAME: ${=key=}\n" - ":EXPORT_TITLE: ${title}\n" - ":AUTHOR: ${author}\n" - ":TYPE: ${=type=}\n" - ":JOURNAL: ${journal}\n" - ":YEAR: ${year}\n" - ":VOLUME: ${volume}\n" - ":PAGES: ${pages}\n" - ":DOI: ${DOI}\n" - ":URL: ${url}\n" - ":NOTER_DOCUMENT: ../pdfs/${=key=}.pdf\n" - ":END:\n" - "\n")) + "* ${author-abbrev} (${year}): ${title} :${=type=}:ignore:\n" + ":PROPERTIES:\n" + ":CUSTOM_ID: ${=key=}\n" + ":EXPORT_FILE_NAME: ${=key=}\n" + ":EXPORT_TITLE: ${title}\n" + ":AUTHOR: ${author}\n" + ":TYPE: ${=type=}\n" + ":JOURNAL: ${journal}\n" + ":YEAR: ${year}\n" + ":VOLUME: ${volume}\n" + ":PAGES: ${pages}\n" + ":DOI: ${DOI}\n" + ":URL: ${url}\n" + ":NOTER_DOCUMENT: ../pdfs/${=key=}.pdf\n" + ":END:\n" + "\n")) ;; Make "Edit notes" the default action (helm-delete-action-from-source "Edit notes" helm-source-bibtex) @@ -2369,12 +2239,11 @@ Map Functions (helm-delete-action-from-source "Open PDF Externally" helm-source-bibtex) (helm-add-action-to-source "Open PDF Externally" 'tdehaeze/open-pdf-externally helm-source-bibtex 1) - ) + ) #+end_src ** Open pdf externally #+begin_src emacs-lisp - ;; Action to open the pdf with Zathura (defun tdehaeze/open-pdf-externally (key) (call-process "zathura" nil 0 nil (nth 0 (-cons-to-list (bibtex-completion-find-pdf key))))) #+end_src @@ -2389,7 +2258,7 @@ Map Functions ** List all element of the bibliography without pdf associated #+begin_src emacs-lisp - (defun list-bib-without-pdf-associated () + (defun tdh-list-bib-without-pdf-associated () (interactive) (bibtex-completion-init) (setq candidates (bibtex-completion-candidates)) @@ -2409,9 +2278,8 @@ Map Functions ) #+end_src -* TODO Matlab -- https://github.com/yuhonglin/matlab-mode -- https://github.com/pronobis/matlab-mode +* Matlab +- https://sourceforge.net/projects/matlab-emacs/ ** Setup Matlab Mode #+begin_src emacs-lisp @@ -2420,7 +2288,7 @@ Map Functions (setq mlint-programs '("mlint" "/home/thomas/.local/bin/mlint")) #+end_src -** Setup Flycheck +** Setup Flycheck to work with =mlint= #+begin_src emacs-lisp (defvar mlint-executable "/home/thomas/.local/bin/mlint") @@ -2437,31 +2305,26 @@ Map Functions (add-hook 'matlab-mode-hook 'flycheck-mode) #+end_src -#+begin_src emacs-lisp :tangle no - (defadvice org-edit-src-code (around set-buffer-file-name activate compile) - (let ((file-name (buffer-file-name))) ;; (1) - ad-do-it ;; (2) - (setq buffer-file-name file-name))) ;; (3) -#+end_src - -** TODO Setup Company - not working -#+begin_src emacs-lisp - ;; (add-to-list 'company-backends 'company-matlab) -#+end_src - ** Completion in the Matlab Shell #+begin_src emacs-lisp - (map! :map matlab-shell-mode-map :i "" 'matlab-shell-tab) + (map! :map matlab-shell-mode-map + :i "" 'matlab-shell-tab) #+end_src -** TODO Beautify code +** Beautify code #+begin_src emacs-lisp - (defun matlab-beautify-buffer () - "Beautify Current Buffer" + (defun tdh-matlab-beautify-buffer () + "Beautify Current Matlab Buffer" (interactive) - (save-buffer) - (matlab-shell-run-command (concat "MBeautify.formatFile(\"" (buffer-file-name) "\")")) - ) + ;; First verifies is the current file is a Matlab file + (if (string= (file-name-extension (buffer-file-name)) "m") + (progn + (save-buffer) + (matlab-shell-run-command (concat "MBeautify.formatFileNoEditor(\"" (buffer-file-name) "\", \"" (buffer-file-name) "\")")) + (revert-buffer :ignore-auto :noconfirm)) + (message "Current buffer is not a matlab file") + ) + ) #+end_src ** Key Bindings @@ -2469,15 +2332,19 @@ Map Functions (defun matlab-add-breakpoint () (interactive) (matlab-shell-run-command (concat "dbstop in " (buffer-name) " at " (number-to-string (line-number-at-pos nil))))) + (defun matlab-remove-breakpoint () (interactive) (matlab-shell-run-command (concat "dbclear in " (buffer-name) " at " (number-to-string (line-number-at-pos nil))))) + (defun matlab-list-breakpoints () (interactive) (matlab-shell-run-command (concat "dbstatus " (buffer-name)))) + (defun matlab-clear-breakpoints () (interactive) (matlab-shell-run-command (concat "dbclear in " (buffer-name)))) + (defun matlab-go-to-file-directory () (interactive) (matlab-shell-run-command (concat "cd " (file-name-directory buffer-file-name)))) @@ -2496,23 +2363,6 @@ Map Functions :n ",dq" 'gud-finish) #+end_src -** Wrong highlight of comments -#+begin_src emacs-lisp :tangle no - (add-hook 'matlab-mode-hook - ;; `highlight-numbers-mode' breaks MATLAB comment coloring -- - ;; `highlight-numbers-mode' is mostly redundant with - ;; `rainbow-identifiers-mode' anyway - (lambda () - (highlight-numbers-mode -1)) - ;; We must append the above *after* `spacemacs/run-prog-mode-hooks' - ;; in `matlab-mode-hook', since the former hook enables - ;; `highlight-numbers-mode'. Note that - ;; `spacemacs/run-prog-mode-hooks' is manually added to - ;; `matlab-mode-hook' by Spacemacs since the upstream `matlab-mode' - ;; package does not derive `matlab-mode' from `prog-mode' (oddly -- - ;; IIRC the author refused to do so for compatibility with XEmacs). - 'append) -#+end_src * Mu4e ** Ressources @@ -2709,8 +2559,8 @@ Choose account label to feed msmtp -a option based on From header in Message buf * PDF-Tools #+begin_src emacs-lisp (use-package! pdf-tools - :config - (add-hook 'pdf-view-mode-hook (lambda() (linum-mode -1))) + :config + (add-hook 'pdf-view-mode-hook (lambda() (linum-mode -1))) ) #+end_src @@ -2720,77 +2570,6 @@ Choose account label to feed msmtp -a option based on From header in Message buf (yas-global-mode 1) #+end_src -* Proxy -#+begin_src emacs-lisp :tangle no - (setq url-proxy-services - '(("http" . "proxy.esrf.fr:3128") - ("https" . "proxy.esrf.fr:3128") - ("no_proxy" . "^.*esrf.fr"))) -#+end_src - -* TODO Neomutt connection -https://mentat.za.net/blog/2018/10/31/using-org-mode-with-neomutt/ - -#+begin_src emacs-lisp :tangle no - (require 'org-protocol) - ;; Call this function, which spawns neomutt, whenever org-mode - ;; tries to open a link of the form mutt:message-id+goes_here@mail.gmail.com - - (defun tdh-mutt-open-message (message-id) - "In neomutt, open the email with the the given Message-ID" - (let* - ((message-id (replace-regexp-in-string "^/*" "" message-id)) - (mail-file - (replace-regexp-in-string - "\n$" "" (shell-command-to-string - (format "mu find -n 1 -f l i:%s" message-id)))) - (mail-dir (replace-regexp-in-string "/\\(cur\\|new\\|tmp\\)/$" "" - (file-name-directory mail-file))) - (message-id-escaped (regexp-quote message-id)) - (mutt-keystrokes - (format "L~i %s\n\n" (shell-quote-argument message-id-escaped))) - (mutt-command (list "neomutt" "-R" "-f" mail-dir - "-e" (format "push '%s'" mutt-keystrokes)))) - - (message "Launching neomutt for message %s" message-id) - (call-process "setsid" nil nil - "-f" "termite" "-e" - (concat "neomutt -R -f " mail-dir " -e \"" (format "push '%s a l'\"" mutt-keystrokes))))) - - ;; Hook up `message:...` style URLs - (org-add-link-type "message" 'tdh-mutt-open-message) -#+end_src - -* Abbreviations -Type the abbreviation and use =C-x a -= to create a new abbreviation. - -#+begin_src emacs-lisp - (setq-default abbrev-mode t) - ;; save abbreviations upon exiting xemacs - (setq save-abbrevs t) - ;; set the file storing the abbreviations - (setq abbrev-file-name "~/.config/doom/my-abbreviations.el") - ;; reads the abbreviations file on startup - (quietly-read-abbrev-file) -#+end_src - -* Other -Here are some additional functions/macros that could help you configure Doom: - -- `load!' for loading external *.el files relative to this one -- `use-package' for configuring packages -- `after!' for running code after a package has loaded -- `add-load-path!' for adding directories to the `load-path', where Emacs - looks when you load packages with `require' or `use-package'. -- `map!' for binding new keys - -To get information about any of these functions/macros, move the cursor over -the highlighted symbol at press 'K' (non-evil users must press 'C-c g k'). -This will open documentation for it, including demos of how they are used. - -You can also try 'gd' (or 'C-c g d') to jump to their definition and see how -they are implemented. - * Doom =init.el= :PROPERTIES: :header-args: :tangle ~/.config/doom/init.el @@ -2877,7 +2656,8 @@ they are implemented. :config literate - (default +bindings +smartparens)) + (default +bindings) + ) #+end_src * Doom =packages.el= @@ -3187,14 +2967,14 @@ $0 #contributor : Thomas Dehaeze #name :Matlab-Figure # -- -#+header: :tangle no :exports results :results none :noweb yes -,#+begin_src matlab :var filepath="${2:figs}/$1.pdf" :var figsize="${3:full-tall}" :post pdf2svg(file=*this*, ext="png") - <>$0 +,#+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: ${4:caption}${5: ([[./figs/$1.png][png]], [[./figs/$1.pdf][pdf]])} -[[file:$2/$1.png]] +,#+name: fig:$1 +,#+caption: $0 +,#+RESULTS: +[[file:figs/$1.png]] #+end_src *** Mfunction