mkrphys / ipython-tikzmagic

IPython magics for generating figures with TikZ
BSD 3-Clause "New" or "Revised" License
159 stars 43 forks source link

Compile tikz image from python string #3

Open cviebig opened 9 years ago

cviebig commented 9 years ago

Hi,

I very much like your extension! It's great to use IPython for TikZ now too :) Would be it be easy to extend the extension in a way such that I can call it programmatically with a python string that contains TikZ code? This would make it a lot easier to generate TikZ graphics in python and display it immediately :)

mkrphys commented 9 years ago

Dear Christoph,

I am not a 100% sure I understand what you want to do. Do you mean calling TikZ in the IPython notebook pretty much like matplotlib, without having to use a TikZ cell? Or do you want to call it from Python, independent of the IPython notebook, and either display the result in a window or save it to file?

The first version should be possible, but I couldn’t say how much effort that would be as I am not much of an IPython developer. The second version, saving to file, should be straight forward to implement, just by stripping down the necessary functionality from the IPython extension. The second version with interactive display could be implemented by just saving the TikZ output to file and displaying it with some available image viewer module (e.g. png+matplotlib).

I will have a look at extracting the basic functionality into a separate module. That should be doable quickly.

Cheers, Michael

On 19.05.2015, at 21:42, Christoph notifications@github.com wrote:

Hi,

I very much like your extension! It's great to use IPython for TikZ now too :) Would be it be easy to extend the extension in a way such that I can call it programmatically with a python string that contains TikZ code? This would make it a lot easier to generate TikZ graphics in python and display it immediately :)

— Reply to this email directly or view it on GitHub.

cviebig commented 9 years ago

Hey Michael,

yes, I would like to call TikZ in the IPython notebook, i.e. constructing a string with TikZ code in a python notebook cell and would like to see the compiled image in the output of the cell :)

Christoph

mkrphys commented 9 years ago

Hi Christoph,

For that one I cannot offer a quick solution. But I’ll happily accept pull requests :o).

Best, Michael

On 20.05.2015, at 20:52, Christoph notifications@github.com wrote:

Hey Michael,

yes, I would like to call TikZ in the IPython notebook, i.e. constructing a string with TikZ code in a python notebook cell and would like to see the compiled image in the output of the cell :)

Christoph

— Reply to this email directly or view it on GitHub.

cviebig commented 9 years ago

Hi Michael,

thank you for looking into this :) I try to find a way when there's some time left

Christoph

goerz commented 8 years ago

Here's a workaround of doing it in two cells by writing to a file:

The first cell would contains something like

tikz_code = r'\draw (0,0) rectangle (1,1);'
with open('drawing.tikz', 'w') as out_fh:
    out_fh.write(tikz_code)

The second cell would be

%%tikz --scale 2 --size 300,300
\input{drawing.tikz}

This depends on the most recent version of tikzmagic.

cviebig commented 8 years ago

Good idea. It also has the advantage that the pictures are also useable in the original LaTeX document (by including). In the mean time I've switched to Emacs org-mode. which is supporting literal programming with python and LaTeX too.

cmoman commented 8 years ago

Do you think it would be possible to add http://www.texample.net/tikz/examples/circuitikz/ ie, be able to add electrical circuit drawings? tikz -l circuitikz does not quite work. Awesome tool here.

mkrphys commented 7 years ago

@cmoman, sorry for not reacting. I saw your comment just now. I created a separate issue #13. This is a bit more involved than just loading a tikz library, but it shouldn't be too hard to implement.

mkrphys commented 7 years ago

@cmoman, I looked into this again. Loading the package is straight forward via the -p argument. Adding an additional environment, however, is actual work for which I do not have time. You are welcome to submit a pull request, though.