lierdakil / pandoc-crossref

Pandoc filter for cross-references
https://lierdakil.github.io/pandoc-crossref/
GNU General Public License v2.0
911 stars 72 forks source link

Start section number from n > 1 #388

Closed kappapiana closed 1 year ago

kappapiana commented 1 year ago

Sometimes, maybe because the document is a part of a more complex document, or because it is a document that follows a previous, separate document, you need to start numbering from a number higher than 1 with the YAML prefix.

Similarly, sometimes I have the need to set the numbering of a particular section or subsection to a higher number than n+1 where n is the number of the last section. Ideally this should be achieved with:

# Section 

## Earlier Subsection

## Title of Subsection {number=6}

Which should render:

1 - Section

1.1 Earlier subsection

1.6 Title of Subsection

lierdakil commented 1 year ago

I can see the use case for the former. Not entirely convinced about the latter, though. FWIW, there is label option that lets you set anything you want for the label, but it doesn't update the internal element counter.

In a pinch, you could bodge something with secLevelLabels, but it's a kludge. Still, not the worst option if you need this ASAP.

I'll see if I can do something in the next little while, but free time has been at a premium lately, so I'm not sure when I'll be able to. Feel free to ping me next week in case I forget.

kappapiana commented 1 year ago

I can see the use case for the former. Not entirely convinced about the latter, though. FWIW, there is label option that lets you set anything you want for the label, but it doesn't update the internal element counter.

Thanks. For reference, I am using the paragraph number AND a label to make a list of accompanying documents that I file with the markdown document in a court submission.

This works well if it's the first filing. But in the subsequent filing for the same case, I need to start from the last filing. Alternatively, an equivalent solution would be to have two separate series.

But there are other use cases. I acknowledge this is a pretty marginal case, but I also reckon this feature ("(re)start from") exists in pretty much all the numbering facilities of the much dreaded word processors.

In a pinch, you could bodge something with secLevelLabels, but it's a kludge. Still, not the worst option if you need this ASAP.

I will also explore that, thanks. I'm personally ok with anything that works, since so far we had to use a custom filter for further processing of the output.

I'll see if I can do something in the next little while, but free time has been at a premium lately, so I'm not sure when I'll be able to. Feel free to ping me next week in case I forget.

Will do, thanks.

lierdakil commented 1 year ago

I've pushed something, which seems to work. It uses the approach you proposed, with the number attribute. I didn't have much opportunity to test, though, so if you're up for a little beta testing before I push out a release, I'd appreciate that. Here are the binaries:

pandoc-crossref-master-Linux-20230513-df1768.tar.xz pandoc-crossref-master-macOS-20230513-df1768.tar.xz pandoc-crossref-master-Windows-20230513-df1768.7z

(or find the latest build in the nightlies tag, or build from source, whatever suits your fancy)

kappapiana commented 1 year ago

Hi, I have tested the patch and it seems to work on my toolchain. It requires updating Pandoc to v3, which creates a different set of issues on my setup (breaks 2 lua packages) and it is not yet in the repos of Ubuntu and I suspect Debian, but this gives exactly the outcome I need. I couldn't hope for anything better.

lierdakil commented 1 year ago

I don't really have the bandwidth to support multiple pandoc versions, unfortunately. Okay, since you've given your seal of approval, I'll try to package a release by the end of this week. Thanks for testing.

kappapiana commented 1 year ago

I don't really have the bandwidth to support multiple pandoc versions, unfortunately. Okay, since you've given your seal of approval, I'll try to package a release by the end of this week. Thanks for testing.

Understood. We'll try and fix the LUA packages that don't work and meanwhile have two separate toolchains. This is already VERY helpful. Thanks again.

lierdakil commented 1 year ago

The release v0.3.16.0 is live

image

kappapiana commented 1 year ago

Great stuff, thanks again.

julianbarg commented 1 year ago

I numbered my foreword as section 0 and it felt like magic :+1: :+1: :+1: