0

I'm working on a big text in orgmode, which is expected to be finally exported to Latex & PDF, so I made this kind of a master document in orgmode:

#+SETUPFILE: exportoptions.org #+INCLUDE: "01.org" #+INCLUDE: "02.org" 

so I can work on individual chapters. Each of those also has

#+SETUPFILE: exportoptions.org 

at the top, so I can check the final result as I go. Only now I'm unable to export the master document as some of those options block Latex-ing when included more than once.

Is it possible to conditionally process the #+SETUPFILE directive, e.g. to ignore it when it's used in included files? I've thought :only-contents t would help, but no.

11
  • Not that I know of: you'll have to delete (or comment out) the #+SETUPFILE: lines in all the included files. Commented Mar 26, 2024 at 19:15
  • I was sort of hoping for some clever elisp trick to do that on the fly. I've seen some in the context of this SE, only I don't understand them. Commented Mar 27, 2024 at 4:04
  • If you provide links, I can take a look at them. Commented Mar 27, 2024 at 14:22
  • You can of course use tools to delete (or comment out) those lines: either on the command line with find and sed (on Linux or other *nix systems) or using Emacs search and replace facitilities Commented Mar 28, 2024 at 1:43
  • 1
    Perhaps you could leverage `org-export-before-parsing-functions' here. The Advanced Export Configuration of the manual shows this being used to delete content before processing. Commented May 1 at 15:48

1 Answer 1

0

As nothing seems to be forthcoming, I'm posting my stopgap solution, which demonstrably works, although not in a manner I'd wished.

Put the code into text file, change the working directory to where your .ORG files are, run the text file with the Bourne shell of your choice (BASH).

It will search for all .ORG files named by the pattern two numbers, not a number, something else, .org, then sort the names and merge the files into one .org file, removing SETUPFILE directive from all of those after the first one, and removing TOC directives from all but the 'real' TOC file (named two numbers, toc, .org).

There's some duplicated AWK code there, but I just didn't want to spend more time on this.

#! /bin/sh ttt="omg.org" # the final ORG file ddd="${PWD}/_tmp" mkdir -p "${ddd}" nnn="${ddd}/${ttt}" rm "${nnn}" # some naming conventions # two numbers and toc ending with .org # signifies TOC-containing file # which shouldn't be purged # the result goes into toc_if_any var toc_if_any=` find . -maxdepth 1 -name '*.org' \ | grep -E '//?[0-9][0-9][^0-9][^/]+$' \ | grep -E '([0-9][0-9]toc\.org)' \ | sort \ | head -n1 ` find . -maxdepth 1 -name '*.org' \ | grep -E '//?[0-9][0-9][^0-9][^/]+$' \ | sort \ | xargs -I [] \ \ sh -c " echo Doing \"[]\" this_is_toc=0 [ -n \"${toc_if_any}\" -a -f \"${toc_if_any}\" ] && ( echo \"[]\" | grep -E --quiet '[0-9][0-9]toc\.org\$' ) && this_is_toc=1 # reference with \$ ( 2>/dev/null 1>/dev/null grep -E -i '^#\\+setupfile' \"${nnn}\" && ( cat \"[]\" \ | awk -v this_is_toc=\$this_is_toc 'BEGIN {IGNORECASE=1 ; print \"\\n# !!! []\\n\"; } /^#\\+(setupfile)/ {next} /^#\\+(toc)/ { if (1 != this_is_toc) next } // {print \$0} ' \ >> \"${nnn}\" ; exit 0 ) ) || ( cat \"[]\" \ | awk -v this_is_toc=\$this_is_toc 'BEGIN {IGNORECASE=1 ; print \"# !!! []\"; } /^#\\+(toc)/ { if (1 != this_is_toc) next } // {print \$0} ' \ >> \"${nnn}\" ) " 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.