Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When setting chapter as {number=n}, subsequent chapter should become {number=n+1} etc. #393

Open
julianbarg opened this issue Jul 14, 2023 · 2 comments

Comments

@julianbarg
Copy link

As described in the title. Appreciate the new feature, I think the next step would be to computationally set chapter numbers so they are consistent. Example: I set the chapter number of the first chapter of my document to 0 (foreword), but the chapter after became chapter 2, i.e., there was no chapter 1. In case this is format dependent, I was converting a markdown document to .docx. System is Ubuntu 22.04, pandoc 3.1.5, pandoc-crossref 0.3.16.0 (love those nightlies).

@lierdakil
Copy link
Owner

set chapter numbers so they are consistent

I do, they are, but there's a caveat: if you use --number-sections, it's pandoc itself which numbers sections, not pandoc-crossref, thus there's a disconnect. That's one of the reasons why numberSections exists.

Now that I think about it, pandoc itself kind of supports number attribute (at least for some writers), so it should be possible to bodge a compatibility layer by force-setting all numbers. But IMO it's pretty low priority, as numberSections offers more flexibility in terms of formatting. Still, here's a silly little lua filter you can use right now if you want:

function Header(el)
	el.attributes.number = el.attributes.label
	el.attributes.label = nil;
	return el
end

You need to enable setLabelAttribute metadata option, e.g., assuming you named the lua filter above fixup-header-nums.lua:

$ pandoc -F pandoc-crossref -L fixup-header-nums.lua --number-sections -MsetLabelAttribute input.md -t docx -o out.docx

An alternative is to let pandoc-crossref number sections:

$ pandoc -F pandoc-crossref -MnumberSections -MsectionsDepth=-1 input.md -t docx -o out.docx

@julianbarg
Copy link
Author

Thanks, I had missed -M numberSections. Got it to work now, which is fabulous. Didn't get the first option to work, but it's probably for the best -- lot of complexity and things interacting going on here, not necessarily the right direction to take pandoc-crossref

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants