docs/manual/guide/12-export.org

a9ec94b75caa22bf47461bc180158d2b961bc747
orgstar/docs/manual/guide/12-export.org

319 lines · 25616 bytes

  1#+TITLE: Export
  2#+DESCRIPTION: Exporting Org files from orgstar to HTML, Markdown and PDF, and to LaTeX, ODT and plain text through Emacs.
  3#+LEDE: orgstar exports HTML, Markdown and PDF itself, on the Mac and iOS, and hands LaTeX, ODT, plain text and LaTeX-made PDF to Emacs on the Mac.
  4
  5* Exporting a file
  6
  7Export 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]].
  8
  9** On the Mac
 10
 11| Format             | Command                          | Emacs preset  | Doom                          | Needs Emacs |
 12|--------------------+----------------------------------+---------------+-------------------------------+-------------|
 13| HTML               | Export to HTML                   | =C-c C-e h h= | =SPC m e h h=, =C-c C-e h h= | no          |
 14| 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          |
 15| Markdown           | Export to Markdown               | =C-c C-e m m= | =SPC m e m m=, =C-c C-e m m= | no          |
 16| PDF                | Export to PDF                    | —             | —                             | no          |
 17| 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         |
 18| LaTeX              | Export to LaTeX with Emacs       | =C-c C-e l l= | =C-c C-e l l=                 | yes         |
 19| ODT                | Export to ODT with Emacs         | =C-c C-e o o= | =C-c C-e o o=                 | yes         |
 20| Plain text         | Export to Plain Text with Emacs  | =C-c C-e t u= | =C-c C-e t u=                 | yes         |
 21
 22The 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.
 23
 24All eight 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=, =.tex=, =.odt= or =.txt=. =#+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/".
 25
 26** The export dialog
 27
 28*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:
 29
 30- *Format*: HTML, Markdown, PDF, PDF via LaTeX (Emacs), ODT (Emacs), LaTeX (Emacs) or Plain text (Emacs).
 31- *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. 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.
 32- *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 =<html>=, =<head>= or the title; Markdown has no title heading. Not available for PDF and ODT.
 33- *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.
 34- *Open after export*: opens the file in its default app when the export finishes.
 35
 36The dialog remembers the format and the *Open after export* setting.
 37
 38** On iOS
 39
 40The Export menu offers HTML, Markdown and PDF. 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, plain text and PDF through LaTeX are not available on iOS.
 41
 42* HTML export
 43
 44orgstar 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=.
 45
 46** Title, author and date
 47
 48| Keyword    | Effect                                                                   |
 49|------------+--------------------------------------------------------------------------|
 50| =#+TITLE:= | The page title and a top heading. Without one, the file's name is used.  |
 51| =#+AUTHOR:=| Shown under the title.                                                   |
 52| =#+DATE:=  | Shown under the title, after the author, as written.                     |
 53
 54Keywords in files named by =#+SETUPFILE:= count, as they do in Org.
 55
 56** =#+OPTIONS=
 57
 58| Option  | Values                                | Default | Effect                                                                 |
 59|---------+---------------------------------------+---------+------------------------------------------------------------------------|
 60| =toc=   | =t=, =nil=, a number                  | =t=     | Table of contents, to the given depth. =t= goes to =H=.                |
 61| =num=   | =t=, =nil=, a number                  | =t=     | Section numbers, to the given depth. =t= goes to =H=.                  |
 62| =H=     | a number                              | =3=     | The deepest heading level the table of contents and numbering count.   |
 63| =tags=  | =t=, =nil=, =not-in-toc=              | =t=     | Heading tags; =not-in-toc= leaves them out of the table of contents.   |
 64| =todo=  | =t=, =nil=                            | =t=     | TODO keywords in headings.                                             |
 65| =pri=   | =t=, =nil=                            | =nil=   | Priority cookies in headings.                                          |
 66| =^=     | =t=, =nil=, ={}=                      | =t=     | =_= and =^= as subscripts and superscripts; ={}= only when braced, as in =x_{1}=. |
 67| =tex=   | =t=, =nil=                            | =t=     | LaTeX fragments and environments; =nil= drops them.                    |
 68| =title= | =t=, =nil=                            | =t=     | The title heading.                                                     |
 69| =author=| =t=, =nil=                            | =t=     | The author.                                                            |
 70| =date=  | =t=, =nil=                            | =t=     | The date.                                                              |
 71
 72A 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.
 73
 74#+BEGIN_SRC org
 75,#+TITLE: Field notes
 76,#+AUTHOR: Sam
 77,#+OPTIONS: toc:2 num:nil pri:t ^:{}
 78#+END_SRC
 79
 80** Which headings are exported
 81
 82- A heading tagged with one of =#+EXCLUDE_TAGS= (=noexport= by default) is left out, with everything under it.
 83- A heading whose title starts with =COMMENT= is left out.
 84- A heading tagged =ARCHIVE= is exported as the heading alone, without its contents.
 85- If any heading has one of =#+SELECT_TAGS= (=export= by default), only those headings, their ancestors and everything under them are exported.
 86
 87Each 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 =<h2>=, since the title is the =<h1>=.
 88
 89** The page head
 90
 91Each =#+HTML_HEAD:= and =#+HTML_HEAD_EXTRA:= line goes into the page's =<head>= as written, in order. Use them for stylesheets and scripts:
 92
 93#+BEGIN_SRC org
 94,#+HTML_HEAD: <link rel="stylesheet" href="notes.css">
 95#+END_SRC
 96
 97The built-in stylesheet is always included first. Other =#+HTML_…= keywords are not used.
 98
 99** Math
100
101LaTeX 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.
102
103** Includes
104
105=#+INCLUDE:= inserts another file before export, as =org-export-expand-include-keyword= does. Paths are relative to the Org file.
106
107| Form                                          | Effect                                                    |
108|-----------------------------------------------+-----------------------------------------------------------|
109| =#+INCLUDE: "part.org"=                       | The file's contents, read as Org; its includes are expanded too, up to eight levels. |
110| =#+INCLUDE: "part.org::*Heading"=             | Only the subtree with that heading.                        |
111| =#+INCLUDE: "part.org::#custom-id"=           | Only the subtree with that =CUSTOM_ID=.                    |
112| =#+INCLUDE: "code.sh" src sh=                 | The file in a source block.                                |
113| =#+INCLUDE: "log.txt" example=                | The file in an example block.                              |
114| =#+INCLUDE: "page.html" export html=          | The file in an export block.                               |
115| =quote=, =verse=, =center=, =comment=         | The file in a block of that kind.                          |
116| =:lines "5-10"=                               | Only those lines; either end may be left out.              |
117| =:minlevel 2=                                 | Shift the included headings so the shallowest is at that level. |
118
119A file that cannot be read is replaced by an empty line.
120
121** Macros
122
123={{{name(arguments)}}}= is replaced before export (=org-macro-replace-all=).
124
125| Macro                        | Replaced by                                                          |
126|------------------------------+----------------------------------------------------------------------|
127| =#+MACRO: name text=         | =text=, with =$1=, =$2=… replaced by the arguments.                   |
128| ={{{title}}}=, ={{{author}}}=, ={{{date}}}=, ={{{email}}}= | That keyword's value.                     |
129| ={{{keyword(NAME)}}}=        | The value of =#+NAME:=.                                               |
130| ={{{input-file}}}=           | The Org file's name.                                                  |
131| ={{{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. |
132| ={{{property(NAME,SEARCH)}}}= | The same for the entry =SEARCH= finds in this file: =*Title=, =#custom-id= or a title. |
133| ={{{n}}}=, ={{{n(name)}}}=   | A counter, increased at each use. =n(name,-)= repeats the current value; =n(name,5)= sets it to 5. |
134| ={{{time(format)}}}=         | The current time, formatted as =format-time-string= does.             |
135
136Arguments 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.
137
138** Footnotes
139
140Footnote 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.
141
142** Tables
143
144An Org table becomes an HTML =<table>=. If it has rules, the rows before the first rule are the header (=<thead>=) and the rest the body. =#+CAPTION:= gives the table a caption. =#+TBLFM:= lines are not exported.
145
146A 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.
147
148** Images and links
149
150A link to an image file without a description becomes an =<img>=. 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.
151
152An image paragraph with =#+CAPTION:= or =#+ATTR_HTML:= becomes a =<figure>=; a caption is numbered "Figure 1:", "Figure 2:" and so on.
153
154Links 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.
155
156** Source blocks and their results
157
158A source block is exported as =<pre><code class="language-LANG">=, 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 =<span>= 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. Line-number switches are ignored.
159
160The 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.
161
162| =:exports=       | Exported                                  |
163|------------------+-------------------------------------------|
164| =code=           | The code.                                 |
165| =results=        | The block's existing =#+RESULTS:=.        |
166| =both=           | The code, then the results.               |
167| =none=           | Nothing.                                  |
168
169A =#+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 =<code>= 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.
170
171** Other blocks and elements
172
173| Org                              | HTML                                            |
174|----------------------------------+-------------------------------------------------|
175| =#+begin_example=                | =<pre>=                                         |
176| =: = lines                       | =<pre class="example">=                         |
177| =#+begin_quote=                  | =<blockquote>=                                  |
178| =#+begin_center=                 | =<div class="center">=                          |
179| =#+begin_verse=                  | =<p class="verse">=, lines and indentation kept |
180| =#+begin_export html=            | Its contents, as they are                       |
181| =#+begin_export= other formats   | Nothing                                         |
182| =#+begin_comment=                | Nothing                                         |
183| =#+begin_NAME=, any other name   | =<div class="NAME">= (a special block)          |
184| =@@html:…@@=                     | Its contents, as they are; other back-ends' snippets are dropped |
185| Plain, numbered and description lists | =<ul>=, =<ol>=, =<dl>=; checkboxes as =[X]=, =[-]=, =[ ]= |
186| Timestamps                       | =<time datetime="…">=                           |
187| Inline tasks                     | =<div class="inlinetask">= with the title in bold |
188| Dynamic blocks                   | Their contents                                  |
189| =-----=                          | =<hr>=                                          |
190
191Comments, drawers, property drawers, planning lines, clock lines and keywords are not exported.
192
193** Citations
194
195HTML and Markdown export handle citations the same way; see Citations below.
196
197* PDF export
198
199Export to PDF makes the HTML export into a PDF, laid out and split into pages by the system's web engine as printing does. It needs neither Emacs nor TeX, and works on iOS. The PDF has what the HTML export has: the title, the byline, the table of contents, colored code, tables, images and math (MathJax, which needs a network connection). For the page:
200
201- Colors are always the light ones, whatever the system's appearance.
202- Pages are US Letter where that is the usual size and A4 elsewhere; on the Mac, the paper size set for printing.
203- Code blocks, tables, figures and quotes are kept on one page when they fit, and a heading is not left at the bottom of a page.
204
205For typeset output with LaTeX's classes and packages, use Export to PDF with Emacs instead (see /Exporting through Emacs/).
206
207* Markdown export
208
209Markdown export writes GitHub-flavored Markdown:
210
211- =#+TITLE:= becomes a top =#= heading. Org headings are one level down: =*= is =##=. TODO keywords stay in the heading text, and tags are shown as inline code. Priority cookies are left out unless =#+OPTIONS= has =pri:t=.
212- Source blocks become fenced code blocks with the language; example blocks, =: = lines and table.el tables become fenced blocks without one.
213- Tables become pipe tables. A rule after the first row makes it the header; otherwise the header row is empty.
214- Checkboxes become task-list items (=- [x]=, =- [ ]=).
215- Footnotes become =[^1]= references with the notes at the end.
216- Quotes become =>= blocks. Verse lines end with two spaces.
217- Images become =![](path)=. Links to =.org= files, with or without =file:=, point to the =.md= file of the same name; a search option after =::= is dropped.
218- =#+begin_export= blocks for =markdown=, =md= or =html=, and =@@html:…@@= snippets, are copied as they are.
219- Underline, subscripts and superscripts are written as HTML tags.
220- =:exports= is handled as in HTML export.
221- Citations are handled as in HTML export.
222
223As in HTML export, =#+INCLUDE:= lines are expanded and macros replaced first, and =#+EXCLUDE_TAGS=, =#+SELECT_TAGS=, =COMMENT= headings and =ARCHIVE= tags decide which headings are exported (see /Which headings are exported/). Of the =#+OPTIONS=, Markdown export reads =todo=, =pri=, =tags=, =^= and =title=; the others do not apply. It writes no author or date.
224
225* Exporting through Emacs
226
227On the Mac, PDF, LaTeX, ODT and plain text exports are done by Emacs, with the =ox= functions Emacs's dispatcher uses:
228
229| Format     | Function                    |
230|------------+-----------------------------|
231| PDF        | =org-latex-export-to-pdf=   |
232| LaTeX      | =org-latex-export-to-latex= |
233| ODT        | =org-odt-export-to-odt=     |
234| Plain text | =org-ascii-export-to-ascii= |
235
236orgstar runs =emacs -Q --batch= in the Org file's folder. It opens the file, replaces its contents with the editor's current text without saving, and calls the function. Emacs writes the result beside the file, as it would itself; with a destination chosen in the export dialog, orgstar then moves it there. The message area shows "Exporting with Emacs…" and then "Exported to /name/".
237
238What you need:
239
240- Emacs, at =ORGSTAR_EMACS= or one of =/opt/homebrew/bin/emacs=, =/usr/local/bin/emacs=, =/Applications/Emacs.app/Contents/MacOS/Emacs=, =/run/current-system/sw/bin/emacs= or =/usr/bin/emacs=. Without it the export fails with "Emacs isn't installed, so this format can't be exported."
241- For PDF, a TeX installation that Emacs's LaTeX export can run. Emacs runs with your =PATH= plus =/opt/homebrew/bin=, =/usr/local/bin=, =/Library/TeX/texbin=, =/usr/bin= and =/bin=, the same as code blocks get, so =latexmk= and =pdflatex= from MacTeX or Homebrew are found when orgstar was opened from the Dock.
242
243Things to know:
244
245- =-Q= means Emacs does not load your init file. Your LaTeX classes, export settings and packages from it are not used; the export uses Org's defaults and what the file itself sets.
246- File-local variables are applied only when Emacs considers them safe.
247- =org-export-use-babel= is off, so no source blocks run.
248- An export that takes more than two minutes is stopped with "Emacs took too long to export."
249- Edit ▸ Cancel Running Task (=⌘.=) stops the export and shows "Export canceled". Starting another export or table recalculation in Emacs cancels the one that is running.
250- If Emacs fails, the message area shows the last line of its error output.
251
252To use your own Emacs configuration, or formats orgstar does not list, export from Emacs itself; see [[file:15-alongside-emacs.org][Alongside Emacs]].
253
254* Citations
255
256HTML and Markdown export process citations as Org's =basic= citation processor does (=oc-basic=).
257
258#+BEGIN_SRC org
259,#+bibliography: refs.bib
260,#+cite_export: basic author-year
261
262As shown in [cite:@smith2020], and again [cite/t:@smith2020; see @lee2019 p. 4].
263
264,#+print_bibliography:
265#+END_SRC
266
267** Bibliography files
268
269Each =#+bibliography:= line names one file, relative to the Org file, optionally in quotes. A file ending in =.json= is read as CSL-JSON; anything else is read as BibTeX, with =@string= abbreviations expanded and =@comment= and =@preamble= skipped. You can have several =#+bibliography:= lines; for a key in more than one file, the first file wins.
270
271** =#+cite_export:=
272
273=#+cite_export: PROCESSOR [BIBLIOGRAPHY-STYLE [CITATION-STYLE]]=.
274
275- With no =#+cite_export:=, or with =basic=, citations are processed.
276- With any other processor, such as =csl= or =biblatex=, orgstar leaves citations as they are written.
277- The citation style, which may include a variant (=text/bare=), is the default for citations that do not name one.
278
279** Citation styles
280
281A citation is =[cite:…]= or =[cite/style:…]= or =[cite/style/variant:…]=, holding one or more =@key= references separated by =;=. Each reference may have its own prefix and suffix, and the whole citation a common prefix and suffix.
282
283| Style                         | Output                                                                  |
284|-------------------------------+-------------------------------------------------------------------------|
285| default (none given)          | =(Author, Year)=                                                        |
286| =author=, =a=                 | =Author=                                                                |
287| =noauthor=, =na=              | =(Year)=                                                                |
288| =text=, =t=                   | =Author (Year)=                                                         |
289| =note=, =ft=                  | A footnote holding the =text= form                                      |
290| =numeric=, =nb=               | =(1)=, numbered by the cited works sorted by author; three or more in a row as =1-3= |
291| =nocite=, =n=                 | Nothing; the work is still listed in the bibliography                   |
292
293| Variant              | Effect                                     |
294|----------------------+--------------------------------------------|
295| =bare=, =b=          | No parentheses                             |
296| =caps=, =c=          | Capitalized author                         |
297| =bare-caps=, =bc=    | Both                                       |
298
299Works by the same author in the same year get =a=, =b=, … after the year. A key not found in any bibliography file shows as =??= and =????=. Citations in the title are dropped.
300
301For =note= citations, the blank before the citation is removed and punctuation right after it moves in front of the footnote mark, as =org-cite-adjust-note= does.
302
303** The bibliography
304
305=#+print_bibliography:= is replaced by an entry for every cited work, sorted by author. The bibliography style from =#+cite_export:= sets the form:
306
307| Bibliography style     | Entry                                                    |
308|------------------------+----------------------------------------------------------|
309| default                | =Author (Year). /Title/, Publisher.=                     |
310| =plain=                | =Surnames. Title, Publisher, Year.=                      |
311| =numeric=              | =[1] Author, /Title/, Publisher, Year.=                  |
312
313The publisher part comes from the =publisher=, =journal=, =institution= or =school= field. Without =#+print_bibliography:= no bibliography is written.
314
315* What export does not do
316
317- Subtree and body-only export are in the export dialog only; the single-format commands export the whole file. There is no asynchronous export.
318- Source blocks are not run, and noweb references are not expanded.
319- Export settings in the dialog are not per file.
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form