public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* Chapter TOC via filter?
@ 2019-01-07  4:10 Axel Rauschmayer
       [not found] ` <1bb6e5f4-04ce-4209-8223-f928f2943998-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 13+ messages in thread
From: Axel Rauschmayer @ 2019-01-07  4:10 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 2051 bytes --]

I’m considering writing a filter that inserts chapter TOCs via \ChapterTOC:

INPUT (# is for parts, ## is for chapters, etc.):

## Chapter on animals {#animals}
### Section on dogs {#dogs}
#### Subsection on poodles
### Section on cats {#cats}

CHAPTER TOC (number of chapter is 12):

* 12.1. [Section on dogs](#dogs)
* 12.1.2. Subsection on poodles
* 12.2. [Section on cats](#cats)

Considerations:

   - Getting the numbering right is challenging – AFAICT, a filter does not 
   have access to the numbers and numbering works differently for LaTeX and 
   HTML. Thus, I’ll probably extend my filter that numbers text units for 
   HTML, to additionally create TOCs (for LaTeX, it would only do the latter): 
   https://groups.google.com/d/topic/pandoc-discuss/N4Qv0Bvgt_E/discussion
   - Alternatively, things would be easier if one omitted the chapter 
   number. But then the numbers in the TOC are not as nice.
   - For another book, where I couldn’t change how Markdown was translated 
   to HTML, PDF, etc., I wrote a shell script that inserted the chapter TOC 
   into the text file. For pandoc, I’d prefer to use a filter. The output of 
   the shell script looks as 
   follows: http://exploringjs.com/es6/ch_symbols.html
   - The shell script complains if sections don’t have IDs. I’ll have to 
   look into retrieving pandoc’s auto-generated IDs.

Is there something I’m overlooking? Any tips or suggestions?

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/1bb6e5f4-04ce-4209-8223-f928f2943998%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 2649 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Chapter TOC via filter?
       [not found] ` <1bb6e5f4-04ce-4209-8223-f928f2943998-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2019-01-07  4:11   ` Axel Rauschmayer
  2019-01-09 14:29   ` Christophe Demko
  2019-01-09 16:46   ` John MacFarlane
  2 siblings, 0 replies; 13+ messages in thread
From: Axel Rauschmayer @ 2019-01-07  4:11 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 697 bytes --]

Related: This GitHub issue explains how numbering differs between HTML and 
LaTeX. https://github.com/jgm/pandoc/issues/1905

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/80922ec5-80ea-4ab3-8723-5bbc3bd4f588%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 1109 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Chapter TOC via filter?
       [not found] ` <1bb6e5f4-04ce-4209-8223-f928f2943998-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  2019-01-07  4:11   ` Axel Rauschmayer
@ 2019-01-09 14:29   ` Christophe Demko
       [not found]     ` <6fe9c4df-2625-4508-8608-da8499e81599-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  2019-01-09 16:46   ` John MacFarlane
  2 siblings, 1 reply; 13+ messages in thread
From: Christophe Demko @ 2019-01-09 14:29 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 2309 bytes --]

It would be be better if a local TOC is created when a class is added to 
the header (.local-top for example)
Ch.D

