alhassy/org-special-block-extras
حول
Write once in Org, export everywhere: Org markup in any block; display maths with colours & calculational proofs; Org lists drawn as Graphviz graphs; folds, tooltips, glossaries, callouts; and org-defblock to make your own ^_^
أدوات التطويرالنمو المقاس للنجوم
- خلال 24 ساعة
- -١
- خلال 7 أيام
- ٠
- خلال 15 يومًا
- ٠
- خلال شهر
- جارٍ جمع السجل
تغيّر صافي النجوم خلال فترات متداخلة، وليس مجموعًا يوميًا. تبقى القياسات المفقودة فارغة. النجوم تقيس الاهتمام لا جودة البرمجيات.
README.md
الأصل🧙♂️ org-special-block-extras: Write once, export everywhere
One Org file ---a tiny Lisp function, a peek at its values, a picture of its loop, and a proof of what it computes---
exported to PDF (left), as written in Emacs (middle), and exported to HTML (right). Click it for the
live HTML export, where we hover the tooltips, unfold the
details, and click the proof's hints.
The Org source, minimal-working-example.org
#+title: Summing odd numbers
* A tiny function
We sum the first =n= [[tooltip:odd][An integer 2i - 1, for some i ≥ 1]] numbers by doc:cl-loop; place the
cursor after the last parenthesis and press kbd:C-x_C-e to define it.
#+begin_src emacs-lisp
(defun sum-odds (n)
"Return 1 + 3 + ⋯ + (2n - 1)."
(cl-loop for i from 1 to n sum (- (* 2 i) 1)))
#+end_src
#+begin_details Peek: the first few values :let (N 4)
=(sum-odds N)= is the sum of the first N odd numbers. In order:
| =n= | 1 | 2 | 3 | 4 |
| =(sum-odds n)= | 1 | 4 | 9 | 16 |
These are red:squares! <<squares>> We [[*Why squares?][prove it below]].
#+end_details
* How the loop accumulates
Each step adds the next odd number to the running sum:
#+begin_graph :direction right
+ 0
+ add 1 :: 1
+ add 3 :: 4
+ add 5 :: 9
+ add 7 :: 16
#+end_graph
* Why squares?
The [[squares][squares]] are no coincidence:
#+begin_math :let (Σ "\\sum_{i=1}^{n}")
Σ (2i - 1)
={ Split the sum }
2 · red:{Σ i} - teal:{Σ 1}
={ Gauss: $red:{Σ i} = n(n+1)/2$; and $n$ ones sum to $teal:n$ }
n(n + 1) - teal:n
={ Distribute, then cancel }
n^2 violet:<<Odd>>
#+end_math
Hence, by [[Odd]], =(sum-odds n)= is $n^2$. badge:sum-odds|n²|teal
Use the Org markup you already know ---in any block. Our new math, graph, and details blocks read
Org just as prose does: colors red:hello, permalinks <<here>> cited by [[here]], hoverable docs
doc:cl-loop, keystrokes kbd:C-x_C-e, footnotes as tooltips, and :let (N 7) substitution ---which works
on every block, Org's own src blocks included. One Org source exports to HTML, LaTeX, and Markdown; no raw
HTML or LaTeX required.
📖 The guide to every block and link type shows, for each, the Org we write, what it exports to, and the Lisp behind it. Start there.
🧱 Ready-to-Use Custom Blocks
Each block is demoed in the guide.
| Block | Use Case |
|---|---|
math |
Display maths wherein red:𝒳 colors a symbol, Org tables are matrices, and <<X>> tags an equation; calculational proofs, with foldable hints. |
graph |
Draw nested Org lists as Graphviz diagrams ---C-c C-c renders a PNG in place. |
smartdiagram |
Typeset an Org list as LaTeX's smartdiagram ---a planet amid satellites, a flow, bubbles--- as image latex would. |
image LANG |
LaTeX, HTML, SVG, dot, PlantUML, Mermaid, D2, or a p5.js sketch: itself where read natively, else a picture ---a TikZ drawing in a web page, an HTML widget in a PDF. C-c C-c shows it in place; a p5.js sketch, running. |
details |
Foldable sections ---perfect for hiding spoilers, proofs, or long explanations. |
parallel |
Display content in multiple columns ---great for comparisons or saving space. |
box |
Emphasize content with nicely styled borders ---great for callouts or side notes. |
note, tip, warning, … |
GitHub-style callouts ---a colored rule and a titled heading. |
highlight |
Color a paragraph's background, rather than its text. |
quote KEY |
Quotations, cited by an org-cite key. |
documentation |
Define a glossary term once; cite it anywhere with doc:, and print a glossary with #+print_glossary:. |
remark |
Editorial comments, shown in color; org-hide-editor-comments hides them all from the export. |
margin |
Subtle explanatory tooltips or side remarks ---delightful for scholarly writing. |
spoiler |
Hide content visually until the reader chooses to see it ---useful in teaching. |
tree |
Display proof trees and logical derivations ---fantastic for formal logic. |
solution |
Reveal answers in stages ---perfect for educational content. |
stutter |
Repeat content multiple times ---e.g., for emphasis or stylistic flair. |
org-demo |
Show Org markup alongside its rendered result ---ideal for tutorials. |
🎛 Switch any block: :when (eq backend 'html), :noexport t, :let (N 7), :boxed "Title", :folded t,
:verbatim t, and :C-c_C-c ACTION work on every block ---ours, yours, or Org's own src and quote blocks.
Sections and blocks are two ways to say the same thing, so every switch works on a section too, as a property;
e.g., this section is only in the HTML export:
* For readers online
:PROPERTIES:
:when: (eq backend 'html)
:END:
See switches.
🗂 Every block is a section: each #+begin_NAME is also a heading tag :NAME:, the heading its title
and the drawer its keyword arguments. So these two agree:
#+begin_box "Heads up" :background-color pink
Mind the gap.
#+end_box
* Heads up :box:
:PROPERTIES:
:BACKGROUND-COLOR: pink
:END:
Mind the gap.
Likewise, * Hint :details: folds a section away, and a :graph: section
draws its subheadings as nodes.
🔗 Ready-to-Use Custom Links
| Link | Purpose |
|---|---|
doc:label |
Glossary tooltips ---from our own documentation blocks, else Emacs Help; e.g., cl-loop. |
tooltip: |
An ad-hoc tooltip: [[tooltip:odd][An integer 2i - 1]] shows odd, and hovers the rest. |
kbd: |
Stylized keybindings with tooltips ---e.g., kbd:C-x_C-e; in Emacs, 〔C-x C-e〕, click to run. |
color: or red: |
Inline text coloring ---supports both names and hex codes. |
highlight: |
Color the background instead ---so highlighted in Emacs too. |
badge: |
Embed project badges ---e.g., GitHub stars, Reddit subs, versioning. |
<<X>> |
Permalinks ---Org's own targets, made a visible 🔗 in HTML. |
palette: |
A button for readers to pick the page's background color. |
toggle-details: |
A button to unfold, or fold, every details block at once. |
fortune: |
Insert ASCII animals saying jokes or phrases ---joy in our docs! |
elisp: |
Make clickable actions ---buttons that run Emacs Lisp. |
info:elisp#Node |
Org's own, yet worth knowing: in Emacs, it opens the Info reader at that node; on HTML export, it becomes the GNU manual's URL, e.g., (elisp) Face Attributes. |
🛠 Make your own blocks and links
Tired of repeating yourself when writing in Org-mode for LaTeX and HTML exports? Org, extended as one
extends Lisp: org-defblock, org-deflink and org-deftag are each declared like a cl-defun, with
&optional and &key arguments.
- Create custom blocks with
org-defblock: define a block once and export to LaTeX and HTML. With header-args support like:color red :signoff "Thanks!"for locally customised exports. Each block is also a link and a tag, for free; and:fontifysays how it looks in the buffer. - Create custom links with
org-deflink, as functions of their label and description. - Create custom tags with
org-deftag, as functions of the Org sections they tag.
For instance, the following folds every src block into a <details> on HTML export:
(org-defblock src (&optional lang &key title &context raw-contents)
"Fold away all ‘src’ blocks as ‘<details>’ on HTML export."
(format "<details> <summary> %s </summary> <pre> %s </pre></details>"
(or title (concat "Details; " lang))
raw-contents))
The developer's guide shows that every block and
link in this package is made with these very tools; so a new one of our own is a defun away.
Basic examples live in the tests, which pair a block's definition, its Org input, and its expected output:
each family of blocks has its own file and tests, e.g., lisp/org-callout-blocks.el
and tests/org-callout-blocks-tests.el; and
tests/demos.org ---live--- shows each
example beside its snapshotted export.
📦 Installation
(use-package org-special-block-extras
:ensure t
:hook (org-mode . org-special-block-extras-mode))
Or use M-x org-special-block-extras-mode to turn it on or off. Graphs need Graphviz's
dot on our PATH.
📚 Further reading
All articles on the package live under #org-special-block-extras:
- Write Once, Export Everywhere ---the package at a glance.
- The block and link types ---the guide.
- A minimal working example ---the one above, live.
- Org lists, drawn as Graphviz graphs ---the
graphblock, a feature at a time. - Make your own blocks and links ---the developer's guide.
- Tooltips for glossaries, dictionaries, and documentation ---
doc:anddocumentation. - Colors, Badge links, Permalinks, Editor comments, and HTML export styles.
- Demos that are tests, rather than docs.
- Powering-up Special Blocks ---our EmacsConf 2020 talk; its slides are no pictures, just Org: “Look ma, no HTML required!”
Bye!
استكشف مشاريع مشابهة ومرتبطة
جارٍ التحميل…
