Browse Source

Mise en forme PDF

Numérotation des titres (niveaux 1 et 2)
L'avant propos n'est pas numéroté (et n'apparait pas dans la table des matières)
Le titre principal du document n'est pas un niveau de titre normal
Mise en forme de la première page
prod
Youen 1 year ago
parent
commit
995daaeff9
  1. 11
      pdftoc-to-latex
  2. 16
      source/030_plan_general.md
  3. 57
      source/css/print-theme.css
  4. 17
      source/index.md
  5. 25
      sphinx-tools/make_pdf.py

11
pdftoc-to-latex

@ -56,14 +56,13 @@ exit 0;
sub add_latex_bm {
my $bm = shift;
# Don't extract top level title and subtitle with level > 2
if ($bm->{level} == 0 || $bm->{level} > 2) {
# Don't extract subtitle with level > 1
if ($bm->{level} > 1) {
return;
}
# Make sections become chapters
my $level = $levels[$bm->{level} - 1];
# Remove the first number because it refers to the root title (ie always 1.X)
my $number = substr($bm->{number}, 2);
my $level = $levels[$bm->{level}];
my $number = $bm->{number};
my $title = $bm->{title};
my $page = $bm->{page} + 2;

16
source/030_plan_general.md

@ -1,52 +1,42 @@
# Plan général
## Côté droit
```{image} img/vues-generales/01.svg
:alt: Côté droit
:align: center
```
## Côté gauche
<p>&nbsp;</p>
```{image} img/vues-generales/02.svg
:alt: Côté gauche
:align: center
```
## Avant/Arrière
```{image} img/vues-generales/03.svg
:alt: Avant/arrière
:align: center
```
## Dessus/dessous
<p>&nbsp;</p>
```{image} img/vues-generales/04.svg
:alt: Dessus/dessous
:align: center
```
## Coupe longitudinale
```{image} img/vues-generales/05.svg
:alt: Coupe longitudinale
:align: center
```
## Coupes transversales
<p>&nbsp;</p>
```{image} img/vues-generales/06.svg
:alt: Coupes transversales
:align: center
```
## Coupe en altimétrie
```{image} img/vues-generales/07.svg
:alt: Coupe en altimetrie
:align: center
```

57
source/css/print-theme.css

@ -35,7 +35,43 @@
}
}
h2 {
div[role=navigation], .headerlink {
display: none;
}
.document-title {
width: 100%;
color: #fbbb15;
text-align: center;
font-size: 5em !important;
border-top: 2px solid black;
border-bottom: 2px solid black;
line-height: 1.2;
font-weight: bold;
}
.document-subtitle {
text-align: center;
font-size: 1.5em;
margin-top: 30px;
margin-bottom: 30px;
}
.title-page-footer {
text-align: center;
font-size: 1.2em !important;
margin-top: 30px;
}
/* displayed as a title, but doesn't count in numbering and doesn't appear in TOC */
.fake-title {
font-weight: 700;
font-size: 175% !important;
font-family: Roboto Slab,ff-tisa-web-pro,Georgia,Arial,sans-serif;
break-before: always;
}
h1 {
break-before: always;
}
@ -55,3 +91,22 @@ h2 {
.resized {
width: 550px;
}
/* Automatic title numbering */
body {
counter-reset: h1
}
h1 {
counter-reset: h2
}
h1:before {
counter-increment: h1;
content: counter(h1) ". "
}
h2:before {
counter-increment: h2;
content: counter(h1) "." counter(h2) ". "
}

17
source/index.md

@ -1,20 +1,22 @@
Bienvenue dans la documentation Vhéliotech
===================================
Guide de montage – Version 1.0.0 - Mai 2023
<div class="document-title">vhéliotech</div>
<div class="document-subtitle">Guide de montage – Version 1.0.0 - Mai 2023</div>
```{image} img/vhelio.png
:alt: Vue vhélio perspective
:align: center
:width: 500px
```
```{image} img/vhelio_logo.png
:alt: Logo vhélio
:align: center
:width: 200px
:width: 450px
```
<h2>Avant propos <a class="headerlink" href="#avant-propos" title="Permalink to this heading"></a></h2>
<p class="title-page-footer">Association Vélo solaire pour tous<br/><a href="https://www.vhelio.org">www.vhelio.org</a></p>
<section class="tex2jax_ignore mathjax_ignore" id="avant-propos">
<p class="fake-title">Avant propos</p>
Le projet vhélio est collaboratif (amélioration continue grâce aux contributions de tous). L’objet vhéliotech et le présent document constituent la première version définitive du vhéliotech, mais l'objet est voué à évoluer continuellement. Vous êtes invités à faire part de vos retours/expériences/propositions d’améliorations sur le [forum](https://communaute.vhelio.org) ainsi que sur le [dépôt officiel de la documentation](https://git.vhelio.org/vhelio/vheliotech-guide-de-montage)
@ -38,7 +40,8 @@ En effet, depuis septembre 2020, la communauté s’organise et révèle d’aut
L’ADN du projet vhéliotech décrit en détails, [sur ce lien](https://vhelio.org/le-projet-et-ses-valeurs/), les enjeux et objectifs du projet.
Copyright Vélo Solaire Pour Tous, Mai 2023, sous [licence CERN-OHL-S version 2](https://ohwr.org/cern_ohl_s_v2.txt)
</section>
```{toctree}
010_documentation
020_moyens_necessaires

25
sphinx-tools/make_pdf.py

@ -5,8 +5,9 @@ import os
source_dir = sys.argv[1]
build_dir = sys.argv[2]
insert_toc_after_page = 1
max_bookmark_level = 3
insert_toc_after_page = 2
max_bookmark_level = 2
numbered_levels = 2
index_pdf_filename = build_dir + '/weasyprint/index.pdf'
css_filename = source_dir + '/css/print-theme.css'
@ -51,7 +52,7 @@ if modified_css != original_css:
assert(subprocess.run(['weasyprint', build_dir + '/weasyprint/index.html', index_pdf_filename, '-s', css_filename]).returncode == 0)
# Insert TOC in the PDF
assert(subprocess.run(['pdftk', 'A='+index_pdf_filename, 'B='+build_dir+'/weasyprint/toc.pdf', 'cat', 'A'+str(insert_toc_after_page), 'B', 'A'+str(insert_toc_after_page+1)+'-end', 'output', build_dir + '/weasyprint/vheliotech-without-bookmarks.pdf']).returncode == 0)
assert(subprocess.run(['pdftk', 'A='+index_pdf_filename, 'B='+build_dir+'/weasyprint/toc.pdf', 'cat', 'A1-'+str(insert_toc_after_page), 'B', 'A'+str(insert_toc_after_page+1)+'-end', 'output', build_dir + '/weasyprint/vheliotech-without-bookmarks.pdf']).returncode == 0)
# Restore bookmarks
extract_bookmarks_from = index_pdf_filename
@ -70,7 +71,10 @@ with open(bookmarks_filename) as bookmarks_file:
# Remove link icon character at the end of each bookmark name (these are added by sphinx but make no sense in a PDF bookmark)
metadata = metadata.replace('&#61633;', '')
# Remove bookmarks for small titles, adjust page number for remaining ones
# Remove bookmarks for small titles, adjust page number for remaining ones, and add numbering if level is not above numbered_levels
title_counters = []
for level in range(numbered_levels):
title_counters.append(0)
def filterBookmark(match):
#print('bookmark: "' + match.group(0) + '"')
level = int(match.group(2))
@ -78,7 +82,18 @@ def filterBookmark(match):
return ''
initial_page = int(match.group(3))
final_page = initial_page + toc_num_pages if initial_page > insert_toc_after_page else initial_page
return 'BookmarkBegin\nBookmarkTitle: '+match.group(1).replace('&#160;', ' ')+'\nBookmarkLevel: '+match.group(2)+'\nBookmarkPageNumber: '+str(final_page)+'\n'
title_counters[level - 1] = title_counters[level - 1] + 1
for l in range(level, numbered_levels):
title_counters[l] = 0
title_number = ''
if level <= numbered_levels:
for l in range(level):
title_number += str(title_counters[l]) + '.'
title_number += ' '
return 'BookmarkBegin\nBookmarkTitle: ' + title_number + match.group(1).replace('&#160;', ' ')+'\nBookmarkLevel: '+match.group(2)+'\nBookmarkPageNumber: '+str(final_page)+'\n'
metadata = re.sub('BookmarkBegin\nBookmarkTitle: (.*)\nBookmarkLevel: ([0-9]+)\nBookmarkPageNumber: ([0-9]+)\n', filterBookmark, metadata)
with open(bookmarks_filename, 'w') as bookmarks_file:

Loading…
Cancel
Save