pystitch / stitch

Write reproducible reports in Markdown
https://pystitch.github.io
MIT License
441 stars 20 forks source link

Emit output that is styled like a normal markdown paragraph rather than a CodeBlock #27

Closed michaelnt closed 8 years ago

michaelnt commented 8 years ago

I'd like to template some text but it is styles as a code block.

import math
print ("The value of pi is {pi:1.3f}".format(pi=math.pi))

The following works when outputting to html but gets ignored when outputting to latex.

from IPython import display
import math
t = "The value of pi is {pi:1.3f}".format(pi=math.pi)
display.HTML(t)

How can I get this to display in both html and latex?

TomAugspurger commented 8 years ago

Print messages go through stdout. At the moment, I just wrap those in a CodeBlock, mainly to signify that the text is output from a code chunk.

How can I get this to display in both html and latex?

I thought that display.display(t) would work. The documentation says

By default all representations will be computed and sent to the frontends. Frontends can decide which representation is used and how.

However, I only see text/plain coming through. If that returns representations for text/html and text/pdf I think we would correct intercept and render it.

michaelnt commented 8 years ago

I thought display.Markdown(t) might be a solution that could then be rendered to latex or html by pandoc

michaelnt commented 8 years ago

Thanks, that worked for me (for html and latex).

TomAugspurger commented 8 years ago

Thinking about it more, when display.display says it computes all the representations, that probably means _repr_latex_, _repr_html_, etc. But strings don't define any of those methods, just str.

I'll write a couple tests and merge that tonight. Thanks for trying it out.