#+TITLE: Export
#+DESCRIPTION: Exporting Org files from orgstar to HTML, Markdown, PDF, Word, RTF, plain text and iCalendar, and to LaTeX, ODT and ASCII through Emacs; copying as rich text.
#+LEDE: orgstar exports HTML, Markdown, PDF, Word, RTF, plain text and iCalendar itself, and hands LaTeX, ODT, ASCII and LaTeX-made PDF to Emacs on the Mac.
* Exporting a file
Export works on the file in the current editor, using its text as it is now, saved or not. It applies to Org files only; in any other file the command says "Not an org file". Source blocks are never run during export. Results already in the file are exported as they are; see [[file:11-code-blocks.org][Code blocks]].
** On the Mac
| Format | Command | Emacs preset | Doom | Needs Emacs |
|--------------------+----------------------------------+---------------+-------------------------------+-------------|
| HTML | Export to HTML | =C-c C-e h h= | =SPC m e h h=, =C-c C-e h h= | no |
| HTML, then open it | Export to HTML and Open | =C-c C-e h o= | =SPC m e h o=, =C-c C-e h o= | no |
| Markdown | Export to Markdown | =C-c C-e m m= | =SPC m e m m=, =C-c C-e m m= | no |
| PDF | Export to PDF | — | — | no |
| Word | Export to Word | — | — | no |
| RTF | Export to RTF | — | — | no |
| Plain text | Export to Plain Text | — | — | no |
| PDF through LaTeX | Export to PDF with Emacs | =C-c C-e l p= | =SPC m e l p=, =C-c C-e l p= | yes |
| LaTeX | Export to LaTeX with Emacs | =C-c C-e l l= | =C-c C-e l l= | yes |
| ODT | Export to ODT with Emacs | =C-c C-e o o= | =C-c C-e o o= | yes |
| ASCII text | Export to Plain Text with Emacs | =C-c C-e t u= | =C-c C-e t u= | yes |
| iCalendar | Export to iCalendar | =C-c C-e c f= | =C-c C-e c f= | no |
| iCalendar, every agenda file | Export Agenda Files to iCalendar | =C-c C-e c a= | =C-c C-e c a= | no |
| iCalendar, agenda files in one | Combine Agenda Files into iCalendar | =C-c C-e c c= | =C-c C-e c c= | no |
The keys follow Emacs's export dispatcher (=org-export-dispatch=). =C-c C-e= on its own is only a prefix: pause after it and the key hints list the formats. The =SPC m e= keys work in normal state; the =C-c C-e= keys work in every Doom state. The Mac preset has no keys for the single formats; its =⇧⌘E= opens the export dialog.
All fourteen commands are in File ▸ Export and in the command palette. They write the export beside the Org file, with the same name and the format's extension: =.html=, =.md=, =.pdf=, =.docx=, =.rtf=, =.tex=, =.odt=, =.txt= or =.ics=. The two agenda-file commands are the exceptions; see [[*iCalendar export][iCalendar export]]. =#+EXPORT_FILE_NAME:= names it instead, as in Org: relative to the Org file's folder (or absolute, or starting with =~=), with its extension replaced by the format's, so =#+EXPORT_FILE_NAME: out/report= writes =out/report.html=. A file already there is replaced. The message area shows "Exported to /name/".
The [[file:../install.org][Mac App Store version]] has the ten commands that don't need Emacs; File ▸ Export, the export dialog and the command palette leave out the other four, and a key bound to Export to PDF with Emacs runs Export to PDF. When the export file, or an =#+INCLUDE:= or =#+SETUPFILE:=, is outside your folders, orgstar first asks for access to its folder; for the export file, Save Elsewhere… instead picks another place. See [[file:../install.org][Install]].
** The export dialog
*Export…* in the command palette, or =⇧⌘E= in the Mac preset, opens a dialog. The Emacs and Doom presets have no key for it; bind =app.export-dialog= in =keymap.toml= if you want one (see [[file:03-keys.org][Keys and commands]]). The dialog has:
- *Format*: HTML, Markdown, PDF, Word, Rich Text (RTF), Plain text, PDF via LaTeX (Emacs), ODT (Emacs), LaTeX (Emacs), Plain text, ASCII (Emacs) or iCalendar.
- *Scope*: the whole file, or the subtree at the caret (Org's =C-s= in the dispatcher). A subtree is exported as a document of its own: its heading is the title, its text the body, and its child headings move up a level. iCalendar is the exception: there the subtree's heading is an entry like any other. The file's =#+= keywords still apply, and the heading's =EXPORT_TITLE=, =EXPORT_AUTHOR=, =EXPORT_DATE=, =EXPORT_EMAIL=, =EXPORT_OPTIONS=, =EXPORT_SELECT_TAGS=, =EXPORT_EXCLUDE_TAGS=, =EXPORT_HTML_HEAD= and =EXPORT_HTML_HEAD_EXTRA= properties override them. Its planning line and property drawer are left out. The choice is available when the caret is under a heading.
- *Body only*: leave out the title and the page around the text (Org's =C-b=). HTML is then the table of contents, the text and the footnotes, without ==, =
= or the title; Markdown has no title heading. Not available for PDF, Word, RTF, plain text, ODT and iCalendar.
- *Destination*: where =#+EXPORT_FILE_NAME:= says, or the subtree's =EXPORT_FILE_NAME= property for a subtree, else beside the Org file. *Choose…* picks another place and name. Changing the format changes the extension.
- *Margins*, *Font* and *Page numbers*, for PDF: see /PDF export/.
- *Open after export*: opens the file in its default app when the export finishes.
The dialog remembers the format and the *Open after export* setting. The PDF settings are =config.toml= settings, and apply to every PDF export.
** On iOS
The Export menu offers HTML, Markdown, PDF, Word, Rich Text (RTF), Plain Text and iCalendar, and Copy as Rich Text. It is under More in the editor, and in the toolbar in the reader. Choosing one opens the share sheet with the exported file, named after the Org file or its =#+EXPORT_FILE_NAME:=. Send it to another app, or use Save to Files to keep it. The export is the same as on the Mac. LaTeX, ODT, ASCII and PDF through LaTeX are not available on iOS, nor are the agenda-file iCalendar exports.
* HTML export
orgstar writes a complete HTML page: a small built-in stylesheet that follows the system's light or dark appearance, the title, an author and date line, the table of contents, then the document. It does not use Emacs, and its output is close to, but not the same as, =ox-html=.
** Title, author and date
| Keyword | Effect |
|------------+--------------------------------------------------------------------------|
| =#+TITLE:= | The page title and a top heading. Without one, the file's name is used. |
| =#+AUTHOR:=| Shown under the title. |
| =#+DATE:= | Shown under the title, after the author, as written. |
| =#+LANGUAGE:= | The page's =lang=, and the language of the words the export writes: the table of contents heading, =Figure N:= captions and the footnotes' label, as Org's =org-export-dictionary= translates them. Without one, =org-export-default-language= (=en=). |
Keywords in files named by =#+SETUPFILE:= count, as they do in Org.
** =#+OPTIONS=
| Option | Values | Default | Effect |
|---------+---------------------------------------+---------+------------------------------------------------------------------------|
| =toc= | =t=, =nil=, a number | =t= | Table of contents, to the given depth. =t= goes to =H=. |
| =num= | =t=, =nil=, a number | =t= | Section numbers, to the given depth. =t= goes to =H=. |
| =H= | a number | =3= | The deepest heading level the table of contents and numbering count. |
| =tags= | =t=, =nil=, =not-in-toc= | =t= | Heading tags; =not-in-toc= leaves them out of the table of contents. |
| =todo= | =t=, =nil= | =t= | TODO keywords in headings. |
| =pri= | =t=, =nil= | =nil= | Priority cookies in headings. |
| =^= | =t=, =nil=, ={}= | =t= | =_= and =^= as subscripts and superscripts; ={}= only when braced, as in =x_{1}=. |
| =tex= | =t=, =nil= | =t= | LaTeX fragments and environments; =nil= drops them. |
| =title= | =t=, =nil= | =t= | The title heading. |
| =author=| =t=, =nil= | =t= | The author. |
| =date= | =t=, =nil= | =t= | The date. |
A depth for =toc= or =num= larger than =H= is cut to =H=. Any value other than =nil= turns an option on. Other =#+OPTIONS= keys are ignored by HTML export. iCalendar export also reads =<= (see /iCalendar/ below) and =-=, which is on by default and turns =---=, =--= and =...= into dashes and an ellipsis in the text it writes.
#+BEGIN_SRC org
,#+TITLE: Field notes
,#+AUTHOR: Sam
,#+OPTIONS: toc:2 num:nil pri:t ^:{}
#+END_SRC
** Which headings are exported
- A heading tagged with one of =#+EXCLUDE_TAGS= (=noexport= by default) is left out, with everything under it.
- A heading whose title starts with =COMMENT= is left out.
- A heading tagged =ARCHIVE= is exported as the heading alone, without its contents.
- If any heading has one of =#+SELECT_TAGS= (=export= by default), only those headings, their ancestors and everything under them are exported.
Each heading gets an =id= for links: its =CUSTOM_ID= property, or a slug made from its title. Headings are one level down from Org's: a top-level heading is an =
=, since the title is the =
=.
** The page head
Each =#+HTML_HEAD:= and =#+HTML_HEAD_EXTRA:= line goes into the page's == as written, in order. Use them for stylesheets and scripts:
#+BEGIN_SRC org
,#+HTML_HEAD:
#+END_SRC
The built-in stylesheet is always included first. Other =#+HTML_…= keywords are not used.
** Math
LaTeX fragments (=\(…\)=, =\[…\]=, =$…$=, =$$…$$=) and LaTeX environments are left in the page for MathJax. When the page has any, orgstar adds MathJax 3 from =cdn.jsdelivr.net=, so the page needs a network connection to show math. Entities such as =\alpha= become their characters.
** Includes
=#+INCLUDE:= inserts another file before export, as =org-export-expand-include-keyword= does. Paths are relative to the Org file.
| Form | Effect |
|-----------------------------------------------+-----------------------------------------------------------|
| =#+INCLUDE: "part.org"= | The file's contents, read as Org; its includes are expanded too, up to eight levels. |
| =#+INCLUDE: "part.org::*Heading"= | Only the subtree with that heading. |
| =#+INCLUDE: "part.org::#custom-id"= | Only the subtree with that =CUSTOM_ID=. |
| =#+INCLUDE: "code.sh" src sh= | The file in a source block. |
| =#+INCLUDE: "log.txt" example= | The file in an example block. |
| =#+INCLUDE: "page.html" export html= | The file in an export block. |
| =quote=, =verse=, =center=, =comment= | The file in a block of that kind. |
| =:lines "5-10"= | Only those lines; either end may be left out. |
| =:minlevel 2= | Shift the included headings so the shallowest is at that level. |
A file that cannot be read is replaced by an empty line.
** Macros
={{{name(arguments)}}}= is replaced before export (=org-macro-replace-all=).
| Macro | Replaced by |
|------------------------------+----------------------------------------------------------------------|
| =#+MACRO: name text= | =text=, with =$1=, =$2=… replaced by the arguments. |
| ={{{title}}}=, ={{{author}}}=, ={{{date}}}=, ={{{email}}}= | That keyword's value. |
| ={{{keyword(NAME)}}}= | The value of =#+NAME:=. |
| ={{{input-file}}}= | The Org file's name. |
| ={{{property(NAME)}}}= | The value of property =NAME= of the entry the macro is in; =ITEM= gives the heading's title. Empty before the first heading. |
| ={{{property(NAME,SEARCH)}}}= | The same for the entry =SEARCH= finds in this file: =*Title=, =#custom-id= or a title. |
| ={{{n}}}=, ={{{n(name)}}}= | A counter, increased at each use. =n(name,-)= repeats the current value; =n(name,5)= sets it to 5. |
| ={{{time(format)}}}= | The current time, formatted as =format-time-string= does. |
Arguments are separated by commas; write =\,= for a literal comma. Macros defined with =(eval …)=, and macros orgstar does not know, become empty. =#+MACRO:= definitions in setup files count.
** Footnotes
Footnote references, named or inline (=[fn:: text]=), become numbered superscript links. The notes are collected in a Footnotes section at the end, numbered in the order they are first referenced, each with a link back. A reference without a definition is exported as written.
** Tables
An Org table becomes an HTML =
=. If it has rules, the rows before the first rule are the header (==) and the rest the body. =#+CAPTION:= gives the table a caption. =#+TBLFM:= lines are not exported.
A table.el table (one drawn with =+=, =-= and =|=) becomes a table with each cell's =colspan= and =rowspan=, and the lines in a cell joined with line breaks. If its drawing is not a well-formed table, it is exported as preformatted text.
** Images and links
A link to an image file without a description becomes an ==. The image types are =png=, =jpg=, =jpeg=, =gif=, =svg=, =webp=, =bmp=, =tif=, =tiff= and =avif=. =#+ATTR_HTML:= before the paragraph adds attributes (=:width 300 :alt "Map"=); without an =:alt=, the file name is used.
An image paragraph with =#+CAPTION:= or =#+ATTR_HTML:= becomes a ==; a caption is numbered "Figure 1:", "Figure 2:" and so on.
Links to =.org= files point to the =.html= file of the same name. Links to headings (=[[*Heading]]=), to =CUSTOM_ID= targets and to radio targets point to the heading's or target's =id= on the page. =id:= links point to =#= and the ID. Other links are written as they are.
** Source blocks and their results
A source block is exported as =
=, with the code escaped and its common indentation removed. Code in a language the editor highlights is colored as the editor colors it: each token is a == with the class Emacs's htmlize gives its face (=org-keyword=, =org-string=, =org-comment=, =org-function-name=, =org-type=, =org-constant=, =org-property-name=, =org-variable-name=), and the page's stylesheet colors them with the theme's =syntax-= colors, light and dark. Other languages are exported plain; the =language-= class lets a script or stylesheet in =#+HTML_HEAD= highlight them. Noweb references are shown as written. Code references are covered in [[file:09-links.org][Links]]: labels come off the lines, =-n= and =+n= number them, and =[[(name)]]= links to the labelled line.
The block's =:exports= header argument decides what appears. orgstar resolves it as running the block would: from the =#+begin_src= line, =#+HEADER:= lines, =header-args= properties and =#+PROPERTY:= lines (see [[file:11-code-blocks.org][Code blocks]]). Without one, it is =results= for =dot=, =plantuml=, =ditaa=, =gnuplot=, =latex= and =lilypond= blocks, as their Org defaults set it, and =code= for other languages.
| =:exports= | Exported |
|------------------+-------------------------------------------|
| =code= | The code. |
| =results= | The block's existing =#+RESULTS:=. |
| =both= | The code, then the results. |
| =none= | Nothing. |
A =#+CALL:= line exports its existing results, never the call itself; =:exports code= or =none= on the call, or in the =header-args= properties where the call is, exports nothing. An inline =src_= block has =:exports results= by default: the ={{{results(…)}}}= after it is exported and its code is not. With =:exports code= the code is exported in == and the results are not; with =both=, both. An inline =call_= never appears itself, and the ={{{results(…)}}}= after it is always exported, whatever =:exports= says, as in Org.
** Other blocks and elements
| Org | HTML |
|----------------------------------+-------------------------------------------------|
| =#+begin_example= | =
= |
| =: = lines | =
= |
| =#+begin_quote= | =
= |
| =#+begin_center= | =
= |
| =#+begin_verse= | =
=, lines and indentation kept |
| =#+begin_export html= | Its contents, as they are |
| =#+begin_export= other formats | Nothing |
| =#+begin_comment= | Nothing |
| =#+begin_NAME=, any other name | =
= (a special block) |
| =@@html:…@@= | Its contents, as they are; other back-ends' snippets are dropped |
| Plain, numbered and description lists | =