-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Issue of --numbered-sections used with --base-header-level=2: produces 0.x.y #5071
Comments
Can you post pandoc version, exact input/output please? |
I'm using Pandoc 2.2.1 A basic md file: # Title of document
## Section 1
text text text
## Section 2
text text text
### Sub-section 2.1
text text text Command:
1 Title of document1.1 Section 1text text text 1.2 Section 2text text text 1.2.1 Sub-section 2.1text text text The purpose would be to number only headers 2 and 3. |
Regarding the introduction of "0.1" or "0.2", it occurs when you are using Rmarkdown document in RStudio (in such case, the title is defined in the YAML header and the levels 2 are defined in the markdown itself). Regards |
Try:
See the http://pandoc.org/MANUAL.html for details.
Maybe RStudio is using an older version of pandoc? Or otherwise it's just a bug at their end... |
It's producing Title of document0.1 Section 1text text text 0.2 Section 2text text text 0.2.1 Sub-section 2.1text text text |
Here the issue is to remove the |
Note: Pandoc 2.2.1 is the version embed with the current version of RStudio |
I've a vague memory of there being such a bug earlier.. The plain pandoc command works as expected, so I'm closing this issue. For questions, pandoc-discuss should be used. Or ask the RStudio folks... |
Sorry, but going back to my initial point. It would be useful to have an additional option in pandoc (e.g. Title of document1 Section 1text text text 2 Section 2text text text 2.1 Sub-section 2.1text text text |
You can do this using CSS counters. If you're targeting other output formats, pandoc-crossref might help. |
@larmarange it sounds like you might be looking for |
Thank you @tarleb, as I understood it, Thank you @mb21 , I will look at pandoc-crossref. |
I suspect you're doing this:
Normally in pandoc you'd lay this out this way instead:
If you do it this way, If you really want the layout where level-2 headers are your section headers, then you can put the |
The issue in HTML is that there is no standard regarding the main title of the page and many templates are using Therefore, your md file looks like:
But you get sections numbers as
|
Maybe a better approach would be to write in your md file titles like:
and to use |
Joseph <notifications@github.com> writes:
The issue in HTML is that there is no standard regarding the main title of the page and many templates are using `<h1>` for that purpose and therefore `<h2>` as the section titles.
Pandoc's templates use `<h1>` for both, distinguishing
the title with a special class.
This allows us to retain a consistent meaning for
level-one headers across formats.
|
That's right. However, there are many cases when there is a need to produce The only problem is when combining For such situation, an additional option (e.g. |
One possibility would be to change the number
generation algorithm so that it rewrites 0.x.y -> x.y.
It's hard to think of cases where this would give bad
results; I suppose it would do so if you started a
document with level 2 headers, then went to level 1,
but who does that?
|
Such approach would work perfectly |
Reopening so this won't get lost. |
thanks |
Just read the full issue and want to say I've exactly the same need of @larmarange I'm also producing HTML page so I don't want to have more than one H1 in my document (for SEO purposes) and my wish is to be able to ignore that H1 in my TOC; don't mention it and don't number it. The first item "1. xxx" start with H2 level. Just like Jospeh is asking for as far I understand. |
this may be related: #5615 ...or maybe not. I guess jgm's proposed fix from above is good enough:
The test input would be:
|
I've been struggling with this myself. I made a stupidly simple Lua filter, which seems to work for me. -- For LaTeX documents, shift all headings down by one.
-- Make Level 1 unnumbered, or remove it if it contains the "hidden" class. (`# Title {.hidden}`)
function Header(el)
-- do this for only latex output.
if FORMAT:match "latex" then
if el.level == 1 then
--check for hidden class. (Why didn't pandoc make this a set? `{class_name = true}`)
for i, v in ipairs(el.classes) do
if v == "hidden" then
--The empty list means remove the element
return {}
end
end
-- this may mean that there are two unnumbered classes, but that doesn't matter.
el.classes[#el.classes + 1] = "unnumbered"
else
-- all headings > 1 are shifted down so that you don't end up with 0.x.y headings.
el.level = el.level - 1
end
end
return el
end
...will not show up in the PDF document, at all |
The docs for
Which lead me to believe that shift-heading-level=x behaves in the way that people are discussing in this issue - but when you add Maybe another flag should be added like Since the content of this issue is kinda spread out, here's an exact example: ---
title: Title of document
---
# Section 1
text text text
# Section 2
text text text
## Sub-section 2.1
text
actual output: ...
<header id="title-block-header">
<h1 class="title">Title of document</h1>
</header>
<h2 data-number="0.1" id="section-1"><span class="header-section-number">0.1</span> Section 1</h2>
<p>text text text</p>
<h2 data-number="0.2" id="section-2"><span class="header-section-number">0.2</span> Section 2</h2>
<p>text text text</p>
<h3 data-number="0.2.1" id="sub-section-2.1"><span class="header-section-number">0.2.1</span> Sub-section 2.1</h3>
<p>text</p>
... expected output: <header id="title-block-header">
<h1 class="title">Title of document</h1>
</header>
<h2 data-number="1" id="section-1"><span class="header-section-number">1</span> Section 1</h2>
<p>text text text</p>
<h2 data-number="2" id="section-2"><span class="header-section-number">2</span> Section 2</h2>
<p>text text text</p>
<h3 data-number="2.1" id="sub-section-2.1"><span class="header-section-number">2.1</span> Sub-section 2.1</h3>
<p>text</p> |
I guess there are two cases to consider:
(1) would seem to be a pretty rare kind of case, while (2) is common for the reason you give. Unfortunately pandoc is producing the output appropriate to (1). One possibility would be to have the HTML writer start numbering with whatever the lowest-numbered header that occurs in the document. So in case 1, we'd number 0.1, 0.2, 1.1, etc., while in case 2 we'd number 1, 2, etc. I prefer not to add options if we can do the right thing automatically. Another question is whether such a change would lead to a divergence in HTML and LaTeX/PDF output, and if so how to fix it. (There may be similar questions about docx and other formats.) |
I currently use this: [
"--standalone",
"--number-sections",
"--shift-heading-level-by=1",
"--number-offset=1",
"--no-highlight",
"--toc",
"--toc-depth=3",
"--top-level-division=chapter",
"--listings",
"--include-after-body",
"'[REDACTED]\\resources\\templates\\_watch.html'",
"--metadata=title-meta:Test",
"--metadata=title:Test",
"'--metadata=date-meta:2022-02-09T11:53:29.849Z'",
"'--metadata=author-meta:Foo bar'",
"'--metadata=subtitle:This is a sample example to show all features.'",
"'--metadata=description-meta:Example here, example there. -- There'",
"--metadata=lang:en",
"'--metadata=keywords:test,demo,example,kitchen-sink'",
"--template",
"'[REDACTED]\\resources\\templates\\default.html'",
"--css",
"'./assets/default.css'",
"--strip-comments",
"--from",
"markdown",
"--to",
"html5"
] Input: # a
## b
### c
# d
## h
### l
# i |
Reply to keep this issue alive. |
I ran into the same issue, and believe it would be convenient to have a solution matching the html and pdf outputs. Thanks for this great tool! |
Related question on StackOverflow: https://stackoverflow.com/q/73417580 Including the relevant Lua filter here to save you a click. Use the filter by saving the below to a file function Pandoc (doc)
-- Create and number sections. Setting the first parameter to
-- `true` ensures that headings are numbered.
doc.blocks = pandoc.utils.make_sections(true, nil, doc.blocks)
-- Shift the heading levels by 1
doc.blocks = doc.blocks:walk {
Header = function (h)
h.level = h.level + 1
return h
end
}
-- Return the modified document
return doc
end |
I have the same issue while trying to convert a markdown file to pdf. Thanks to everyone who contributed. |
I ran into this myself via via Obsidian plugin: https://github.com/mokeyish/obsidian-enhancing-export. Context: pdfTeX 3.141592653-2.6-1.40.25 (TeX Live 2023/Debian) |
To reproduce:
|
This is like `makeSections` but has an additional parameter specifying number offsets, for use with the `--number-offset` option. Use `makeSectionsWithOffsets` in HTML writer instead of ad hoc and inefficient number-adjusting code. Clarify MANUAL.txt: the `--number-offset` option should only directly affect numbering of the first section heading in a document; subsequent headings will increment normally. Fix test output for #5071 to reflect this.
This is like `makeSections` but has an additional parameter specifying number offsets, for use with the `--number-offset` option. Use `makeSectionsWithOffsets` in HTML writer instead of ad hoc and inefficient number-adjusting code. Clarify MANUAL.txt: the `--number-offset` option should only directly affect numbering of the first section heading in a document; subsequent headings will increment normally. Fix test output for #5071 to reflect this.
Even though this has been closed, doing what the OP said in the issue still produces numbers like "0.1", "0.2" etc. if you use numbered sections but start with h2 (
|
When
h1
is used for the title of a document andh2
for the sub-sections,--numbered-sections
is producing0.1
,0.2
etc.It would be relevant to have an option to specify that numbering should start at level 2.
The text was updated successfully, but these errors were encountered: