Skip to content

Commit

Permalink
dungeonsheets/modules: Add MSavage latex template
Browse files Browse the repository at this point in the history
This patch adds the MSavage latex template as a submodule
to dungeonsheets, adds it to the TEXINPUTS environment
and adds TTFONTS environment variable to find the kalam
font.

Furthermore, make the MSavage latex template part of the
tests in the github workflow.

Remove babel support from the MSavage latex template,
otherwise latex will complain about missing languages
(alternatively, we could add the languages directory from
the dnd class to pyproject.toml).

The latest version of the MSavage latex template adds
automatic text scaling so that text fields no longer overflow with
longer inputs.

This fixes canismarko#92
  • Loading branch information
PJBrs committed Jul 7, 2024
1 parent 5ffa071 commit 8c86bed
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/python-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Set up required system dependencies
run: |
sudo apt-get update
sudo apt-get -y install pdftk texlive-latex-base texlive-latex-extra texlive-fonts-recommended texlive-fonts-extra
sudo apt-get -y install pdftk texlive-latex-base texlive-latex-extra texlive-fonts-recommended texlive-fonts-extra texlive-pstricks
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
Expand All @@ -37,7 +37,7 @@ jobs:
run: >
cd examples/;
makesheets --debug;
makesheets --debug --fancy;
makesheets --debug --fancy --tex-template;
makesheets --debug --output-format=epub;
cd ../;
pytest --cov=dungeonsheets tests/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "dungeonsheets/modules/DND-5e-LaTeX-Template"]
path = dungeonsheets/modules/DND-5e-LaTeX-Template
url = https://github.com/rpgtex/DND-5e-LaTeX-Template.git
[submodule "dungeonsheets/modules/DND-5e-LaTeX-Character-Sheet-Template"]
path = dungeonsheets/modules/DND-5e-LaTeX-Character-Sheet-Template
url = https://github.com/matsavage/DND-5e-LaTeX-Character-Sheet-Template
2 changes: 0 additions & 2 deletions dungeonsheets/forms/MSavage_template.tex
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
\usepackage{ifthen}
\usepackage{pstricks}

\usepackage[UKenglish]{babel}

\usepackage{dndtemplate}
\usepackage{bookmark}

Expand Down
19 changes: 18 additions & 1 deletion dungeonsheets/latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def create_latex_pdf(
basename: str,
keep_temp_files: bool = False,
use_dnd_decorations: bool = False,
use_tex_template: bool = False,
comm1: str = "pdflatex",
):
# Create tex document
Expand All @@ -69,14 +70,30 @@ def create_latex_pdf(
str(tex_file),
]

# Deal with TEXINPUTS and add paths to latex modules
environment = os.environ
tex_env = environment.get('TEXINPUTS', '')
module_root = Path(__file__).parent / "modules/"
module_dirs = [module_root / mdir for mdir in ["DND-5e-LaTeX-Template"]]
module_dirs = [module_root / mdir for mdir in ["DND-5e-LaTeX-Template", "DND-5e-LaTeX-Character-Sheet-Template"]]
log.debug(f"Loading additional modules from {module_dirs}.")
texinputs = ['.', *module_dirs, module_root, tex_env]
separator = ';' if isinstance(module_root, pathlib.WindowsPath) else ':'
environment['TEXINPUTS'] = separator.join(str(path) for path in texinputs)

if use_tex_template:
environment['TTFONTS'] = ""
# Find the Kalam font from the DND-5e-LaTeX-Character-Sheet-Template
fontpath_command = [
"kpsewhich",
"--expand-path",
"'$TTFONTS'",
]
fontpath_proc = subprocess.run(fontpath_command, capture_output=True, env=environment)
if isinstance(fontpath_proc.stdout, bytes):
fontpath_proc.stdout = fontpath_proc.stdout.decode()
environment['TTFONTS'] = separator.join(str(path) for path in [*module_dirs, fontpath_proc.stdout])

# Prepare the latex subprocess
passes = 2 if use_dnd_decorations else 1
log.debug(tex_command_line)
log.debug("LaTeX command: %s" % " ".join(tex_command_line))
Expand Down
1 change: 1 addition & 0 deletions dungeonsheets/make_sheets.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ def msavage_sheet(character, basename, debug=False):
keep_temp_files=debug,
use_dnd_decorations=True,
comm1="xelatex",
use_tex_template=True,
)


Expand Down
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ dungeonsheets = [
"modules/DND-5e-LaTeX-Template/*",
"modules/DND-5e-LaTeX-Template/lib/*",
"modules/DND-5e-LaTeX-Template/img/*",
"modules/DND-5e-LaTeX-Character-Sheet-Template/*",
"modules/DND-5e-LaTeX-Character-Sheet-Template/template/*",
"modules/DND-5e-LaTeX-Character-Sheet-Template/template/fonts/*",
"modules/DND-5e-LaTeX-Character-Sheet-Template/template/character-sheet/*",
"modules/DND-5e-LaTeX-Character-Sheet-Template/template/background-sheet/*",
"modules/DND-5e-LaTeX-Character-Sheet-Template/template/half-spell-sheet/*",
"modules/DND-5e-LaTeX-Character-Sheet-Template/template/spell-sheet/*",
]

[tool.setuptools_scm]
Expand Down

0 comments on commit 8c86bed

Please sign in to comment.