David Koes localbuild  over 8 years ago

Commit id: fed45d173e8668ddc00be178bc0cf804868aede4

deletions | additions      

       

number = {2},  pages = {174--176},  publisher = {Wiley Online Library},  title = {{The Use of Three-Dimensional Shape and Electrostatic Similarity Searching in the Identification of a Melanin{\^a}Concentrating Melanin Concentrating  Hormone Receptor 1 Antagonist}}, volume = {67},  year = {2006},  issn = {1747-0285},           

#!/usr/bin/env python  from __future__ import division, print_function  """  This script generates a file to use for building authorea papers, and then runs  latex on them.  Requires python >= 2.6 (3.x should work, too)  The key assumptions are:  * ``layout.md`` exists in the article (I think it always does in Authorea)  * ``preamble.tex``, ``header.tex``, ``title.tex``, and  ``bibliobgraphy/biblio.bib`` exist (I think these are created normally in a  new Authorea article)  * ``posttitle.tex`` exists. This one you'll have to create, containing  everything you want after the title but before the beginning of the document.  """  import os, re  import subprocess  #lots of dobule-{}'s are here because we use it as a formatting template below  MAIN_TEMPLATE = r"""  {preamblein}  {headerin}  \begin{{document}}  {titlecontent}  {sectioninputs}  \bibliography{{{bibloc}}}{{}}  \end{{document}}  """  FIGURE_TEMPLATE=r"""  \begin{figure}[tb]  \centering  \includegraphics[width=\linewidth]{}    \end{figure}  """.replace('{', '{{').replace('}', '}}').replace('<', '{').replace('>', '}')  WRAPFIGURE_TEMPLATE=r"""  \begin{wrapfigure}  \centering  \includegraphics[width=1\linewidth]{}      \end{wrapfigure}  """.replace('{', '{{').replace('}', '}}').replace('<', '{').replace('>', '}')  FIGURESC_TEMPLATE=r"""  \begin{SCfigure}[50][tb]  \centering  \includegraphics[width=]{}    \end{SCfigure}  """.replace('{', '{{').replace('}', '}}').replace('<', '{').replace('>', '}')  STARTFIG_TEMPLATE=r"""  \begin{figure}[tb]  \centering  \begin{minipage}{\linewidth}  \includegraphics[width=\linewidth]{}    \end{minipage}""".replace('{', '{{').replace('}', '}}').replace('<', '{').replace('>', '}')  ENDFIG_TEMPLATE=r"""\hfill  \begin{minipage}{\linewidth}  \includegraphics[width=\linewidth]{}    \end{minipage}  \end{figure}  """.replace('{', '{{').replace('}', '}}').replace('<', '{').replace('>', '}')  def get_input_string(filename, localdir):  if filename.endswith('.tex'):  filename = filename[:-4]  return r'\input{' + os.path.join(os.path.abspath(localdir), filename) + '}'  def get_figure_string(filename, localdir):  figdir, figfn = os.path.split(filename)  figdir = os.path.join(localdir, figdir)  print('rep', figfn)  figfnbase = os.path.splitext(figfn)[0]  figfn = os.path.join(figdir, figfn)  pdffn = os.path.join(figdir, figfnbase + '.pdf')  epsfn = os.path.join(figdir, figfnbase + '.eps')  figsize = 1  if not os.path.exists(pdffn):  pdffn = None  if not os.path.exists(epsfn):  epsfn = None  if pdffn or epsfn:  figfn = os.path.join(figdir, figfnbase)  figfn = os.path.abspath(figfn)  capfn = os.path.join(figdir, 'caption.tex')  template = FIGURE_TEMPLATE  if os.path.exists(capfn):  caption = r'\caption{ \protect\input{' + os.path.abspath(capfn) + '}}'  captext = open(capfn).read()    m = re.search(r'figsize (\S+)',captext)  if m:  figsize = m.group(1)  m = re.search(r'wrapfig (\S+)\s*(\S*)$',captext,flags = re.MULTILINE)   sc = re.search(r'sidecap (\S+)',captext,flags = re.MULTILINE)   stfig = re.search(r'startfig (\S+)',captext,flags = re.MULTILINE)  endfig = re.search(r'endfig (\S+)',captext,flags = re.MULTILINE)  if m:  template = WRAPFIGURE_TEMPLATE  wrapoptions = m.group(1)  endcap = m.group(2)  elif sc:  template = FIGURESC_TEMPLATE  figwidth = sc.group(1)  elif stfig:  template = STARTFIG_TEMPLATE  figwidth = stfig.group(1)  elif endfig:  template = ENDFIG_TEMPLATE  figwidth = endfig.group(1)  elif re.search(r'%nofig',captext):  template = ''  else:  caption = ''  return template.format(**locals())  def build_authorea_latex(localdir, builddir, latex_exec, bibtex_exec, outname,  usetitle, dobibtex, npostbibcalls, openwith):  if not os.path.exists(builddir):  os.mkdir(builddir)  if not os.path.isdir(builddir):  raise IOError('Requested build directory {0} is a file, not a '  'directory'.format(builddir))  # generate the main tex file as a string  preamblein = get_input_string('preamble', localdir)  headerin = get_input_string('header', localdir)  bibloc = os.path.join(os.path.abspath(localdir), 'bibliography', 'biblio')  titlecontent = []  if usetitle:  titlecontent.append(r'\title{' + get_input_string('title', localdir) + '}')  if os.path.exists(os.path.join(os.path.abspath(localdir), 'posttitle.tex')):  titlecontent.append(get_input_string('posttitle', localdir))  titlecontent = '\n'.join(titlecontent)  sectioninputs = []  with open(os.path.join(localdir, 'layout.md')) as f:  for l in f:  ls = l.strip()  if ls == '':  pass  elif ls.startswith('figures'):  sectioninputs.append(get_figure_string(ls, localdir))  else:  sectioninputs.append(get_input_string(ls, localdir))  sectioninputs = '\n'.join(sectioninputs)  maintexstr = MAIN_TEMPLATE.format(**locals())  #now save that string out as a file  outname = outname if outname.endswith('.tex') else (outname + '.tex')  outtexpath = os.path.join(builddir, outname)  with open(outtexpath, 'w') as f:  f.write(maintexstr)  if outname.endswith('.tex'):  outname = outname[:-4]  #now actually run latex/bibtex  args = [latex_exec, outname + '.tex']  print('\n\RUNNING THIS COMMAND: "{0}"\n'.format(' '.join([latex_exec, outname + '.tex'])))  subprocess.check_call(args, cwd=builddir)  if dobibtex:  args = [bibtex_exec, outname]  print('\n\RUNNING THIS COMMAND: "{0}"\n'.format(' '.join([latex_exec, outname + '.tex'])))  subprocess.check_call(args, cwd=builddir)  for _ in range(npostbibcalls):  args = [latex_exec, outname + '.tex']  print('\n\RUNNING THIS COMMAND: "{0}"\n'.format(' '.join([latex_exec, outname + '.tex'])))  subprocess.check_call(args, cwd=builddir)  #launch the result if necessary  resultfn = outtexpath[:-4] + ('.pdf' if 'pdf' in latex_exec else '.dvi')  if openwith:  args = openwith.split(' ')  args.append(resultfn)  print('\nLaunching as:' + str(args), '\n')  subprocess.check_call(args)  else:  msg = '\nBuild completed. You can see the result in "{0}": "{1}"'  print(msg.format(builddir, resultfn), '\n')  if __name__ == '__main__':  import argparse  parser = argparse.ArgumentParser(description='Local builder for authorea papers.')  parser.add_argument('localdir', nargs='?', default='.',  help='The directory to actually search for the authorea'  ' files in. Default to the current directory.')  parser.add_argument('--build-dir', '-d', default='authorea_build',  help='the directory to build the paper in')  parser.add_argument('--latex', '-l', default='pdflatex',  help='The executable to use for the latex build step.')  parser.add_argument('--bibtex', '-b', default='bibtex',  help='The executable to use for the bibtex build step.')  parser.add_argument('--filename', '-f', default='authorea_paper',  help='The name to use for the output tex file.')  parser.add_argument('--no-bibtex', action='store_false', dest='usebibtex',  help='Provide this to not run bibtex.')  parser.add_argument('--no-title', action='store_false', dest='usetitle',  help='Provide this to skip the title command.')  parser.add_argument('--n-runs-after-bibtex', '-n', type=int, default=3,  help='The number of times to call latex after bibtex.')  parser.add_argument('--open-with', '-o', default=None,  help='An executable to launch the output file with. '  'Default is to not do anything with it.')  args = parser.parse_args()  build_authorea_latex(args.localdir, args.build_dir, args.latex, args.bibtex,  args.filename, args.usetitle, args.usebibtex,  args.n_runs_after_bibtex, args.open_with)           

\author{David Koes \and Ethan Hain}  \institute{David Koes \at Affiliation not available \and Ethan Hain \at Affiliation not available}  %\authorrunning{Short form of author list} % if too long for running head  %\date{Received: date / Accepted: date}  % The correct dates will be entered by the editor  \maketitle           

%%%%%%%%%%%%%%%%%%%%%%% file template.tex %%%%%%%%%%%%%%%%%%%%%%%%%  %  % This is a general template file for the LaTeX package SVJour3  % for Springer journals. Springer Heidelberg 2010/09/16  %  % Copy it to a new file with a new name and use it as the basis  % for your article. Delete % signs as needed.  %  % This template includes a few options for different layouts and  % content for various journals. Please consult a previous issue of  % your journal as needed.  %  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %  % First comes an example EPS file -- just ignore it and  % proceed on the \documentclass line  % your LaTeX will extract the file if required  \begin{filecontents*}{example.eps}  %!PS-Adobe-3.0 EPSF-3.0  %%BoundingBox: 19 19 221 221  %%CreationDate: Mon Sep 29 1997  %%Creator: programmed by hand (JK)  %%EndComments  gsave  newpath  20 20 moveto  20 220 lineto  220 220 lineto  220 20 lineto  closepath  2 setlinewidth  gsave  .4 setgray fill  grestore  stroke  grestore  \end{filecontents*}  %  \RequirePackage{fix-cm}  %  %\documentclass{svjour3} % onecolumn (standard format)  %\documentclass[smallcondensed]{svjour3} % onecolumn (ditto)  %\documentclass[smallextended]{svjour3} % onecolumn (second format)  \documentclass[twocolumn]{svjour3} % twocolumn  %  \smartqed % flush right qed marks, e.g. at end of proof  %  \usepackage{graphicx}  \usepackage[space]{grffile}  \usepackage{latexsym}  \usepackage{textcomp}  \usepackage{longtable}  \usepackage{multirow,booktabs}  \usepackage{amsfonts,amsmath,amssymb}  \usepackage{natbib}  \usepackage{url}  \usepackage{hyperref}  \hypersetup{colorlinks=false,pdfborder={0 0 0}}  %\usepackage{latexml}  \usepackage[utf8x]{inputenc}  \usepackage[english]{babel}  %  % \usepackage{mathptmx} % use Times fonts if available on your TeX system  %  % insert here the call for the packages your document requires  %\usepackage{latexsym}  % etc.  %  % please place your own definitions here and don't use \def but  % \newcommand{}{}  %  % Insert the name of "your journal" with  % \journalname{myjournal}  %  \bibliographystyle{spmpsci}