Search code examples
markdownpandoc

pandoc markdown keep section numeration among different files


Is it possible to keep section numeration between different files?

For instance, I have this file:

 ---
 title: Title
 number_sections: true
 output: latex
 graphics: yes
 header-includes:
   - '\usepackage{graphics}'
 ---
           
    # Section 1
    
    ## SUbsection
    
    # Section 2

The output file (pdf) will have the following numeration:

1 Section 1
1.1 Subsection
2 Section 2

If I have a 2nd file like:

 ---
 title: Title
 number_sections: true
 output: latex
 graphics: yes
 header-includes:
   - '\usepackage{graphics}'
 ---
    
    # Section 3

The output file (pdf) will have the following numeration:

1 Section 3

But I wanted it to be like:

3 Section 3

The only workaround I found for now is to repeat the content of previous files:

---
title: Title
number_sections: true
output: latex
graphics: yes
header-includes:
  - '\usepackage{graphics}'
---

# Section 1

## SUbsection

# Section 2

## Another subsection

\newpage

# Section 3

The new content

Which gives a pdf file like:

1 Section 1
1.1 Subsection
2 Section 2

3 Section 3
New content...

I would also be able to keep numeration of subsections as well.

I'm compiling with:

pandoc file.md -o file.pdf --pdf-engine=xelatex --number-sections --highlight-style tango

Any help is appreciated.


Solution

  • As suggested by @tarleb

    \setcounter{section}{3}
    

    and

    \setcounter{subsection}{3}
    

    get the job done manually.