Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
bmbroom opened this issue Nov 8, 2011 · 1 comment
Open

Comments

@bmbroom
Copy link

bmbroom commented Nov 8, 2011

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]),
@CJ-Wright
Copy link

I would like this as well. I use Sympy which can output latex strings, and would like them to be rendered via latex in the output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants