Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

suppress section numberings in nbconvert to latex?

Is it possible with nbconvert --> latex --> PDF to suppress section numberings?

Essentially I would like to keep the simple font size distinctions that the markdown header syntax (#, ##, etc.), and ipynb section headings provide (nbconvert --to latex appears to treat these same), and still use these to define section headings, but without the numberings. Then I also have the option of adding my own numbers manually.

I can cope with losing some aspects of general latex document structuring and functionality. Ideally though I would like to keep that information, and just suppress the numberings in the PDF.

Cheers.

like image 689
J Grif Avatar asked Feb 15 '23 12:02

J Grif


1 Answers

You can simply use the stared version of the LaTeX heading tags (section*, subsection*).
To do so, you have to create a custom template (e.g. secnum.tplx) which could look like the following

for IPython 1.x:

((*- extends 'latex_article.tplx' -*))

((* block h1 -*))section*((* endblock h1 -*))
((* block h2 -*))subsection*((* endblock h2 -*))
((* block h3 -*))subsubsection*((* endblock h3 -*))
((* block h4 -*))paragraph*((* endblock h4 -*))
((* block h5 -*))subparagraph*((* endblock h5 -*))

for IPython 2.x:

((*- extends 'article.tplx' -*))

((* block h1 -*))\section*((* endblock h1 -*))
((* block h2 -*))\subsection*((* endblock h2 -*))
((* block h3 -*))\subsubsection*((* endblock h3 -*))
((* block h4 -*))\paragraph*((* endblock h4 -*))
((* block h5 -*))\subparagraph*((* endblock h5 -*))

for IPython 3.x:

As IPython 3.x removed the heading cell type these approaches are no longer applicable here.

((* extends 'article.tplx' *))

((* block commands *))
\setcounter{secnumdepth}{0} % Turns off numbering for sections
((( super() )))
((* endblock commands *))

Note that stared headings will not be present in the TOC.
To use these templates, call them during the conversion like
ipython nbconvert --to=latex --template=secnum.tplx file.ipynb

like image 182
Jakob Avatar answered May 10 '23 04:05

Jakob