Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
EOASkripts/eoatex2pdf.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executable file
136 lines (126 sloc)
3.72 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from utils.load_config import load_config, check_executable, exec_command, copy_dir_overwrite | |
import utils.libeoaconvert as libeoaconvert | |
import argparse | |
from pathlib import Path | |
import logging | |
import os | |
import sys | |
import shutil | |
import pathlib | |
BASE_DIR = Path( __file__ ).resolve().parent | |
SCRIPT_PATH = Path( __file__ ) | |
SCRIPT_NAME = SCRIPT_PATH.stem | |
def main( | |
input_file, | |
output_dir, | |
nobiber | |
): | |
check_executable( "xelatex" ) | |
if( not os.path.exists( output_dir ) ): | |
os.makedirs( output_dir ) | |
input_file = Path( input_file ) | |
input_dir = input_file.resolve().parent | |
input_path = Path( input_file ) | |
if input_path.suffix == '': | |
input_path = input_path.with_suffix( ".tex" ) | |
elif input_path.suffix != ".tex": | |
raise( Exception( "input file matching '*.tex' expected" ) ) | |
output_dir = Path( output_dir ) | |
fixed_file_path = output_dir / input_file.with_suffix( ".tex" ).name | |
libeoaconvert.enable_preamble( | |
input_file = input_path, | |
output_file = fixed_file_path, | |
pdf_or_xml = "pdf" | |
) | |
copy_dir_overwrite( | |
input_dir / "texfiles", | |
output_dir / "texfiles" | |
) | |
copy_dir_overwrite( | |
input_dir / "preambel", | |
output_dir / "preambel" | |
) | |
if (input_dir / "inline").exists(): | |
copy_dir_overwrite( | |
input_dir / "inline", | |
output_dir / "inline" | |
) | |
if (input_dir / "images").exists(): | |
copy_dir_overwrite( | |
input_dir / "images", | |
output_dir / "images" | |
) | |
if (input_dir / "facsim").exists(): | |
copy_dir_overwrite( | |
input_dir / "facsim", | |
output_dir / "facsim" | |
) | |
output_dir = output_dir.resolve() | |
cwd = Path.cwd() | |
os.chdir( output_dir ) | |
logging.info( "cd {}".format( output_dir ) ) | |
if nobiber: | |
logging.info("Skipping biber and running only two passes of XeLaTeX.") | |
pass | |
else: | |
exec_command( | |
f"xelatex --halt-on-error {input_file.name}", | |
) | |
exec_command( | |
"biber {}".format( input_file.stem ), | |
) | |
exec_command( | |
f"xelatex --halt-on-error {input_file.name}", | |
) | |
exec_command( | |
f"xelatex --halt-on-error {input_file.name}", | |
) | |
logging.info( "cd {}".format( cwd ) ) | |
os.chdir( cwd ) | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser( | |
formatter_class=argparse.ArgumentDefaultsHelpFormatter | |
) | |
parser.add_argument( | |
"-f", "--filename", | |
required = True, | |
help="Name of main EOATeX file without .tex extension." | |
) | |
parser.add_argument( | |
"-o", "--output-dir", | |
default = "./output/latex", | |
help = "output directory" | |
) | |
parser.add_argument( | |
"-c", "--config", | |
default = BASE_DIR / "config" / "eoaconvert.cfg", | |
help="Name of config file" | |
) | |
parser.add_argument( | |
"-l", "--log-file", | |
default = Path("output/logs", SCRIPT_NAME).with_suffix(".log"), | |
help="logfile" | |
) | |
parser.add_argument( | |
"--log-level", | |
default = "INFO", | |
help="log level: choose between DEBUG, INFO, WARNING, ERROR, CRITICAL" | |
) | |
parser.add_argument( | |
"--no-biber", | |
action="store_true", | |
default = False, | |
help="Run only two passes of XeLaTeX and no biber." | |
) | |
args = parser.parse_args() | |
load_config( | |
args.config, | |
args.log_level, | |
args.log_file | |
) | |
main( | |
input_file = args.filename, | |
output_dir = args.output_dir, | |
nobiber = args.no_biber | |
) |