# Folding headers containing source code blocks in an org file?

I always refer to org mode when I want to document anything, but what I am struggling with right now is how to make folding mechanism work when my headers contain source code blocks under a list element. Consider the MWE below:

* Main Subject
** Fonts
*** \definefont
- ~\definefont [TitleFont] [Serif sa 2.4]~
- ~\definefont [TitleFont] [Serif]~ means ~\definefont [TitleFont] [Serif sa *]~ which in turn expands into the current actual font size, after the application of size corrections for super and subscripts
- this creates a macro name for a font switch, =\TitleFont= in this example ~{\TitleFont anytext}~
*** \definedfont
- ~\definedfont [...]~ inherits from \definefont
*** \definebodyfont
- ~\definebodyfont [10pt] [rm] [tf=tir at 10pt]~ This single line actually defines two font switches =\tf= for use after a =\rm= command, and =\rmtf= for direct access
- End
- Example-1: of using different font sizes for Computer Modern Roman font
#+BEGIN_SRC tex
\definebodyfont [12pt] [rm]
[tf=cmr12,
tfa=cmr12 scaled \magstep1,
tfb=cmr12 scaled \magstep2,
tfc=cmr12 scaled \magstep3,
tfd=cmr12 scaled \magstep4,
bf=cmbx12,
it=cmti12,
sl=cmsl12,
bi=cmbxti10 at 12pt,
bs=cmbxsl10 at 12pt,
sc=cmcsc10 at 12pt]
#+END_SRC
- Example-2: for Helvetica Type 1 font
#+BEGIN_SRC tex
\definebodyfont [12pt] [ss]
[tf=hv sa 1.000,
bf=hvb sa 1.000,
it=hvo sa 1.000,
sl=hvo sa 1.000,
tfa=hv sa 1.200,
tfb=hv sa 1.440,
tfc=hv sa 1.728,
tfd=hv sa 2.074,
sc=hv sa 1.000]
#+END_SRC


My struggle is to hide the visibility or folding of the header Example-1 and Example-2 in org. What is the best strategy in org-mode to document such code chunks? May be I am using it the wrong way. Please note I want to stick with the way org mode writes code blocks because of its ease and breeze, I just type <s and then TAB and this will extend nicely to a source block template. I would like to continue using this nice feature in org mode, yet with the folding mechanism inherent of Org-mode document structures also in place.

Note

Org mode version 9.1.13

If I'm not mistaken, Example-1 and 2 are not headers, but list elements. I'd suggest turning them into headers (by adding ****).

If you insist on using lists, or just would like to fold code-blocks and other text under items, make sure to indent everything that follows and should go under the item (i.e., should collapse with the item).

I'd clean up your example like so:

- Example-1: of using different font sizes for Computer Modern Roman font
#+BEGIN_SRC tex
\definebodyfont [12pt] [rm]
[tf=cmr12,
tfa=cmr12 scaled \magstep1,
...
#+END_SRC


To summarize: indent the text below the item just as much as the text on the first line of item itself.

This was originally a comment, but turned it into an answer for more explanation.

A tip.

Use TAB to make org-mode do the indenting for you.

For example: type

- Test RET
TAB This is indented RET
TAB <s TAB RET
TAB This code is indented as well.

That should result in something like:

- Test
This is indented
#+BEGIN_SRC
This code is indented as well.
#+END_SRC

• Yes, that works, but I had to do the indentation manually for each line of code inside the block as much space as the text on the first line of the item. When I hit C-M- to run indent-region it doesn't work. Is it so either with you? – doctorate Aug 17 '18 at 10:20
• I think ideally, the source code block would be all aligned with the first line where it says #+BEGIN_SRC tex, is there any missing item in the setup to make the source code blocks behave itself so by indentation? I hope so. – doctorate Aug 17 '18 at 10:25
• in other words, how to make source code block with all it lines respect the indentation of the respective list element they fall under? – doctorate Aug 17 '18 at 10:36
• I'm no expert, but I'll add a few tips to my answer. – EFLS Aug 17 '18 at 13:20