I am writing a document where I have a collection of code for different topics. My document structure is as follows.

* Heading1

Some text
#+include: "Heading1/file11.py" src python

Test illustrating something else
#+include: "Heading1/file64.py" src python

* Heading2

Some text
#+include: "Heading2/file84.py" src python

Test illustrating something else
#+include: "Heading2/file96.py" src python

My directory structure is as below.

├── Heading1
│   ├── file11.py
│   └── file64.py
└── Heading2
    ├── file84.py
    └── file96.py

Is there a way I can do something like the following where I declare each base folder under each heading so that I don't have to repeatedly write the heading when I include the source file?

* Heading1
#+declare base foldername as Heading1

Some text
#+include: "file11.py" src python
  • I don't think so.
    – NickD
    Jul 20, 2020 at 20:56
  • @NickD alright, so is there a better way for my process that I can improve? I somehow find that I might be inefficient... Not sure.. Jul 20, 2020 at 21:11
  • 1
    IMO there is very little efficiency to be gained by having the pathname filled in automatically, but it all depends on the numbers. If you have a lot of includes and the pathname is long and complicated, then type it once, save it in a buffer and yank it every time you need to (or equivalently, copy it to the clipboard and paste it)- you can take care of minor differences, like the appended number after "Heading" in your example, by typing it by hand. If it gets tiring and repetitive, then you automate more. Note that there are stages of automation too: it's not all or nothing.
    – NickD
    Jul 21, 2020 at 11:47
  • You might also look into keyboard macros : it allows you to record a series of keys and save them in a macro. The macro can then be replayed.
    – NickD
    Jul 21, 2020 at 16:19


Your Answer

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

Browse other questions tagged or ask your own question.