Skip to content

Instantly share code, notes, and snippets.

@danielkrizian
Last active June 13, 2024 16:37
Show Gist options
  • Save danielkrizian/921f681a652f6d941949cfed1a2ee326 to your computer and use it in GitHub Desktop.
Save danielkrizian/921f681a652f6d941949cfed1a2ee326 to your computer and use it in GitHub Desktop.
org mode cheatsheet

ORG Cheatsheet

http://spacemacs.org/layers/+emacs/org/README.html https://org-babel.readthedocs.io/en/latest/ https://gist.github.com/drj42/1755992 https://github.com/kshenoy/dotfiles/blob/master/emacs.org

markup

emphasis

  • bold italic underlined verbatim strikethrough C-c C-l for hyperlink
  • escape comma in verbatim by prepending with ZERO WIDTH SPACE C-x 8 RET 200b RET

footnotes

This is [fn:1] footnote 1.

[fn:1] The actual footnote.

This is [fn:: Anonymous definition] anonymous footnote

headings

M-h M-l M-S-h M-S-L promote/demote heading/subtree

Example heading level 1

use number of stars (*) for levels; TAB will collapse this. S-TAB collapses everything

Level 2 heading

TAB TAB will collapse everything Alt-down will move whole level within the parent level Alt-left/right change level , s r — will refile subtree - move this level under different parent

Another level 2

Level 3

Level 4

tables

hit TAB at end of line. M-arrow moving rows/columns

NameAgeOccupation
Barney65Work

calculator in table

https://easyorgmode.com/blog/use-org-mode-as-an-inline-calculator-and-notepad-calculator https://orgmode.org/worg/org-tutorials/org-spreadsheet-intro.html

type this | 3.14 | 10 | := $1 * $2^2 |, then C-c C-c

3.1410314.

with variable names

Expected Income
Gross_Salary_Wanted100000
Health_Insurance0.07 Gross_Salary_Wanted
Pension_Plan:=0.15 * Gross_Salary_Wanted
Total Revenue:=vsum(@2..@4)
Hourly rate
Unpaid_vacation_days20
PublicHolidaysAndWeekends120
Work_days_per_year:=365 - Unpaid_vacation_days - PublicHolidaysAndWeekends
Work_hours_per_year:=Work_days_per_year*8
Rate needed:=Gross_Salary_Wanted/Work_hours_per_year

