Tip
Unlock the power of Emacs! Join my next exclusive “Emacs Boost” course!
Ready to supercharge your productivity and become an Emacs ninja? Look no further!
What you’ll learn:
- Master Emacs from the basics to advanced tricks.
- Boost your editing efficiency and streamline your workflow.
- Customize Emacs to fit your unique needs.
- And much more!
Audience:
Open to anyone interested in Emacs, from beginners to advanced users.
Why choose my course?
- Expert instructor with 25 years of Emacs experience.
- Hands-on exercises to reinforce your learning.
- Networking opportunities with like-minded Emacs enthusiasts.
- Personalized attention.
Don’t miss this opportunity to take your Emacs skills to the next level!
Visit https://emacsboost.com/en/ for more information, dates and locations, and to reserve your seat.
The macros in Org allow you to add text or code to an Org document that will be expanded during export: the text between the 3 pairs of accolades is expanded so that readers can see it in the exported versions of the document.
Some people (such as me) use it to construct complex HTML or LaTeX code.
Using macros allows you to insert dynamic content or add extra functionality in exports of an Org document.
These Org-macros have been tested for HTML exports.
FIXME They will be soon made available for PDF exports.
Use this command to check out the latest source code of the project from the Git repository hosted at GitHub:
git clone https://github.com/fniessen/org-macros
#+INCLUDE: /PATH/TO/org/org-macros.setup
Once you’ve cloned Org-macros, many macros will be ready to use within your Org files.
You can invoke macros anywhere in the document (even in code examples).
Examples:
- With no arguments:
{{{name-of-the-macro}}}
- With arguments:
{{{name-of-the-macro(arg1,arg2)}}}
Below is a list of the few macros currently available.
- author macro
- date macro
- email macro
- input-file macro
- modification-time macro
- property macro
- time macro
- title macro
- bgcolor macro
- clearpage macro
- color macro
- lcolor macro
- fixme macro
- highlight macro
- loremipsum macro
- newline macro
- redact macro
- kbd macro
- dvipng-when-odt macro
- if-latex-else macro
- style macro
- image macro
recently-updated
macrotasklist
macro- version-history macro
- vspace macro
- collapse macro
- info macro
- minipage macro
- note macro
- panel macro
- tip macro
- warning macro
children
macro (to display child pages)- toc macro
# -*- mode: org; -*-
The author
macro outputs a list of users who have created or edited the
document.
None.
People who have created and edited this document: {{{author}}}.
Option #+AUTHOR:
.
The date
macro outputs the date and time specified in the document.
- Format string understood by
format-time-string
.
The date of this document is: {{{date}}} or {{{date(%Y-%m)}}}.
- Option
#+DATE:
(for the whole document). - Property
:EXPORT_DATE:
(for specific subtrees). - modification-time macro.
- time macro.
The email
macro outputs the email of the author(s).
None.
The email of this document is: {{{email}}}.
Option #+EMAIL:
.
The input-file
macro displays the name of the input Org file.
None.
The input file name for this document is: {{{input-file}}}.
The modification-time
macro outputs the modification date and time of the file
being exported.
- Format string understood by
format-time-string
.
This document was last modified on: {{{modification-time(%Y-%m-%d %a %H:%M)}}}.
The property
macro outputs …
- Node property name.
* TODO Do it!
:PROPERTIES:
:Effort: 1:00
:END:
This task should take no more than {{{property(Effort)}}} hours.
The time
macro outputs the current date and time when the document is being
exported.
- Format string understood by
format-time-string
.
This document was last exported on: {{{time(%Y-%m-%d %a %H:%M)}}}.
- date macro.
- modification-time macro.
The title
macro outputs the document title.
None.
The title of this document is: {{{title}}}.
Option #+TITLE:
.
The bgcolor
macro allows you to change the background color of a block of text.
#+MACRO: bgcolor @@html:<div style="background-color: $1;">$2</div>@@
- Color name or hexadecimal code.
- Text you want to color.
{{{bgcolor(red, This information is important.)}}} {{{bgcolor(#E0E0E0, This other isn’t.)}}}
Common color names are supported by most Org exporters (HTML, LaTeX):
{{{bgcolor(red, red)}}} {{{bgcolor(orange, orange)}}} {{{bgcolor(yellow, yellow)}}} {{{bgcolor(green, green)}}} {{{bgcolor(blue, blue)}}} {{{bgcolor(purple, purple)}}} {{{bgcolor(violet, violet)}}}
You can also use hexadecimal color codes:
{{{bgcolor(#FF0000, #FF0000)}}} {{{bgcolor(#00FF00, #00FF00)}}} {{{bgcolor(#0000FF, #0000FF)}}}
#+MACRO: clearpage @@latex:\\clearpage@@@@odt:<text:p text:style-name="PageBreak"/>@@
None.
The color
macro allows you to change the foreground color of inline text.
#+MACRO: color @@html:<span style="color: $1">$2</span>@@@@latex:\textcolor{$1}{$2}@@@@odt:<text:span text:style-name="$1">$2</text:span>@@
- Color name or hexadecimal code.
- Text you want to color.
{{{color(red, This information is important.)}}} {{{color(#E0E0E0, This other isn’t.)}}}
Common color names are supported by most Org exporters (HTML, LaTeX):
{{{color(red, red)}}} {{{color(orange, orange)}}} {{{color(yellow, yellow)}}} {{{color(green, green)}}} {{{color(blue, blue)}}} {{{color(purple, purple)}}} {{{color(violet, violet)}}}
You can also use hexadecimal color codes:
{{{color(#FF0000, #FF0000)}}} {{{color(#00FF00, #00FF00)}}} {{{color(#0000FF, #0000FF)}}}
The lcolor
macro is similar to color macro except (a) it first
converts org markup to latex and then applies color.
#+MACRO: lcolor (eval (concat "\n#+BEGIN_EXPORT latex\n {\color{" $1 (format "}{%s}}\n#+END_EXPORT\n" (org-export-string-as $2 'latex t))))
- Color name
- Text you want to color.
{{{lcolor(red, This information is **important**.)}}}
Common color names are supported by most Org exporters (HTML, LaTeX):
{{{color(red, red)}}} {{{color(orange, orange)}}} {{{color(yellow, yellow)}}} {{{color(green, green)}}} {{{color(blue, blue)}}} {{{color(purple, purple)}}} {{{color(violet, violet)}}}
The fixme
macro inserts a “Fix Me!” image (with adequate CSS).
#+MACRO: fixme @@html:<span class="fixme">FIXME</span>@@
CSS example:
.fixme {
background: #FFFF88 url('../images/fixme.png') no-repeat top left;
color: #CC0000;
display: inline-block;
height: 16px;
text-indent: -9999px;
width: 82px;
}
None.
{{{fixme}}} Delete this…
Testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing {{{FIXME}}} testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing
The highlight
macro allows you to change the background color of inline text.
#+MACRO: highlight @@html:<span style="background-color: $1;">$2</span>@@
- Color name or hexadecimal code.
- Text you want to color.
{{{highlight(red, Highlighting text is easy in Org mode.)}}} {{{highlight(#E0E0E0, This text isn’t important.)}}}
Common color names are supported by most Org exporters (HTML, LaTeX):
{{{highlight(red, red)}}} {{{highlight(orange, orange)}}} {{{highlight(yellow, yellow)}}} {{{highlight(green, green)}}} {{{highlight(blue, blue)}}} {{{highlight(purple, purple)}}} {{{highlight(violet, violet)}}}
You can also use hexadecimal color codes:
{{{highlight(#FF0000, #FF0000)}}} {{{highlight(#00FF00, #00FF00)}}} {{{highlight(#0000FF, #0000FF)}}}
The hl
macro allows you to highlight text with a “neon marker” effect.
#+MACRO: hl {{{highlight(#FFFF00,$1)}}}
- Color name or hexadecimal code.
- Text you want to color.
{{{hl(This information is important.)}}}
The loremipsum
macro displays one paragraph of meaningless text that you can
use for demonstration purposes of visual elements such as font, typography or
layout.
#+MACRO: loremipsum Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
None.
This is a basic example of the Loremipsum
text:
{{{loremipsum}}}
\\
in headlines doesn’t cause a line break, but gets exported in LaTeX to
$\backslash$
.
You have to put it in a macro.
#+MACRO: newline @@latex:\hspace{0pt}\\@@ @@html:<br>@@
None.
#+TITLE: Foo {{{newline}}} bar
Is there any way to completely redact text in HTML export, so it just looks like black boxes?
I’m not sure I fully understand, but it this what you are looking for?
To {{{redact(redact)}}} or not to {{{redact(redact)}}} that is the question.
#+MACRO: kbd @@html:<kbd>@@$1@@html:</kbd>@@
See menukeys
for LaTeX.
- Text to markup.
Use {{{kbd(C-c a a)}}} to launch the agenda.
#+MACRO: dvipng-when-odt (eval (if (org-export-derived-backend-p org-export-current-backend 'odt) "#+OPTIONS: tex:dvipng" ))
XXX
#+MACRO: if-latex-else (eval (if (org-export-derived-backend-p org-export-current-backend 'latex) "$1" "$2"))
- Code for LaTeX back-end.
- Code for other back-ends.
{{{if-latex-else(latex code,something else)}}}
The style
macro allows you to add custom style sheets to a page or import from
an external URL.
#+MACRO: style (eval (concat "#+HTML_HEAD_EXTRA: <style></style>"))
URL to import an external style sheet.
<style type=”text/css”> .atb-sidebar.expanded {display:run-in;} .atb-sidebar.collapsed {display:none;visibility:collapse;} </style>
<link type=”text/css” rel=”stylesheet” href=”http://whatever.com/mystyle.css” media=”all”>
The image
macro displays an image.
#+MACRO: image \includegraphics{$1}
- Path to image file.
{{{image}}}
{{{image(a.png)}}} | {{{image(b.png)}}} |
{{{image(c.png)}}} | {{{image(d.png)}}} |
The version-history
macro inserts the history of (the last 5) updates made to
a document: version number, date, author and comment.
XXX + link to View Changes?
#+name: version-history
#+begin_src shell :exports none :results silent :colnames '(Version Date Author Comment)
git log --pretty=format:"%h%x09%ad%x09%an%x09%s" --date=short | head -n 5
#+end_src
#+MACRO: version-history call_version-history[:eval yes]()[:eval yes :results table :colnames '(Version Date Author Comment)]
None.
This only will work with Git repositories.
{{{version-history}}}
The vspace
macro XXX.
#+MACRO: vspace @@latex:\vspace{10pt}@@@@html:<div style="margin-bottom: 10pt;"></div>@@
None.
The collapse
macro inserts of collapsed block of text.
None.
{{{collapse(View details…) This is a block of text that is collapsed by default. It can be expanded by clicking a link. }}}
The info
macro is useful for including helpful information.
#+MACRO: begin_info @@html:<div class="info"><p>@@
#+MACRO: end_info @@html:</p></div>@@
None.
{{{begin_info}}}
Info example
Did you know…
{{{end_info}}}
You’d better use a “special block”, such as:
#+begin_info *Info example* \\ Did you know... #+end_info
#+MACRO: BeginMiniPage @<div style="border:1px solid #aaaaaa;padding:10px;width:780px;margin-left:auto;margin-right:auto;">
#+MACRO: EndMiniPage @</div>
#+MACRO: begin_note @@html:<div class="note"><p>@@
#+MACRO: end_note @@html:</p></div>@@
None.
{{{begin_note}}}
Note example
This is a useful note…
{{{end_note}}}
You’d better use a “special block”, such as:
#+begin_note *Note example* \\ This is a useful note... #+end_note
#+MACRO: begin_panel @@html:<div class="panel"><p>@@
#+MACRO: end_panel @@html:</p></div>@@
XXX PanelHeader + PanelContent
None.
{{{begin_panel}}}
Panel example
This is a formatted block of text…
{{{end_panel}}}
You’d better use a “special block”, such as:
#+begin_panel *Panel example* \\ This is a formatted block of text... #+end_panel
#+MACRO: begin_tip @@html:<div class="tip"><p>@@
#+MACRO: end_tip @@html:</p></div>@@
None.
{{{begin_tip}}}
Tip example
Try doing it this way…
{{{end_tip}}}
You’d better use a “special block”, such as:
#+begin_tip *Tip example* \\ Try doing it this way... #+end_tip
#+MACRO: begin_warning @@html:<div class="warning"><p>@@
#+MACRO: end_warning @@html:</p></div>@@
None.
{{{begin_warning}}}
Warning example
Be careful! Check that you have…
{{{end_warning}}}
You’d better use a “special block”, such as:
#+begin_warning *Warning example* \\ Be careful! Check that you have... #+end_warning
I’m trying to create a simple two-column table. The left column will show images of symbols used in the document, and the right column will explain what those images mean.
{{{p(./GreenDot.png)}}} | This symbol indicates that the associated item is in a normal or successful state. |
{{{p(./YellowDots.png)}}} | This symbol denotes a state of concern or potential trouble for the associated item. |
{{{p(./RedDots.png)}}} | This symbol indicates that the associated item is in a severely troubled or non-functioning state. |
FIXME Problem with the tab title.
Insert a table of contents.
#+MACRO: toc #+toc: headlines $1
- Number of headline levels.
The toc
macro can’t be inlined in text.
Insert the TOC here, with one headline level:
{{{toc(1)}}}
Add a “Share a link” button to your website.
#+MACRO: twitter-share-link-button @@html:<script src="http://platform.twitter.com/widgets.js"></script><a href="https://twitter.com/share" class="twitter-share-button" data-via="$1">Tweet</a>@@
- Username.
Insert the Twitter “Share a link” button here:
{{{twitter-share-link-button(f_niessen)}}}
Keep a library of helpful CSS classes. Useful for debugging, but should be
avoided in the release version (separate markup and presentation). Since you
can use multiple class names (i.e. <p class="floatLeft alignLeft
width75">...</p>
), make use of them debugging your markup.
.width100 { width: 100%; }
.width75 { width: 75%; }
.width50 { width: 50%; }
.floatLeft { float: left; }
.floatRight { float: right; }
.alignLeft { text-align: left; }
.alignRight { text-align: right; }
.clear { clear: both; }
.float-left { float: left; }
.float-right { float: right; }
.highlight { background: #FFFFCC; }
.wrap { width: 960px; margin: 0 auto; }
.img-left { float: left; margin: 4px 10px 4px 0; }
.img-right { float: right; margin: 4px 0 4px 10px; }
.nopadding { padding: 0; }
.noindent { margin-left: 0; padding-left: 0; }
.nobullet { list-style: none; list-style-image: none; }
Report issues and suggest features and improvements on the GitHub issue tracker.
I love contributions! Patches under any form are always welcome!
If you use the org-macros project and feel it is making your life better and easier, you can show your appreciation and help support future development by making today a donation through PayPal. Thank you!
Regardless of the donations, org-macros will always be free both as in beer and as in speech.
Copyright (C) 2014-2022 Fabrice Niessen
Author: Fabrice Niessen
Keywords: org-mode macros
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.