def rst2tex(in_path, out_path): options.mkdir_p(out_path) for file in glob.glob(os.path.join(in_path, '*')): shutil.copy(file, out_path) base_dir = os.path.dirname(__file__) scipy_status = os.path.join(base_dir, '_static/status.sty') shutil.copy(scipy_status, out_path) scipy_style = os.path.join(base_dir, '_static/scipy.sty') shutil.copy(scipy_style, out_path) preamble = r'''\usepackage{scipy}''' # Add the LaTeX commands required by Pygments to do syntax highlighting pygments = None try: import pygments except ImportError: import warnings warnings.warn( RuntimeWarning('Could not import Pygments. ' 'Syntax highlighting will fail.')) if pygments: from pygments.formatters import LatexFormatter from writer.sphinx_highlight import SphinxStyle preamble += LatexFormatter(style=SphinxStyle).get_style_defs() settings = { 'documentclass': 'IEEEtran', 'use_verbatim_when_possible': True, 'use_latex_citations': True, 'latex_preamble': preamble, 'documentoptions': 'letterpaper,compsoc,twoside', 'halt_level': 3, # 2: warn; 3: error; 4: severe } try: rst, = glob.glob(os.path.join(in_path, '*.rst')) except ValueError: raise RuntimeError("Found more than one input .rst--not sure which " "one to use.") content = header + open(rst, 'r').read() tex = dc.publish_string(source=content, writer=writer, settings_overrides=settings) stats_file = os.path.join(out_path, 'paper_stats.json') d = options.cfg2dict(stats_file) d.update(writer.document.stats) options.dict2cfg(d, stats_file) tex_file = os.path.join(out_path, 'paper.tex') with open(tex_file, 'w') as f: f.write(tex)
def arxiv_html(config): mkdir_p(arxiv_dir) for name in ['index', 'submissions']: dest_fn = os.path.join(arxiv_dir, 'arxiv_%s.html' % name) template = tempita.HTMLTemplate(open(os.path.join(template_dir, 'arxiv_%s.html.tmpl' % name), 'r').read()) content = template.substitute(config) with open(dest_fn, mode='w') as f: f.write(content)
def rst2tex(in_path, out_path): options.mkdir_p(out_path) for file in glob.glob(os.path.join(in_path, '*')): shutil.copy(file, out_path) base_dir = os.path.dirname(__file__) scipy_status = os.path.join(base_dir, '_static/status.sty') shutil.copy(scipy_status, out_path) scipy_style = os.path.join(base_dir, '_static/scipy.sty') shutil.copy(scipy_style, out_path) preamble = r'''\usepackage{scipy}''' # Add the LaTeX commands required by Pygments to do syntax highlighting pygments = None try: import pygments except ImportError: import warnings warnings.warn(RuntimeWarning('Could not import Pygments. ' 'Syntax highlighting will fail.')) if pygments: from pygments.formatters import LatexFormatter from writer.sphinx_highlight import SphinxStyle preamble += LatexFormatter(style=SphinxStyle).get_style_defs() settings = {'documentclass': 'IEEEtran', 'use_verbatim_when_possible': True, 'use_latex_citations': True, 'latex_preamble': preamble, 'documentoptions': 'letterpaper,compsoc,twoside', 'halt_level': 3, # 2: warn; 3: error; 4: severe } try: rst, = glob.glob(os.path.join(in_path, '*.rst')) except ValueError: raise RuntimeError("Found more than one input .rst--not sure which " "one to use.") content = header + open(rst, 'r').read() tex = dc.publish_string(source=content, writer=writer, settings_overrides=settings) stats_file = os.path.join(out_path, 'paper_stats.json') d = options.cfg2dict(stats_file) d.update(writer.document.stats) options.dict2cfg(d, stats_file) tex_file = os.path.join(out_path, 'paper.tex') with open(tex_file, 'w') as f: f.write(tex)
def build_paper(paper_id, start=1): out_path = os.path.join(output_dir, paper_id) in_path = os.path.join(papers_dir, paper_id) print("Building:", paper_id) options.mkdir_p(out_path) page_number_file = os.path.join(out_path, 'page_numbers.tex') with io.open(page_number_file, 'w', encoding='utf-8') as f: f.write('\setcounter{page}{%s}' % start) rst2tex(in_path, out_path) pdflatex_stdout = tex2pdf(out_path) page_count(pdflatex_stdout, out_path)
def build_paper(paper_id): out_path = os.path.join(output_dir, paper_id) in_path = os.path.join(papers_dir, paper_id) print "Building:", paper_id rst2tex(in_path, out_path) pdflatex_stdout = tex2pdf(out_path) page_count(pdflatex_stdout, out_path) options.mkdir_p(arxiv_dir) archive = tarfile.TarFile(os.path.join(arxiv_dir,paper_id+'.tar'), 'w') for filename in filter(include_for_arxiv, os.listdir(out_path)): if filename.endswith('-eps-converted-to.pdf'): archive.add(os.path.join(out_path, filename), arcname=filename[:-21]+'.pdf') else: archive.add(os.path.join(out_path, filename), arcname=filename) archive.close()
#!/usr/bin/env python import os import glob import shutil from copy import deepcopy from conf import bib_dir, template_dir, html_dir, static_dir, pdf_dir from options import get_config, mkdir_p from build_template import bib_from_tmpl, html_from_tmpl, from_template config = get_config() mkdir_p(bib_dir) for file in glob.glob(os.path.join(static_dir, '*.css')): shutil.copy(file, html_dir) html_pdfs = os.path.join(html_dir, 'pdfs') mkdir_p(html_pdfs) for file in glob.glob(os.path.join(pdf_dir, '*.pdf')): shutil.copy(file, html_pdfs) citation_key = config['proceedings']['citation_key'] # e.g. proc-scipy-2010 bib_from_tmpl('proceedings', config, citation_key) proc_dict = deepcopy(config) proc_dict.update({ 'pdf': 'pdfs/proceedings.pdf', 'bibtex': 'bib/' + citation_key }) for dest_fn in ['index', 'organization', 'students']:
__FILENAME__ = build_html #!/usr/bin/env python import os import glob import shutil from conf import bib_dir, template_dir, html_dir, static_dir, pdf_dir from options import get_config, mkdir_p from build_template import bib_from_tmpl, html_from_tmpl, from_template config = get_config() mkdir_p(bib_dir) for file in glob.glob(os.path.join(static_dir,'*.css')): shutil.copy(file, html_dir) html_pdfs = os.path.join(html_dir, 'pdfs') mkdir_p(html_pdfs) for file in glob.glob(os.path.join(pdf_dir,'*.pdf')): shutil.copy(file, html_pdfs) citation_key = config['proceedings']['citation_key'] # e.g. proc-scipy-2010 bib_from_tmpl('proceedings', config, citation_key) proc_dict = dict(config.items() + {'pdf': 'pdfs/proceedings.pdf'}.items() + {'bibtex': 'bib/' + citation_key}.items()) for dest_fn in ['index', 'organization', 'students']: html_from_tmpl(dest_fn+'.html', proc_dict, dest_fn)
with open(os.path.join(output_dir, paper_id, 'page_numbers.tex'), 'w') as f: f.write('\setcounter{page}{%s}' % start) # Build table of contents stats.update({'page': {'start': start, 'stop': stop}}) stats.update({'paper_id': paper_id}) return stats, stop if __name__ == "__main__": start = 0 toc_entries = [] options.mkdir_p(pdf_dir) for paper_id in dirs: build_paper(paper_id) stats, start = paper_stats(paper_id, start + 1) toc_entries.append(stats) build_paper(paper_id) src_pdf = os.path.join(output_dir, paper_id, 'paper.pdf') dest_pdf = os.path.join(pdf_dir, paper_id+'.pdf') shutil.copy(src_pdf, dest_pdf) command_line = 'cd '+pdf_dir+' ; pdfannotextractor '+paper_id+'.pdf' run = subprocess.Popen(command_line, shell=True, stdout=subprocess.PIPE) out, err = run.communicate()
#!/usr/bin/env python import os import glob import shutil from conf import bib_dir, template_dir, html_dir, static_dir, pdf_dir from options import get_config, mkdir_p from build_template import bib_from_tmpl, html_from_tmpl, from_template config = get_config() mkdir_p(bib_dir) for file in glob.glob(os.path.join(static_dir, "*.css")): shutil.copy(file, html_dir) html_pdfs = os.path.join(html_dir, "pdfs") mkdir_p(html_pdfs) for file in glob.glob(os.path.join(pdf_dir, "*.pdf")): shutil.copy(file, html_pdfs) citation_key = config["proceedings"]["citation_key"] # e.g. proc-scipy-2010 bib_from_tmpl("proceedings", config, citation_key) proc_dict = dict(config.items() + {"pdf": "pdfs/proceedings.pdf"}.items() + {"bibtex": "bib/" + citation_key}.items()) for dest_fn in ["index", "organization"]: html_from_tmpl(dest_fn + ".html", proc_dict, dest_fn) for article in config["toc"]: art_dict = dict( config.items()
def rst2tex(in_path, out_path): options.mkdir_p(out_path) for file in glob.glob(os.path.join(in_path, '*')): if os.path.isdir(file): copytree(file, out_path) else: shutil.copy(file, out_path) base_dir = os.path.dirname(__file__) scipy_status = os.path.join(base_dir, '_static/status.sty') shutil.copy(scipy_status, out_path) scipy_style = os.path.join(base_dir, '_static/scipy.sty') shutil.copy(scipy_style, out_path) preamble = r'''\usepackage{scipy}''' # Add the LaTeX commands required by Pygments to do syntax highlighting pygments = None try: import pygments except ImportError: import warnings warnings.warn( RuntimeWarning('Could not import Pygments. ' 'Syntax highlighting will fail.')) if pygments: from pygments.formatters import LatexFormatter from writer.sphinx_highlight import SphinxStyle preamble += LatexFormatter(style=SphinxStyle).get_style_defs() settings = { 'documentclass': 'wlpeerj', 'use_verbatim_when_possible': True, 'use_latex_citations': True, 'latex_preamble': preamble, 'documentoptions': 'fleqn,12pt', 'halt_level': 3, # 2: warn; 3: error; 4: severe } try: rst, = glob.glob(os.path.join(in_path, '*.rst')) except ValueError: raise RuntimeError("Found more than one input .rst--not sure which " "one to use.") content = header + open(rst, 'r').read() tex = dc.publish_string(source=content, writer=writer, settings_overrides=settings) tex = tex.replace('subsection{', 'section*{') # remove incorrect \labels texlines = tex.split('\n') texlines = filter(lambda x: not x.startswith(r' \label{'), texlines) tex = '\n'.join(texlines) tex_file = os.path.join(out_path, 'paper.tex') with open(tex_file, 'w') as f: f.write(tex)
__FILENAME__ = build_html #!/usr/bin/env python import os import glob import shutil from conf import bib_dir, template_dir, html_dir, static_dir, pdf_dir from options import get_config, mkdir_p from build_template import bib_from_tmpl, html_from_tmpl, from_template config = get_config() mkdir_p(bib_dir) for file in glob.glob(os.path.join(static_dir, '*.css')): shutil.copy(file, html_dir) html_pdfs = os.path.join(html_dir, 'pdfs') mkdir_p(html_pdfs) for file in glob.glob(os.path.join(pdf_dir, '*.pdf')): shutil.copy(file, html_pdfs) citation_key = config['proceedings']['citation_key'] # e.g. proc-scipy-2010 bib_from_tmpl('proceedings', config, citation_key) proc_dict = dict(config.items() + {'pdf': 'pdfs/proceedings.pdf'}.items() + {'bibtex': 'bib/' + citation_key}.items()) for dest_fn in ['index', 'organization', 'students']: html_from_tmpl(dest_fn + '.html', proc_dict, dest_fn) for article in config['toc']:
'w') as f: f.write('\setcounter{page}{%s}' % start) # Build table of contents stats.update({'page': {'start': start, 'stop': stop}}) stats.update({'paper_id': paper_id}) return stats, stop if __name__ == "__main__": start = 0 toc_entries = [] options.mkdir_p(pdf_dir) for paper_id in dirs: build_paper(paper_id) stats, start = paper_stats(paper_id, start + 1) toc_entries.append(stats) build_paper(paper_id) src_pdf = os.path.join(output_dir, paper_id, 'paper.pdf') dest_pdf = os.path.join(pdf_dir, paper_id + '.pdf') shutil.copy(src_pdf, dest_pdf) command_line = 'cd ' + pdf_dir + ' ; pdfannotextractor ' + paper_id + '.pdf' run = subprocess.Popen(command_line, shell=True,
def rst2tex(in_path, out_path): options.mkdir_p(out_path) for file in glob.glob(os.path.join(in_path, '*')): if os.path.isdir(file): copytree(file, out_path) else: shutil.copy(file, out_path) base_dir = os.path.dirname(__file__) scipy_status = os.path.join(base_dir, '_static/status.sty') shutil.copy(scipy_status, out_path) scipy_style = os.path.join(base_dir, '_static/scipy.sty') shutil.copy(scipy_style, out_path) preamble = r'''\usepackage{scipy}''' # Add the LaTeX commands required by Pygments to do syntax highlighting pygments = None try: import pygments except ImportError: import warnings warnings.warn(RuntimeWarning('Could not import Pygments. ' 'Syntax highlighting will fail.')) if pygments: from pygments.formatters import LatexFormatter from writer.sphinx_highlight import SphinxStyle preamble += LatexFormatter(style=SphinxStyle).get_style_defs() settings = {'documentclass': 'wlpeerj', 'use_verbatim_when_possible': True, 'use_latex_citations': True, 'latex_preamble': preamble, 'documentoptions': 'fleqn,12pt', 'halt_level': 3, # 2: warn; 3: error; 4: severe } try: rst, = glob.glob(os.path.join(in_path, '*.rst')) except ValueError: raise RuntimeError("Found more than one input .rst--not sure which " "one to use.") content = header + open(rst, 'r').read() tex = dc.publish_string(source=content, writer=writer, settings_overrides=settings) tex = tex.replace('subsection{', 'section*{') # remove incorrect \labels texlines = tex.split('\n') texlines = filter(lambda x: not x.startswith(r' \label{'), texlines) tex = '\n'.join(texlines) tex_file = os.path.join(out_path, 'paper.tex') with open(tex_file, 'w') as f: f.write(tex)