Le lundi 7 janvier 2019 05:10:33 UTC+1, Axel Rauschmayer a écrit :
>
> I’m considering writing a filter that inserts chapter TOCs via \ChapterTOC
> :
>
> INPUT (# is for parts, ## is for chapters, etc.):
>
> ## Chapter on animals {#animals}
> ### Section on dogs {#dogs}
> #### Subsection on poodles
> ### Section on cats {#cats}
>
> CHAPTER TOC (number of chapter is 12):
>
> * 12.1. [Section on dogs](#dogs)
> * 12.1.2. Subsection on poodles
> * 12.2. [Section on cats](#cats)
>
> Considerations:
>
>    - Getting the numbering right is challenging – AFAICT, a filter does 
>    not have access to the numbers and numbering works differently for LaTeX 
>    and HTML. Thus, I’ll probably extend my filter that numbers text units for 
>    HTML, to additionally create TOCs (for LaTeX, it would only do the latter): 
>    https://groups.google.com/d/topic/pandoc-discuss/N4Qv0Bvgt_E/discussion
>    - Alternatively, things would be easier if one omitted the chapter 
>    number. But then the numbers in the TOC are not as nice.
>    - For another book, where I couldn’t change how Markdown was 
>    translated to HTML, PDF, etc., I wrote a shell script that inserted the 
>    chapter TOC into the text file. For pandoc, I’d prefer to use a filter. The 
>    output of the shell script looks as follows: 
>    http://exploringjs.com/es6/ch_symbols.html
>    - The shell script complains if sections don’t have IDs. I’ll have to 
>    look into retrieving pandoc’s auto-generated IDs.
>
> Is there something I’m overlooking? Any tips or suggestions?
>

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/6fe9c4df-2625-4508-8608-da8499e81599%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 3848 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Chapter TOC via filter?
       [not found]     ` <6fe9c4df-2625-4508-8608-da8499e81599-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2019-01-09 14:58       ` Gareth Stockwell
  0 siblings, 0 replies; 13+ messages in thread
From: Gareth Stockwell @ 2019-01-09 14:58 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

[-- Attachment #1: Type: text/plain, Size: 3848 bytes --]

> It would be be better if a local TOC is created when a class is added to
the header (.local-top for example)

That would remove the ability of the author to control where the local ToC
appears, for example

    # My section

    Here is some introduction.

    <insert local ToC here>

    Body of the section.

For "insert local ToC here", I would suggest using some markup which is
agnostic of output format, for example

    <div class="local-toc"></div>

Then the filter can convert this to markup which is appropriate for each
supported output format - e.g. for latex, convert to \ChapterTOC

Gareth


On Wed, Jan 9, 2019 at 2:29 PM Christophe Demko <chdemko-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:

> It would be be better if a local TOC is created when a class is added to
> the header (.local-top for example)
> Ch.D
>
> Le lundi 7 janvier 2019 05:10:33 UTC+1, Axel Rauschmayer a écrit :
>>
>> I’m considering writing a filter that inserts chapter TOCs via
>> \ChapterTOC:
>>
>> INPUT (# is for parts, ## is for chapters, etc.):
>>
>> ## Chapter on animals {#animals}
>> ### Section on dogs {#dogs}
>> #### Subsection on poodles
>> ### Section on cats {#cats}
>>
>> CHAPTER TOC (number of chapter is 12):
>>
>> * 12.1. [Section on dogs](#dogs)
>> * 12.1.2. Subsection on poodles
>> * 12.2. [Section on cats](#cats)
>>
>> Considerations:
>>
>>    - Getting the numbering right is challenging – AFAICT, a filter does
>>    not have access to the numbers and numbering works differently for LaTeX
>>    and HTML. Thus, I’ll probably extend my filter that numbers text units for
>>    HTML, to additionally create TOCs (for LaTeX, it would only do the latter):
>>    https://groups.google.com/d/topic/pandoc-discuss/N4Qv0Bvgt_E/discussion
>>    - Alternatively, things would be easier if one omitted the chapter
>>    number. But then the numbers in the TOC are not as nice.
>>    - For another book, where I couldn’t change how Markdown was
>>    translated to HTML, PDF, etc., I wrote a shell script that inserted the
>>    chapter TOC into the text file. For pandoc, I’d prefer to use a filter. The
>>    output of the shell script looks as follows:
>>    http://exploringjs.com/es6/ch_symbols.html
>>    - The shell script complains if sections don’t have IDs. I’ll have to
>>    look into retrieving pandoc’s auto-generated IDs.
>>
>> Is there something I’m overlooking? Any tips or suggestions?
>>
> --
> You received this message because you are subscribed to the Google Groups
> "pandoc-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pandoc-discuss/6fe9c4df-2625-4508-8608-da8499e81599%40googlegroups.com
> <https://groups.google.com/d/msgid/pandoc-discuss/6fe9c4df-2625-4508-8608-da8499e81599%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CAGewFGCx%2BTTcC4Vv-VoQv_v8LkM9frr7F1r4W1puhKK7nc5oiQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #2: Type: text/html, Size: 5542 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Chapter TOC via filter?
       [not found] ` <1bb6e5f4-04ce-4209-8223-f928f2943998-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  2019-01-07  4:11   ` Axel Rauschmayer
  2019-01-09 14:29   ` Christophe Demko
@ 2019-01-09 16:46   ` John MacFarlane
       [not found]     ` <m2va2xvkwl.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
  2 siblings, 1 reply; 13+ messages in thread
From: John MacFarlane @ 2019-01-09 16:46 UTC (permalink / raw)
  To: Axel Rauschmayer, pandoc-discuss

Axel Rauschmayer <rauschma-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:

>    - Getting the numbering right is challenging – AFAICT, a filter does not 
>    have access to the numbers and numbering works differently for LaTeX and 
>    HTML. Thus, I’ll probably extend my filter that numbers text units for 
>    HTML, to additionally create TOCs (for LaTeX, it would only do the latter): 
>    https://groups.google.com/d/topic/pandoc-discuss/N4Qv0Bvgt_E/discussion

The hierarchicalize function will divide your document
into nested sections with numbering information
included (and section ids too). This is made available
to lua filters.

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/m2va2xvkwl.fsf%40johnmacfarlane.net.
For more options, visit https://groups.google.com/d/optout.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Chapter TOC via filter?
       [not found]     ` <m2va2xvkwl.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
@ 2019-01-10 19:50       ` Axel Rauschmayer
       [not found]         ` <4f0905e3-c55d-4d97-958c-8478ada10bcf-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 13+ messages in thread
From: Axel Rauschmayer @ 2019-01-10 19:50 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 951 bytes --]

Useful, thanks!

Is there a way of intercepting pandoc’s numbering via a Lua filter? That 
would help a lot with implementing --top-level-division=part for HTML via a 
filter.

The field numbering (in Sec) is useful. If Header had it, then numbering 
could happen within the document (instead of – AFAICT – a separate step) 
and filters could influence it.

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/4f0905e3-c55d-4d97-958c-8478ada10bcf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 1392 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Chapter TOC via filter?
       [not found]         ` <4f0905e3-c55d-4d97-958c-8478ada10bcf-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2019-01-10 23:09           ` John MacFarlane
       [not found]             ` <yh480ka7k8155j.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
  0 siblings, 1 reply; 13+ messages in thread
From: John MacFarlane @ 2019-01-10 23:09 UTC (permalink / raw)
  To: Axel Rauschmayer, pandoc-discuss

Axel Rauschmayer <rauschma-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:

> Useful, thanks!
>
> Is there a way of intercepting pandoc’s numbering via a Lua filter? That 

Yes, the numbers are in Sec.  That is how pandoc does it.
You shuold be able to do what you need to in a filter.

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/yh480ka7k8155j.fsf%40johnmacfarlane.net.
For more options, visit https://groups.google.com/d/optout.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Chapter TOC via filter?
       [not found]             ` <yh480ka7k8155j.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
@ 2019-01-10 23:58               ` Axel Rauschmayer
       [not found]                 ` <e9ec0801-2490-4119-88cd-74adbcd9afe6-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 13+ messages in thread
From: Axel Rauschmayer @ 2019-01-10 23:58 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 1014 bytes --]

Alas, that still doesn’t give me part numbers for HTML. For 
example: http://exploringjs.com/impatient-js/toc.html

I’ve written the following filter which mostly does what I want (minus some 
polish): https://gist.github.com/rauschma/7f631cacad55b8b6c920b9334f711244

   - For LaTeX, I would  track section numbers and generate the chapter 
   TOCs the same way. But I would leave the numbering of headings to LaTeX.
   

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/e9ec0801-2490-4119-88cd-74adbcd9afe6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 1453 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Chapter TOC via filter?
       [not found]                 ` <e9ec0801-2490-4119-88cd-74adbcd9afe6-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2019-01-11  5:14                   ` John MacFarlane
       [not found]                     ` <m2o98nvkqc.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
  0 siblings, 1 reply; 13+ messages in thread
From: John MacFarlane @ 2019-01-11  5:14 UTC (permalink / raw)
  To: Axel Rauschmayer, pandoc-discuss


I haven't looked at this in detail, but I would have
thought you could have extracted what you needed from
the `numbering` part of a Sec, which is just
a list of integers, e.g. 2, 4, 2.

If your top level header is parts, then the first
number is the part, the second the chapter, the
third the section.  Then it's just a matter of
converting the part to a roman numeral when the
other numbers are absent, and otherwise ignoring
the part and concatenating the other numbers
with '.' between...


Axel Rauschmayer <rauschma-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:

> Alas, that still doesn’t give me part numbers for HTML. For 
> example: http://exploringjs.com/impatient-js/toc.html
>
> I’ve written the following filter which mostly does what I want (minus some 
> polish): https://gist.github.com/rauschma/7f631cacad55b8b6c920b9334f711244
>
>    - For LaTeX, I would  track section numbers and generate the chapter 
>    TOCs the same way. But I would leave the numbering of headings to LaTeX.
>    
>
> -- 
> You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/e9ec0801-2490-4119-88cd-74adbcd9afe6%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/m2o98nvkqc.fsf%40johnmacfarlane.net.
For more options, visit https://groups.google.com/d/optout.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Chapter TOC via filter?
       [not found]                     ` <m2o98nvkqc.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
@ 2019-01-11 12:56                       ` Axel Rauschmayer
       [not found]                         ` <6e119a06-0158-452e-84e3-b248a4efd4a6-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 13+ messages in thread
From: Axel Rauschmayer @ 2019-01-11 12:56 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 1944 bytes --]



> I haven't looked at this in detail, but I would have 
> thought you could have extracted what you needed from 
> the `numbering` part of a Sec, which is just 
> a list of integers, e.g. 2, 4, 2. 
>
> If your top level header is parts, then the first 
> number is the part, the second the chapter, the 
> third the section.  Then it's just a matter of 
> converting the part to a roman numeral when the 
> other numbers are absent, and otherwise ignoring 
> the part and concatenating the other numbers 
> with '.' between... 
>

The problem is that part numbers don’t affect chapter numbers:

   - I. Part 1
      - Chapter 1
      - Chapter 2
   - II. Part 2
      - Chapter 3
      - Chapter 4
   
The first part of my filter numbers Headers properly (to be used with HTML 
and parts):

   - Visit Headers via a filter.
   - Per Header:
      - Update a counter (with one integer per content entity): depending 
      on the level of the Header, while correctly handling part numbers.
      - Prefix the Header’s content with the properly formatted counter.
   
Given that I already track Headers and their numbers:

   - I just additionally keep a mapping from chapter IDs to a list of the 
   chapter’s Headers.
   - For the chapter TOC, I transform this list to nested bullet lists, in 
   a second pass.
   

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/6e119a06-0158-452e-84e3-b248a4efd4a6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 2592 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Chapter TOC via filter?
       [not found]                         ` <6e119a06-0158-452e-84e3-b248a4efd4a6-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2019-01-11 17:21                           ` BPJ
       [not found]                             ` <CADAJKhDkztkE+k35A4r4XuZJFoy9ivEm3=48YHkbdfNJbMYhrA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  2019-01-11 19:22                           ` John MacFarlane
  1 sibling, 1 reply; 13+ messages in thread
From: BPJ @ 2019-01-11 17:21 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

[-- Attachment #1: Type: text/plain, Size: 3178 bytes --]

You need to keep a counter for the chapter numbers, basically a variable
holding a number to which you add 1 each time you encounter a new chapter
and then replace the "local" number at the chapter level with the value of
this variable for each heading.

BTW number incrementing in Lua is very old school: var = var + 1.


Den fre 11 jan. 2019 13:57 skrev Axel Rauschmayer <rauschma-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:

>
> I haven't looked at this in detail, but I would have
>> thought you could have extracted what you needed from
>> the `numbering` part of a Sec, which is just
>> a list of integers, e.g. 2, 4, 2.
>>
>> If your top level header is parts, then the first
>> number is the part, the second the chapter, the
>> third the section.  Then it's just a matter of
>> converting the part to a roman numeral when the
>> other numbers are absent, and otherwise ignoring
>> the part and concatenating the other numbers
>> with '.' between...
>>
>
> The problem is that part numbers don’t affect chapter numbers:
>
>    - I. Part 1
>       - Chapter 1
>       - Chapter 2
>    - II. Part 2
>       - Chapter 3
>       - Chapter 4
>
> The first part of my filter numbers Headers properly (to be used with HTML
> and parts):
>
>    - Visit Headers via a filter.
>    - Per Header:
>       - Update a counter (with one integer per content entity): depending
>       on the level of the Header, while correctly handling part numbers.
>       - Prefix the Header’s content with the properly formatted counter.
>
> Given that I already track Headers and their numbers:
>
>    - I just additionally keep a mapping from chapter IDs to a list of the
>    chapter’s Headers.
>    - For the chapter TOC, I transform this list to nested bullet lists,
>    in a second pass.
>
> --
> You received this message because you are subscribed to the Google Groups
> "pandoc-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pandoc-discuss/6e119a06-0158-452e-84e3-b248a4efd4a6%40googlegroups.com
> <https://groups.google.com/d/msgid/pandoc-discuss/6e119a06-0158-452e-84e3-b248a4efd4a6%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CADAJKhDkztkE%2Bk35A4r4XuZJFoy9ivEm3%3D48YHkbdfNJbMYhrA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #2: Type: text/html, Size: 4463 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Chapter TOC via filter?
       [not found]                         ` <6e119a06-0158-452e-84e3-b248a4efd4a6-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  2019-01-11 17:21                           ` BPJ
@ 2019-01-11 19:22                           ` John MacFarlane
  1 sibling, 0 replies; 13+ messages in thread
From: John MacFarlane @ 2019-01-11 19:22 UTC (permalink / raw)
  To: Axel Rauschmayer, pandoc-discuss

Axel Rauschmayer <rauschma-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:

>> I haven't looked at this in detail, but I would have 
>> thought you could have extracted what you needed from 
>> the `numbering` part of a Sec, which is just 
>> a list of integers, e.g. 2, 4, 2. 
>>
>> If your top level header is parts, then the first 
>> number is the part, the second the chapter, the 
>> third the section.  Then it's just a matter of 
>> converting the part to a roman numeral when the 
>> other numbers are absent, and otherwise ignoring 
>> the part and concatenating the other numbers 
>> with '.' between... 
>>
>
> The problem is that part numbers don’t affect chapter numbers:

Ah, yes, I see. You could fix this by iterating over the Sec
objects and incrementing the second number as
necessary; then Sec would contain the numbers you need.
Your way works too, of course!

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/yh480kzhs73spm.fsf%40johnmacfarlane.net.
For more options, visit https://groups.google.com/d/optout.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Chapter TOC via filter?
       [not found]                             ` <CADAJKhDkztkE+k35A4r4XuZJFoy9ivEm3=48YHkbdfNJbMYhrA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2019-02-07  1:40                               ` Cormac Relf
  0 siblings, 0 replies; 13+ messages in thread
From: Cormac Relf @ 2019-02-07  1:40 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 3655 bytes --]

I have written something very similar that may be helpful. It wasn't for a 
ToC, but it does the visit-and-update-header-contents thing, and you could 
easily build a ToC as you go and insert it in a second pass.

https://github.com/cormacrelf/dotfiles/blob/master/pandoc/filters/aglc-headers.lua

On Saturday, January 12, 2019 at 4:21:40 AM UTC+11, BP wrote:
>
> You need to keep a counter for the chapter numbers, basically a variable 
> holding a number to which you add 1 each time you encounter a new chapter 
> and then replace the "local" number at the chapter level with the value of 
> this variable for each heading.
>
> BTW number incrementing in Lua is very old school: var = var + 1.
>
>
> Den fre 11 jan. 2019 13:57 skrev Axel Rauschmayer <raus...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org 
> <javascript:>>:
>
>>
>> I haven't looked at this in detail, but I would have 
>>> thought you could have extracted what you needed from 
>>> the `numbering` part of a Sec, which is just 
>>> a list of integers, e.g. 2, 4, 2. 
>>>
>>> If your top level header is parts, then the first 
>>> number is the part, the second the chapter, the 
>>> third the section.  Then it's just a matter of 
>>> converting the part to a roman numeral when the 
>>> other numbers are absent, and otherwise ignoring 
>>> the part and concatenating the other numbers 
>>> with '.' between... 
>>>
>>
>> The problem is that part numbers don’t affect chapter numbers:
>>
>>    - I. Part 1
>>       - Chapter 1
>>       - Chapter 2
>>    - II. Part 2
>>       - Chapter 3
>>       - Chapter 4
>>    
>> The first part of my filter numbers Headers properly (to be used with 
>> HTML and parts):
>>
>>    - Visit Headers via a filter.
>>    - Per Header:
>>       - Update a counter (with one integer per content entity): 
>>       depending on the level of the Header, while correctly handling part numbers.
>>       - Prefix the Header’s content with the properly formatted counter.
>>    
>> Given that I already track Headers and their numbers:
>>
>>    - I just additionally keep a mapping from chapter IDs to a list of 
>>    the chapter’s Headers.
>>    - For the chapter TOC, I transform this list to nested bullet lists, 
>>    in a second pass.
>>    
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "pandoc-discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <javascript:>.
>> To post to this group, send email to pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org 
>> <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/pandoc-discuss/6e119a06-0158-452e-84e3-b248a4efd4a6%40googlegroups.com 
>> <https://groups.google.com/d/msgid/pandoc-discuss/6e119a06-0158-452e-84e3-b248a4efd4a6%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/05cb8702-be42-4970-9a99-084e920b632b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 5869 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2019-02-07  1:40 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-07  4:10 Chapter TOC via filter? Axel Rauschmayer
     [not found] ` <1bb6e5f4-04ce-4209-8223-f928f2943998-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-01-07  4:11   ` Axel Rauschmayer
2019-01-09 14:29   ` Christophe Demko
     [not found]     ` <6fe9c4df-2625-4508-8608-da8499e81599-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-01-09 14:58       ` Gareth Stockwell
2019-01-09 16:46   ` John MacFarlane
     [not found]     ` <m2va2xvkwl.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
2019-01-10 19:50       ` Axel Rauschmayer
     [not found]         ` <4f0905e3-c55d-4d97-958c-8478ada10bcf-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-01-10 23:09           ` John MacFarlane
     [not found]             ` <yh480ka7k8155j.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
2019-01-10 23:58               ` Axel Rauschmayer
     [not found]                 ` <e9ec0801-2490-4119-88cd-74adbcd9afe6-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-01-11  5:14                   ` John MacFarlane
     [not found]                     ` <m2o98nvkqc.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
2019-01-11 12:56                       ` Axel Rauschmayer
     [not found]                         ` <6e119a06-0158-452e-84e3-b248a4efd4a6-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-01-11 17:21                           ` BPJ
     [not found]                             ` <CADAJKhDkztkE+k35A4r4XuZJFoy9ivEm3=48YHkbdfNJbMYhrA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2019-02-07  1:40                               ` Cormac Relf
2019-01-11 19:22                           ` John MacFarlane

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).