Number of Hashes by Level but Inside Prefix

Hi,

Is there a way to multiply a symbol by the hierarchy level depth in the title options under section layouts? What I would like to do is to prefix a title with a number of (#)'s according to the heirarchy in the binder area. The available feature is not usable for me because it is also adding the hashes at the suffix of the title, which I do not want. Thanks.

EDIT: C’mon I still cannot add images?

In the Section Layouts pane, click the ··· / Gear button in the upper right corner of the main list of layouts and disable Add closing hashes to titles. If you’re on Windows, sadly they haven’t added this setting at the time of this writing. You’ll just have to make do with the Title Prefix field in the Title Options tab, and create x number of level-based layouts to handle it.

Alternatively (and this is how I’d handle it since that would be an ugly solution that could potentially require a lot of duplication of settings), you can write a script that gets run by the Processing pane after compilation is complete. If Windows has something similar to sed, that’s what I’d do.

Oof, I was afraid it was gonna go this way. I’m currently on Windows and yes a quick fix would be to work with the Title Prefix field.

Anyway, I’ve written a script in Python which removes these closing hashes before sending it to pandoc for further processing. Anyone interested can take a look at the code below.

import sys
import re

# Scrivener: Remove all closing hashes from headings
# https://forum.literatureandlatte.com/t/number-of-hashes-by-level-but-inside-prefix/
regex = re.compile("#+\n")

# Get contents from command line arguments
# print(sys.argv)
filename = sys.argv[1]

with open(filename, "r") as f:
    text = f.read()
    text = regex.sub("\n", text)
    
# Clears the contents of filename
with open(filename, "w") as f:
    f.write(text)
2 Likes