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

ConTeXt Writer: Start and Stop Section Levels #5539

Closed
ghost opened this issue May 31, 2019 · 11 comments · Fixed by #8106
Closed

ConTeXt Writer: Start and Stop Section Levels #5539

ghost opened this issue May 31, 2019 · 11 comments · Fixed by #8106

Comments

@ghost
Copy link

ghost commented May 31, 2019

Background

Using Pandoc 2.7.2, consider the following document:

# Inflation Theory
## 13,813 ± 58
Time did not start with an explosion...

### Relevance
Our Universe's first three minutes produced vast amounts of protons...

This results in a document similar to the following:

\chapter[title={Inflation Theory},reference={inflation-theory}]

\section[title={13,813 ± 58},reference={section}]

Time did not start with an explosion...

\subsection[title={Relevance},reference={relevance}]

Our Universe's first three minutes produced vast amounts of protons...

Problem

By generating \chapter, \section, and \subsection, etc., it puts constraints around embedding documents within documents. As Hans Hagen wrote on the ConTeXt mailing list:

I don't know as I never use these coding methods. But it might make sense to check all these mappings onto context, for instance I think that pandoc uses \section and such while in fact it should use \startsectionlevel[title={}] ... \stopsectionlevel so that one can embed documents in other documents.

Expected Output

The expected outputs include a standalone document and a document fragment.

Standalone Document

The relevant portions of the standalone document might resemble:

\definestructureconversionset
  [documentstructure]
  [numbers, numbers, numbers]
  [numbers]

\setupheads [sectionconversionset=documentstructure]

\starttext

\startsectionlevel [title={Inflation Theory},reference={inflation-theory}]
  \startsectionlevel [title={13,813 ± 58},reference={section}]
    Time did not start with an explosion...

    \startsectionlevel [title={Relevance},reference={relevance}]
      Our Universe's first three minutes produced vast amounts of protons...
    \stopsectionlevel
  \stopsectionlevel
\stopsectionlevel

\stoptext

The [numbers, numbers, numbers] code reflects the depth of heading levels in the document. If the document has 5 levels, then [numbers, numbers, numbers, numbers, numbers] may be necessary.

Document Fragment

A document fragment could look as follows:

\startsectionlevel [title={Inflation Theory},reference={inflation-theory}]
  \startsectionlevel [title={13,813 ± 58},reference={section}]
    Time did not start with an explosion...

    \startsectionlevel [title={Relevance},reference={relevance}]
      Our Universe's first three minutes produced vast amounts of protons...
    \stopsectionlevel
  \stopsectionlevel
\stopsectionlevel

Discussion

Could detecting when to stop the current sectionlevel be beyond Pandoc's ability in certain circumstances?

@mb21
Copy link
Collaborator

mb21 commented May 31, 2019

Have you tried the --section-divs option?

But yes, this should be documented better (was added in 751b5ad)...

The expected outputs include a standalone document and a document fragment.

Sounds exactly like pandoc templates.

@mb21 mb21 added the docs label May 31, 2019
@jgm
Copy link
Owner

jgm commented May 31, 2019 via email

@ghost
Copy link
Author

ghost commented May 31, 2019

Using the following command:

$ pandoc -t context --section-divs test.md

Produces the following document:

\startsection[title={Inflation Theory},reference={inflation-theory}]

\startsubsection[title={13,813 ± 58},reference={section}]

Time did not start with an explosion\ldots{}

\startsubsubsection[title={Relevance},reference={relevance}]

Our Universe's first three minutes produced vast amounts of
protons\ldots{}

\stopsubsubsection

\stopsubsection

\stopsection

Would subsections and sub-subsections interfere with embedding documents? (I suspect so because there'd be no way to distinguish an embedded document's startsubsection from its parent document's startsubsection.) As opposed to startsectionlevel, which relies on the nested hierarchy to determine the level heading.

@ghost
Copy link
Author

ghost commented May 31, 2019

Regarding the documentation: yes, having a section that describes additional output formats beyond HTML could be useful.

@denismaier
Copy link
Contributor

I would opt for using the \startsectionlevel (not \startsection, \startsubsection, etc.) as this allows for maximal flexibility.

@denismaier
Copy link
Contributor

The following code maps those sectionlevels to chapter, section, subsection, etc.

\definesectionlevels
   [default]
   [chapter,
    section,
    subsection,
    subsubsection,
    subsubsubsection,
    subsubsubsubsection]

@tarleb
Copy link
Collaborator

tarleb commented Jun 4, 2022

Here's a somewhat hacky approach to this: we could return \startsectionlevel ... \stopsectionlevel for all headings below level six. The desired result could then be produced by calling pandoc with --section-divs --shift-heading-level-by=6.

@denismaier
Copy link
Contributor

What about using the same approach as with JATS XML?

@tarleb
Copy link
Collaborator

tarleb commented Jun 4, 2022

Could you expand on that? The JATS model has no concept of explicit section levels, the <sec> element is equivalent to the sectionlevel environment.

A cleaner approach than what I suggested above might be to make the behavior depend on --top-level-division, with --top-level-division=default giving the behavior proposed here, and --top-level-division=section producing the current behavior.

@denismaier
Copy link
Contributor

Could you expand on that? The JATS model has no concept of explicit section levels, the <sec> element is equivalent to the sectionlevel environment.

That's basically my suggestion: Just use sectionslevels throughout. Then, when building a standalone document add something like this to the preamble:

\definesectionlevels
   [default]
   [section,
    subsection,
    subsubsection,
    subsubsubsection,
    subsubsubsubsection]

Or, with --top-level-division=chapter:

\definesectionlevels
   [default]
   [chapter,
    section,
    subsection,
    subsubsection,
    subsubsubsection,
    subsubsubsubsection]

@adityam
Copy link
Contributor

adityam commented Jun 6, 2022

I don't use pandoc + context too much these days, but I'll chime in to say that I support the default output being \sectionlevel. FWIW, that's what the Hans Hagen's m-markdown module (which is a markdown parser written in Lua and distributed as part of context distribution) does.

tarleb added a commit to tarleb/pandoc that referenced this issue Jun 6, 2022
The document hierarchy is now conveyed using the
`\startsectionlevel`/`\stopsectionlevel` by default. This makes it easy
to include pandoc-generated snippets in documents at arbitrary levels.
The more semantic environments "chapter", "section", "subsection", etc.
are used if the `--top-level-division` command line parameter is set to
a non-default value.

Closes: jgm#5539
tarleb added a commit to tarleb/pandoc that referenced this issue Jun 6, 2022
The document hierarchy is now conveyed using the
`\startsectionlevel`/`\stopsectionlevel` by default. This makes it easy
to include pandoc-generated snippets in documents at arbitrary levels.
The more semantic environments "chapter", "section", "subsection", etc.
are used if the `--top-level-division` command line parameter is set to
a non-default value.

Closes: jgm#5539
@jgm jgm closed this as completed in #8106 Jun 6, 2022
jgm pushed a commit that referenced this issue Jun 6, 2022
The document hierarchy is now conveyed using the
`\startsectionlevel`/`\stopsectionlevel` by default. This makes it easy
to include pandoc-generated snippets in documents at arbitrary levels.
The more semantic environments "chapter", "section", "subsection", etc.
are used if the `--top-level-division` command line parameter is set to
a non-default value.

Closes: #5539
vedranmiletic added a commit to vedranmiletic/pandoc_resume that referenced this issue Oct 4, 2022
mwolson added a commit to mwolson/resume that referenced this issue Dec 12, 2024
Required for Pandoc 2.19, see jgm/pandoc#5539

Co-authored-by: Vedran Miletić <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants