From d3108b0612c846941a179fa4a7e43ca89724a01b Mon Sep 17 00:00:00 2001 From: Sylvain Chevallier Date: Mon, 11 Jul 2016 23:46:21 +0200 Subject: [PATCH] support for \newcommand and \renewcommand conversion --- local_build.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/local_build.py b/local_build.py index 13c5e54..e8e61fb 100755 --- a/local_build.py +++ b/local_build.py @@ -25,12 +25,12 @@ """ +import re import os import sys import shutil import subprocess - #lots of dobule-{}'s are here because we use it as a formatting template below MAIN_TEMPLATE = r""" {preamblein} @@ -59,7 +59,6 @@ FIGURE_DEFAULTS = {'placement': '', 'width': '1\columnwidth', 'figure_env': 'figure'} - def get_input_string(filename, localdir, quotepath=True, flatten=False): if flatten: filepath = os.path.join(localdir, filename) @@ -172,14 +171,29 @@ def build_authorea_latex(localdir, builddir, latex_exec, bibtex_exec, outname, else: preamblein = '' if os.path.exists(os.path.join(localdir, 'header.tex')): - headerin = get_input_string('header', get_in_path(localdir, builddir, pathtype), flatten=flatten) + with open(os.path.join(localdir, 'header.tex'), 'r') as h: + lines = h.readlines() + pdflines = [] + pdflines.append(r'\newif\iflatexml\latexmlfalse'+'\n') + for l in lines: + if re.match(r'\\r*e*newcommand', l): + rl = re.search('(^.*)(\[.*\])(\[.*\])(.*)', l) + if len(rl.group(2)) > 2: + pdflines.append(''.join(rl.group(1, 2, 4))+'\n') + else: + pdflines.append(''.join(rl.group(1, 4))+'\n') + else: + pdflines.append(l) + with open(os.path.join(localdir, 'header_pdflatex.tex'), 'w') as p: + p.writelines(pdflines) + + headerin = get_input_string('header_pdflatex', get_in_path(localdir, builddir, pathtype), flatten=flatten) else: headerin = '' if not headerin and not preamblein: print("Neither preable nor header found! Proceeding, but that's rather weird") - if copy_figs: bibloc_abs = os.path.join(get_in_path(localdir, builddir, 'abs'), 'bibliography', 'biblio') + '.bib' shutil.copy(bibloc_abs, os.path.join(builddir, os.path.split(bibloc_abs)[1]))