def test_max_image_width(format_):
    ctx = Context()
    ctx.paper_size = format_
    _make_pdf._set_max_image_width(ctx)
    assert ctx.image_max_width == int(_make_pdf.PAPER_FORMATS_WIDTH[format_])
def test_max_image_wrong_value(format_):
    ctx = Context()
    ctx.paper_size = format_
    with pytest.raises(ValueError):
        _make_pdf._set_max_image_width(ctx)
Exemple #3
0
def _build_folder(ctx: Context):
    ctx.info(f'making PDF')

    with TempDir(ctx):

        get_media_folders(ctx)

        get_template(ctx)

        get_index_file(ctx)

        get_settings(ctx)

        get_includes(ctx)

        ctx.template_file = Path(ctx.temp_dir, 'template.tex').absolute()

        title = ctx.source_folder.name
        ctx.title = title

        out_folder = elib.path.ensure_dir('.', must_exist=False, create=True)
        ctx.out_folder = out_folder

        for paper_size in ctx.settings.papersize:
            ctx.paper_size = paper_size
            _set_max_image_width(ctx)

            if paper_size.lower() == 'a4' or len(ctx.settings.papersize) == 1:
                ctx.out_file = Path(out_folder, f'{title}.PDF').absolute()
            else:
                ctx.out_file = Path(out_folder, f'{title}_{paper_size}.PDF').absolute()

            _download_existing_file(ctx)

            if skip_file(ctx):
                continue

            process_markdown(ctx)

            check_for_unused_images(ctx)

            process_latex(ctx)

            ctx.source_file = Path(ctx.temp_dir, 'source.md').absolute()
            ctx.source_file.write_text(ctx.markdown_text, encoding='utf8')

            ctx.info(f'building format: {paper_size}')

            ctx.debug(f'context:\n{elib.pretty_format(ctx.__repr__())}')

            # noinspection SpellCheckingInspection
            pandoc_cmd = [
                '-s',
                '--toc',
                f'--template "{ctx.template_file}"',
                f'--listings "{ctx.source_file}"',
                f'-o "{ctx.out_file}"',
                '-V geometry:margin=1.5cm',
                '-V test',
                '-V geometry:headheight=17pt',
                '-V geometry:includehead',
                '-V geometry:includefoot',
                '-V geometry:heightrounded',
                '-V lot',
                '-V lof',
                '--pdf-engine=xelatex',
                f'-V papersize:{ctx.paper_size}',
                '-N',
            ]

            PANDOC(' '.join(pandoc_cmd))

            add_metadata_to_pdf(ctx)