jgm / pandoc

Universal markup converter
https://pandoc.org
Other
34.34k stars 3.37k forks source link

Allow suffixes on (@)-numbered counters #1350

Open dubiousjim opened 10 years ago

dubiousjim commented 10 years ago

A common numbering style in academic papers is to number displayed items in groups like this:

(10a) Sample sentence.
(10b) Variant of the preceding.
As (10b) demonstrates, ... But now consider:
(10c) blah blah

Rather than coding this with explicit LaTeX markup, it'd be very useful if Pandoc extended the (@foo)-numbering syntax like this:

(@foo:a) Sample sentence.
(@foo:b) Variant of the preceding.
As (@foo:b) demonstrates, ... But now consider:
(@foo:c) blah blah

The intention is that this would render the same as the preceding displayed block. I'd hope that the post-colon material could also include things like ${}'$, so that I could have (10), (10'), (10''), and so on.

Sorry if this has already been discussed; I wasn't able to find anything relevant on the bugtracker or in pandoc-discuss.

dubiousjim commented 10 years ago

Here is some work towards generating the right output formats.

In LaTeX, one just will generate a enumerate environment as Pandoc normally does, then use:

  \item[(foo)] line

to have a line labeled with (foo).

In HTML, one needs this css:

ol.hard-numbered {
    list-style-type: none;
}
.hard-numbered li:before {
    content: attr(value)'.';
    margin-left: -3.5em;
    padding-right: 0.5em;
    display: inline-block;
    text-align: right;
    width: 3em;
}

then one can do this:

<ol class=hard-numbered>
    <li value="foo">equation</li>
    <li value="bar">equation</li>
</ol>

to get lines labeled with foo. and bar..

dubiousjim commented 10 years ago

I have this implemented (at least the Reader side of it) in a custom version of Pandoc I'm tinkering with. Once it's stable and the Writer side is also implemented, I'll pass on what I've got for consideration. Just thought I should say this in the (unlikely) event someone else may consider working on it simultaneously. The syntax I'm using is:

I'm keeping track of the needed additional metadata in some additional counters and maps in the parser state. I'm assuming that I can just pass that additional state to Writers that are capable of properly outputing the new markup. To Writers that aren't capable of handling it, then instead of:

(9) example item
(10a) a subitem
(10b) a second subitem
(9*) the first item again with a suffix
(11) a new main item

you'd just get output like:

(9) example item
(10) a subitem
(11) a second subitem
(12) the first item again with a suffix
(13) a new main item
jgm commented 10 years ago

+++ dubiousjim [Jul 17 14 06:12 ]:

I'm keeping track of the needed additional metadata in some additional counters and maps in the parser state.

Parser state is local to the parser. Everything the writers need must be put into the Pandoc AST.

            (reader)       (writer)
 source format ==> Pandoc AST ==> output

Note that example lists are not first-class citizens in the Pandoc AST. (See Text.Pandoc.Definition.) The markdown reader converts them to regular ordered lists at the end of parsing. All the writers see is an ordered list. And the problem is then that the OrderedList type doesn't contain any way to mark all the distinctions you want.

dubiousjim commented 10 years ago

I feared that it might be so, but I thought I'd just work on the Reader side for now and worry about it later. I was trying to make changes only to a single package, without having to also customize pandoc-types.