Skip to content

Feature request (with patch): recognize latex blocks in output #3

Description

@bmbroom

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

*** 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]),

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions