joblib/pyreport — Issue #3: Feature request (with patch): recognize latex blocks in output
Author: bmbroom
Created: 2011-11-08 00:34:37+00:00
State: open

Hi Gael,

I often generate lots of output inside inner loops, and I would like to be able to format that nicely. The following patch recognizes blocks wrapped in \begin{latex} \end{latex} brackets in output chunks and passes that directly into the latex output. I've used it successfully for adding section headings, include TOC entries, and generated latex tables etc into the output.

Please consider this (or something like it) for a future version of pyreport.

Regards,
Bradley

```diff
*** pyreport-0.3.4c/pyreport/main.py	Sat Nov 14 08:49:10 2009
--- pyreport/main.py	Sun Nov 6 15:04:12 2011
***************
*** 668,674 ****
elif block[0] == "textBlock":
rst_text = self.textBlocktpl % (self.add_indent(block[1]))
elif block[0] == "outputBlock":
! rst_text = self.outputBlocktpl % ((block[1]).replace("\n","\n "))
for figure_name in block[2]:
rst_text = re.sub("Here goes figure " + re.escape(figure_name),
self.figuretpl % (os.path.splitext(figure_name)[0]),
--- 668,685 ----
elif block[0] == "textBlock":
rst_text = self.textBlocktpl % (self.add_indent(block[1]))
elif block[0] == "outputBlock":
! rst_text = ""
! startescape = "\\begin{latex}"
! endescape = "\\end{latex}"
! while startescape in block[1]:
! start = block[1].index(startescape)
! end = block[1].index(endescape)
! if start > 0:
! rst_text += self.outputBlocktpl % ((block[1][0:start]).replace("\n","\n "))
! rst_text += self.latexBlocktpl % (self.add_indent(block[1][(start+len(startescape)):end]))
! block[1] = block[1][(end+len(endescape)):]
! if len(block[1]) > 0:
! rst_text += self.outputBlocktpl % ((block[1]).replace("\n","\n "))
for figure_name in block[2]:
rst_text = re.sub("Here goes figure " + re.escape(figure_name),
self.figuretpl % (os.path.splitext(figure_name)[0]),
```