2

Pretext

I am using the emacs batch mode to script the export of .org files to LaTeX via a Makefile, and I am aware of some of the customization options that exist in that regard.

For example, I can (under Emacs 25.2.2 with org-mode 9.1.11) successfully use the command

emacs my.org --batch --eval "(org-latex-export-to-latex nil nil nil t)" --kill

to export only the body (via the fourth argument set to t) of my.org file to my.tex. The arguments of org-latex-export-to-latex are described at https://github.com/emacsmirror/org/blob/master/lisp/ox-latex.el#L3588.

Problem description

I am now looking for a possibility to batch-export a specific subtree from an .org file. In other words, while I have already managed to script the 'body-only' C-e C-b option of a manual org-mode export, I am now trying to also automate its C-e C-s option.

This raises the question of how to identify the desired subtree to-be-exported.

Not quite what I want: Export by ID via .el script

The exact same problem that I am describing is also formulated at

https://lists.gnu.org/archive/html/emacs-orgmode/2015-02/msg00133.html

The responses suggest to export a section by its ID property and include pointers to

for according emacs-lisp code, as well as a more specific emacs-lisp code example, which I can successfully get to export a specific section by its CUSTOM_ID property.

However, this solution has the following flaws:

  1. It includes the heading of the section identified by CUSTOM_ID, whereas a subtree exported manually via C-e C-s contains only the content of the exported section (which is what I want).
  2. It requires me to specify CUSTOM_IDs, whereas I am hoping to identify the subtree to-be-exported by the text of its headline.
  3. It requires emacs-lisp code. :)

Perhaps a better solution: 2nd argument of org-latex-export-to-latex?

The code for org-latex-export-to-latex at https://github.com/emacsmirror/org/blob/master/lisp/ox-latex.el#L3575 shows that its second argument relates to the export of subtrees, and I am wondering whether it can be used to achieve my goals outlined above.

The comment at https://github.com/emacsmirror/org/blob/master/lisp/ox-latex.el#L3588 says:

When optional argument SUBTREEP is non-nil, export the sub-tree at point, extracting information from the headline properties first.

However, the code comment above to me raises the following questions:

  • What does "at point" mean?
  • How exactly would it "extract information from the headline properties"
  • What meaningful non-nil values can I set this option to?

I would appreciate examples of how the second argument of org-latex-export-to-latex can be used in practice.

0

1 Answer 1

1

You can try something like:

emacs my.org --batch --eval \
      "(progn (re-search-forward \"CUSTOM_ID: ${FOO}\") \
              (org-latex-export-to-latex nil t nil t))"

[ Note: 100% untested ]

1
  • The search should include the headline (see point 2). Looks good otherwise. Related.
    – jagrg
    Dec 27, 2019 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.