Thursday 4 July 2013

ipython header for document preparation and publication quality plotting.


# hideOutput
# Document generation.  If problem run from shell the commands one by one.
docroot = '/home/starnesm/projects/FT/ipython/'
a = '20130607-v9Transducer'

from reference import hideIpythonCells as hideIpythonCells
from IPython.zmq.pylab import backend_inline
from IPython.zmq.pylab.backend_inline import InlineBackendConfig
import subprocess as sub # for calling o/s commands like, `pdflatex'
from scipy.interpolate import interp1d
from reference import counter as counter # color cycling.

out, err = sub.PIPE, sub.STDOUT # for bash commands.

# Set the plot defaults to svg:  png is tough to make look good in latex.
cfg = backend_inline.InlineBackendConfig.instance()
cfg.figure_format = 'svg' # 'png' / 'svg'
InlineBackendConfig.instance().figure_format = 'svg'

coms = ['cd %s; ' % docroot]
coms[0] += 'nbconvert2.py latex_base --no-stdout --write=True %s.ipynb' % a # 0
coms.append('cp %s%sNoCode.tex %s%s_files/' % (docroot, a, docroot, a)) # 1
coms.append('for i in %s%s_files/*.pdf; do mv $i ${i%%.pdf}.svg; done' % (docroot, a)) # 2
coms.append('cd %s%s_files; pdflatex --shell-escape %sNoCode.tex' % (docroot, a, a)) # 3
    
# original form discards the output, making for difficult debug:
p = []
p.append(sub.call(['/bin/bash', '-c', coms[0]], stdout=out, stderr=err)) # convert
hideIpythonCells('%s%s' % (docroot, a)) # update
p.append(sub.call(['/bin/bash', '-c', coms[1]], stdout=out, stderr=err)) # copy
p.append(sub.call(['/bin/bash', '-c', coms[2]], stdout=out, stderr=err)) # rename
p.append(sub.call(['/bin/bash', '-c', coms[3]], stdout=out, stderr=err)) # compile



No comments:

Post a Comment