and DONE, priority [#C] [#B]

S-left S-right TODO DONE S-up S-down priority cycle C-c , priority set C-c C-c ,, refresh line #+SEQ_TODO custom TODO states #+PRIORITIES: A B C buffer settings

schedules, deadline

Schedule C-c C-s

Schedule Recurring

+1w – will make it recurring ++1w – recurring also from the past

Deadline C-c C-d

agenda ,a

f b forward backward one week (setq org-agenda-files (quote ("~/myfile.org"))) (setq org-agenda-files (append (file-expand-wildcards "~/dir/*.org") (file-expand-wildcards "~/dir2/*.org"))) C-c [ adds current file to the front of the agenda C-c ] org-remove-file M-SPC transient state C-v change view

lists

Unordered

  • item
    • indented item
  • also item

Ordered

  1. first item
    • can have nested bullets
  2. also first item
  3. enforcing the item starting with 20

Description

term is bold
description on the next line indented

checklists

Checklist [2/3] [66%]

  • [ ] item 1 of checklist
  • [X] item 2 of checklist
  • [X] item 3 of checklist

C-c C-c – check/uncheck the checklist item will toggle [x] [/] or [%] in heading will track all checklist subitems; as completed/total or %complete respectively

LaTeX

https://www.authorea.com/users/77723/articles/110898-how-to-write-mathematical-equations-expressions-and-symbols-with-latex-a-cheatsheet http://asciimath.org/

,Te toggle pretty entities ,Tx toggle LaTeX

logic

  • and land
  • or lor ∨​
  • if…then to →​
  • if and only if leftrightarrow
  • logical equivalence equiv ≡​
  • therefore therefore \therefore
  • there exists exist ∃​
  • for all forall
  • implies Rightarrow ⇒​

equivalent Leftrightarrow

basic

Unicode References
α, β, γ, π, ∞, ∑ .
Subscripts
_ { } (without spaces) like Hydrogen atoms, H_2, and Water, H2O.
Superscripts
^ { } (without spaces) The mass of the sun is $1.989 ⋅ 1030 kg$.
Embedded/inline Equations
Surrounded with either single $, like $a^2=b$, or escaped parenthesis, like: \( b=\frac{1}{2} \)
Separated equations
Either in double $$ or escaped brackets \[ \], like this: $$ a=\frac{1}{2}\sqrt{2} $$ or this: \[ a=-\sqrt{2} \] or this: \begin{equation} x=\sqrt{b} \end{equation}
Block
\[ \]

\[ c=a+b \] $\Bbb{R}$ \displaystyle fullsize for this $\displaystyle ∑n=1 \frac{1}{n}$ , not this $∑n=1 \frac{1}{n}$

align equal signs

\begin{align} a=1
a+2=4 \end{align}

matrices

\begin{matrix} a & b
c & d \end{matrix}

\begin{matrix} a & b
c & d \end{matrix} \begin{pmatrix} a & b \ c & d \end{pmatrix} \begin{bmatrix} a & b \ c & d \end{bmatrix} \begin{vmatrix} a & b \ c & d \end{vmatrix} \begin{Vmatrix} a & b \ c & d \end{Vmatrix} $\vdots \ddots \hdots$

logic

not ~ ∼ and ∧ ∧∧​ or ∨ ∨∨​ if…then → →→​ if and only if ↔ ↔↔​ logical equivalence ≡ ≡≡​ therefore \therefore \therefore∴​ there exists ∃ ∃∃​ for all ∀ ∀∀​ implies ⇒ ⇒⇒​ equivalent ⇔ ⇔⇔

tex input method

C-x RET C-\ set-input-method to TeX, then C-\ toggle on/off last used input method

Babel (source code)

babel package for literate programming and reproducibility. See https://news.ycombinator.com/item?id=16841909 https://github.com/novoid/org-babel-examples

reverse 5 4 2                                      / some comment

babel package for literate programming and reproducibility. See https://news.ycombinator.com/item?id=16841909

  • ,ibs insert source code block (via org-insert-structure-template)
  • <sTAB> insert source code block via easy templates
  • C-c ' or ,' will edit in separate major mode window
  • ,bv - expand according to block header args into preview buffer
  • ,bp ,bn - move to prev/next chunk
  • ,bj - insert header argument
  • ,bt or ,bf - generate into a file using org-babel-tangle
  • ,bb ,bs - execute all buffer/subtree blocks
  • ,T# toggle visibility of all blocks (hide/collapse - show)

Header arguments

system-wide

(setq org-babel-default-header-args '((:noweb . "yes")))
(setq org-babel-default-header-args:C++ '((:flags . "-I.")))
(setq org-babel-default-header-args:R '(:session . "*org-R*"))
(setq org-babel-default-header-args:R '((:width . 640) (:height . 640)))

buffer-wide

subtree-wide

Block-wide

Function call-wide

reuse

plot(x, y)
abline(out1)

input (STDIN, file)

int a;
std::cin >> a;
std::cout << a;
(completing-read "Enter a number: " nil)
#include <iostream>
#include <string>

int main() {
    int a = std::atoi(input);
    std::cout << a;
}

Header file

int i, n = 4;
double x[4] = { 1970, 1980, 1990, 2000 };
double y[4] = {   12,   11,   14,   13 };
double w[4] = {  0.1,  0.2,  0.3,  0.4 };

double c0, c1, cov00, cov01, cov11, chisq;

gsl_fit_wlinear (x, 1, w, 1, y, 1, n,
                 &c0, &c1, &cov00, &cov01, &cov11,
                 &chisq);

printf ("# best fit: Y = %g + %g X\n", c0, c1);
printf ("# covariance matrix:\n");
printf ("# [ %g, %g\n#   %g, %g]\n",
        cov00, cov01, cov01, cov11);
printf ("# chisq = %g\n", chisq);

for (i = 0; i < n; i++)
  printf ("data: %g %g %g\n",
          x[i], y[i], 1/sqrt(w[i]));

printf ("\n");

for (i = -30; i < 130; i++)
  {
  double xf = x[0] + (i/100.0) * (x[n-1] - x[0]);
  double yf, yf_err;

  gsl_fit_linear_est (xf,
                      c0, c1,
                      cov00, cov01, cov11,
                      &yf, &yf_err);

  printf ("fit: %g %g\n", xf, yf);
  printf ("hi : %g %g\n", xf, yf + yf_err);
  printf ("lo : %g %g\n", xf, yf - yf_err);
  }

org-mode tables as data

sqrnoise
0.00.23
1.01.31
4.04.61
9.09.05
16.016.55
for (int i=0; i<somedata_rows; i++)
  {
  for (int j=0; j<somedata_cols; j++)
    {
    std::cout << somedata[i][j]/2.0 << "\t";
    }
  std::cout << "\n";
  }

tangle

  • ,bt ,bf generate into a file using org-babel-tangle
  • SPC u ,bt tangle only block at point
  • SPC u SPC u ,bt tangle all blocks for the the tangle file at point
namespace ns {
    class MyClass {};
}

int main(int argc, char* argv[])
{
ns::MyClass{};
std::cout << "hi" << std::endl;
return 0;
}

C++

https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-C.html

std::cout << "Hello World!" << std::endl;
printf ("mystring %s\n", mystring);
printf ("myint    %d\n", myint);
printf ("mydouble %g\n", mydouble);

inline source code block

calc built-in calculator

type src_calc{100+2*4} and execute with C-c C-c

tags

C-c C-q or  , i t

Inherited

projectile

SPC p ogo to the TODOs for the current project
SPC a o pcapture a TODO for the current project
SPC u SPC a o pcapture a TODO for any given project (choose from list)

special characters

C-x 8 RET ZERO WIDTH SPACE necessary for things like quote inside verbatim e.g. C-c '​

dates and times

https://orgmode.org/manual/The-date_002ftime-prompt.html#The-date_002ftime-prompt

  • ​,dt ​,dT org-time-stamp/inactive (does/does not enter agenda)

customization

org-directory org-agenda-files org-archive-location

archive

  • ​,sA move subtree to archive location

visibility cycling

  • TAB current subtree
  • S-TAB SPC u N S-TAB global, up to N level
  • SPC u SPC u TAB startup
  • SPC u SPC u SPC u TAB show all, incl. drawers
  • C-c C-k headings of this subtree
  • ,sb current subtree to buffer

motion (go to)

  • { } paragraph
  • M-{ M-} element
  • C-c C-n C-c C-p visible heading next/previous
  • C-c C-f C-c C-b same level heading forward/backward
  • C-c C-u upper level heading
  • C-c C-j differet place witout changing current visibility

,bu source block head

links

file:name.org::LineOrHeading

internal links

,il insert link [[Heading]] [[Heading][Title]] heading [[http://www.google.com][hyperlink title]] hyperlink

images

,iDy paste image from url stored in clipboard ,Ti toggle inline images

org-roam

  • C-M i completion at point for inserting a node link
  • M-x org-id-get-create turn this top-level header into a node

pdfs

search within my org/files library

helm-find-files home/dk/org/files M-a M-g p - calls helm-ff-run-pdfgrep

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment