Orm Finnendahl writes: > To recapitulate: In my code, org-export-as calls process-multipage in > the backend. This function: > > - collects and adds information necessary for org-multipage to do its > job, splitting the document into different parts, etc. and > > - then calls org-export-data on the subtrees and exports each returned > string to an individual file. > > - It finally issues a done string and executes a browser open/visit > file or simply exits nil. Currently, org-export-as does the following: 1. Compute global export attributes, according to the selected export backend 2. Copy original buffer into working copy 3. Process and parse the copy, generating AST 4. Do the actual export You plugged your multipage processing into (4), but what it actually does involves (3), (4), and also a new kind of post-processing. I do not think that it is a good design from the point of view of ox.el. I prefer to reuse or extend the existing mechanisms if at all possible - this makes new features less confusing for users and backend developers. > - collects and adds information necessary for org-multipage to do its > job, splitting the document into different parts, etc. and What you describe here is more or less what :filter-parse-tree filters do - they can rearrange the parse tree before passing it to the transcoders. Why not reusing it for multipage export? > - then calls org-export-data on the subtrees and exports each returned > string to an individual file. And you simply call `org-export-transcode-page' for this, followed by writing the returned string to file. The first part can fit within `org-export-as', but writing to file is going a step beyond, duplicating what `org-export-to-file' does. > - It finally issues a done string and executes a browser open/visit > file or simply exits nil. ... which again steps beyond `org-export-as' scope - post-processing is currently done as a part of `org-export-to-file'/`org-export-to-buffer'. ---- Let me propose the following changes to ox.el: 1. org-data will be transcoded using `org-export-transcode-org-data', which can be overridden by setting org-data transcoders in the individual backends. 2. org-export-as will understand transcoded output to be a list of strings and will transfer INFO plist as text property in the return values 3. org-export-to-file will make use of the text properties to retrieve the file name to write. This way, export backend itself can assign the file names where each exporter string should go. I believe that my changes should allow you to implement multipage export in the following way: 1. You can use :filter-parse-tree in ox-html backend to replace the original (org-data ...) AST with a list of ((org-page ...) (org-page ...) ...) pseudo-elements and populate INFO channel with auxiliary information you now compute in `org-html-process-multipage' 2. You can define org-page transcoder to render individual pages as needed 3. You can assign :output-file text property to the returned org-page strings and use org-export-to-file to generate the multipage output on disk 4. You can handle opening exported files by augmenting POST-PROCESS argument in `org-html-export-to-multipage-html' and calling `org-export-file' instead of `org-export-as'. The tentative patches (against Org mode main branch) implementing my changes are attached.