def test_process_template(): ctx = Context() template = Path('./template.tex').absolute() template_out = Path('./out.tex').absolute() ctx.template_file = template_out ctx.template_source = template ctx.media_folders = [] template.touch() ctx.template_source = template latex.process_latex(ctx) assert ctx.template_file.read_text(encoding='utf8') == ''
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)