Skip to content

Commit

Permalink
Latex feature pages: Continue page numbering
Browse files Browse the repository at this point in the history
The feature pages start with page number one. This patch keeps count of
the number of pdf pages written _before_ the feature pages and then
starts with the number after that. For most characters, this is 4, but 3
characters without spells.
  • Loading branch information
PJBrs committed Aug 22, 2024
1 parent 95014f3 commit b342519
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
1 change: 1 addition & 0 deletions dungeonsheets/forms/preamble.tex
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,4 @@
\begin{document}

\chapter*{[[ title ]]}
[% if first_page is defined %]\setcounter{page}{[[ first_page ]]}[% endif %]
2 changes: 1 addition & 1 deletion dungeonsheets/latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def create_latex_pdf(
basename: str,
keep_temp_files: bool = False,
use_dnd_decorations: bool = False,
comm1: str = "pdflatex"
comm1: str = "pdflatex",
):
# Create tex document
tex_file = f"{basename}.tex"
Expand Down
35 changes: 23 additions & 12 deletions dungeonsheets/make_sheets.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from itertools import product
from multiprocessing import Pool, cpu_count
from pathlib import Path
from pypdf import PdfReader
from typing import Union, Sequence, Optional, List

from dungeonsheets import (
Expand Down Expand Up @@ -398,6 +399,7 @@ def make_character_content(
fancy_decorations: bool = False,
spell_order: bool = False,
feat_order: bool = False,
first_page: int = 1,
) -> List[str]:
"""Prepare the inner content for a character sheet.
Expand Down Expand Up @@ -432,6 +434,7 @@ def make_character_content(
content = [
jinja_env.get_template(f"preamble.{content_format}").render(
use_dnd_decorations=fancy_decorations,
first_page=first_page,
title="Features, Magical Items and Spells",
)
]
Expand Down Expand Up @@ -594,17 +597,8 @@ def make_character_sheet(
person_base = basename + "_person"
sheets = [char_base + ".pdf"]
pages = []
# Prepare the tex/html content
content_suffix = format_suffixes[output_format]
# Create a list of features and magic items
content = make_character_content(
character=character,
content_format=content_suffix,
fancy_decorations=fancy_decorations,
spell_order=spell_order,
feat_order=feat_order,
)
# Typeset combined LaTeX file
totalpages = 0
# Typeset LaTeX character, background and spell-sheet files
if output_format == "pdf":
if use_tex_template:
msavage_sheet(
Expand Down Expand Up @@ -633,7 +627,24 @@ def make_character_sheet(
)
for spell_base in created_basenames:
sheets.append(spell_base + ".pdf")
# Combined with additional LaTeX pages with detailed character info
# Check how many pages we've written
for file in sheets:
with open(file, 'rb') as handle:
readpdf = PdfReader(handle)
totalpages = totalpages + len(readpdf.pages)
# Prepare the tex/html content
content_suffix = format_suffixes[output_format]
# Create a list of features and magic items
content = make_character_content(
character=character,
content_format=content_suffix,
fancy_decorations=fancy_decorations,
spell_order=spell_order,
feat_order=feat_order,
first_page=totalpages + 1,
)
if output_format == "pdf":
# Create and combine additional LaTeX pages with detailed character info
features_base = "{:s}_features".format(basename)
try:
if len(content) > 2:
Expand Down

0 comments on commit b342519

Please sign in to comment.