|
6 | 6 | .. _Sphinx: http://www.sphinx-doc.org/
|
7 | 7 | """
|
8 | 8 | import codecs
|
| 9 | +import itertools |
9 | 10 | import logging
|
10 | 11 | import os
|
11 | 12 | import shutil
|
12 | 13 | import sys
|
13 | 14 | import zipfile
|
14 | 15 | from glob import glob
|
| 16 | +from pathlib import Path |
15 | 17 |
|
16 | 18 | from django.conf import settings
|
17 | 19 | from django.template import loader as template_loader
|
@@ -392,6 +394,57 @@ def build(self):
|
392 | 394 | raise BuildEnvironmentError('No TeX files were found')
|
393 | 395 |
|
394 | 396 | # Run LaTeX -> PDF conversions
|
| 397 | + if self.project.has_feature(Feature.USE_PDF_LATEXMK): |
| 398 | + return self._build_latexmk(cwd, latex_cwd) |
| 399 | + |
| 400 | + return self._build_pdflatex(tex_files, latex_cwd) |
| 401 | + |
| 402 | + def _build_latexmk(self, cwd, latex_cwd): |
| 403 | + # These steps are copied from the Makefile generated by Sphinx >= 1.6 |
| 404 | + # https://github.com/sphinx-doc/sphinx/blob/master/sphinx/texinputs/Makefile_t |
| 405 | + latex_path = Path(latex_cwd) |
| 406 | + images = [] |
| 407 | + for extension in ('png', 'gif', 'jpg', 'jpeg'): |
| 408 | + images.extend(latex_path.glob(f'*.{extension}')) |
| 409 | + |
| 410 | + # FIXME: instead of checking by language here, what we want to check if |
| 411 | + # ``latex_engine`` is ``platex`` |
| 412 | + pdfs = [] |
| 413 | + if self.project.language == 'ja': |
| 414 | + pdfs = latex_path.glob('*.pdf') |
| 415 | + |
| 416 | + for image in itertools.chain(images, pdfs): |
| 417 | + self.run( |
| 418 | + 'extractbb', |
| 419 | + image.name, |
| 420 | + cwd=latex_cwd, |
| 421 | + record=False, |
| 422 | + ) |
| 423 | + |
| 424 | + rcfile = 'latexmkrc' |
| 425 | + if self.project.language == 'ja': |
| 426 | + rcfile = 'latexmkjarc' |
| 427 | + |
| 428 | + cmd_ret = self.run( |
| 429 | + 'latexmk', |
| 430 | + '-r', |
| 431 | + rcfile, |
| 432 | + |
| 433 | + # FIXME: check for platex here as well |
| 434 | + '-pdfdvi' if self.project.language == 'ja' else '-pdf', |
| 435 | + |
| 436 | + '-dvi-', |
| 437 | + '-ps-', |
| 438 | + f'-jobname={self.project.slug}', |
| 439 | + warn_only=True, |
| 440 | + cwd=latex_cwd, |
| 441 | + ) |
| 442 | + |
| 443 | + self.pdf_file_name = f'{self.project.slug}.pdf' |
| 444 | + |
| 445 | + return True # :) |
| 446 | + |
| 447 | + def _build_pdflatex(self, tex_files, latex_cwd): |
395 | 448 | pdflatex_cmds = [
|
396 | 449 | ['pdflatex', '-interaction=nonstopmode', tex_file]
|
397 | 450 | for tex_file in tex_files
|
|
0 commit comments