Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions local_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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]))
Expand Down