Call Windows Support

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Tuesday, 15 October 2013

PythonTeX

Posted on 14:33 by Unknown
I write technical documents in LaTeX, and my programming language of choice is (currently) Python.  I’m about to start writing a large LaTeX document that will have lots of figures drawn with Python’s matplotlib.  So, I was wondering, wouldn’t it be nice if there was some support for including these more directly in the document.  I went surfing, and came across PythonTeX, by Geoffrey M. Poore.

PythonTeX doesn’t just allow you to put figures in your LaTeX, it allows whole chunks of Python, with the results embedded in the output.  After watching a YouTube video on the capabilities, I thought it looked interesting, so I decide to give it a go: it might well be useful, and anyway it’s a great displacement activity from actually starting writing that document.

It wasn’t a particularly onerous installation process, as LaTeX and Python installations go.  In order to get the test document, pythontex_gallery.tex, to format properly, I just had to:
  1. download PythonTeX
  2. run LaTeX on the provided example file pythontex_gallery.tex (I use TeXnicCenter)
  3. give LaTeX permission install several macro packages (as warned by the PythonTeX installation documentation)
  4. from the command line, run pythontex.py pythontex_gallery.tex
  5. scrutinise the error messages to see I needed pygments.style, sympy, and scipy  (again, as warned by the PythonTeX installation documentation)
  6. go to the pygments page, and see that it recommends installation via ez_setup
  7. go to the ez_setup page, and download it
  8. from the command line, run python ez_setup.py
  9. download the relevant pygments “egg”
  10. from the command line, run easy_install Pygments-1.6-py2.7.egg
  11. download and install sympy
  12. download and install scipy (hence discovering that it is pronounced “sigh pie”, not “skippy”)
  13. from the command line, run pythontex.py pythontex_gallery.tex
  14. run LaTeX on pythontex_gallery.tex again
At this point out popped a LaTeX pdf with figures, equations, integrals, and expression derivations all produced from the embedded python!

Now that I have everything installed, all I have to do to generate this pdf from scratch is:
  1. run LaTeX on pythontex_gallery.tex
  2. from the command line, run pythontex.py pythontex_gallery.tex
  3. run LaTeX on pythontex_gallery.tex again
Simples!

There is also a handy utility to convert the LaTeX file with embedded python into a stand-alone LaTeX document, suitable for other people to process.  (This is essential if the document needs to be sent off for publication, for example.)
  1. edit the LaTeX file to include the depythontex=true option in the pythontex package
  2. run LaTeX on pythontex_gallery.tex again
  3. run pythontex.py pythontex_gallery.tex again
  4. run depythontex.py --graphicspath pythontex_gallery.tex final.tex
Then anyone can run LaTeX on final.tex without needing PythonTeX.

Having installed PythonTeX, and checked that it can at least process the supplied test file, I next needed to check that I can get it to produce the kind of diagrams I want.

So I wrote a short LaTeX document with the body:
\begin{pylabcode}
n = 16
m = 6
figure(figsize=(n*0.2, m*0.2))
gca().axison = False
x = 8
y = 4
fill( (x,x+1,x+1,x), (y,y,y+1,y+1), 'r', linewidth=0)
for i in range(0,n+1):
ii = (i,i)
jj = (0,m)
plot(ii,jj,'0.4', linewidth=0.2)
for j in range(0,m+1):
ii = (0,n)
jj = (j,j)
plot(ii,jj,'0.4', linewidth=0.2)
savefig('myplot.pdf', bbox_inches='tight')
\end{pylabcode}

\includegraphics{myplot.pdf}

This is a \pylab{'${0} \\times {1} = {2}$'.format(n, m, n * m)}
square grid, with a red block at $(\pylab{x},\pylab{y})$.

The top bit is some python code to draw a grid and a red square, and the bottom bit is some explanatory LaTeX text.  Going through the LaTeX-PythonTex-LaTeX process gives:
Excellent.  I can use it to draw diagrams in situ.  The great advantage this approach has is that I can keep all my code for the figures in the same file as the LaTeX text, so there will be much less chance for fragments to wander off and get lost.

As shown in the code above, the LaTeX can include references to python variables, which is how the caption part is generated.  Then, if I decide that I want a slightly different figure, I just edit this single file, change only the values assigned to n,m,x,y in the python part, and get something like:

The new variable values have changed the drawn figure, and these changes have also been propagated to the caption, including the calculation of the product.  This gives a much more sophisticated form of cross referencing.

I’m sold!


Read More
Posted in LaTeX, python | No comments

too much tech!

Posted on 04:52 by Unknown
So, there I was, sitting at my computer, waiting for a Google hangout to start (an excellent way to have a meeting, btw – video on one screen, Google doc on another, everyone typing up the notes in the doc – works really well, at least for smallish groups).

My computer’s webcam is throwing a wobbly at the moment, so I had my tablet ready to run the hangout itself.  The hangout organiser sent the invitation.  My computer notified me.  My tablet’s screen lit up, notifying me.  What I hadn’t been expecting was that my phone, sitting next to my tablet, would also suddenly come alive, notifying me!

I’m surrounded by tech, all demanding to talk to me…
Read More
Posted in computer | No comments

Saturday, 12 October 2013

mushrooms gonna mushroom

Posted on 12:22 by Unknown
We've had mushrooms in the garden before, but going out today, the sight was just surreal.



Read More
Posted in food, garden | No comments

Friday, 11 October 2013

sequestering carbon, several books at a time X

Posted on 15:23 by Unknown
Three weeks’ worth of input, partly populated as a result of me reading Mattessich’s 1982 survey of Systems Theory literature (“The Systems Approach: Its Variety of Aspects”), because the author “decided to concentrate mainly on books” in that survey.  Naturally, several of the concentrate appear in this pile.  Some others appear because they were brought to my attention on blogs that I read.


Read More
Posted in books | No comments

Saturday, 5 October 2013

Martin Magnus on Kindle

Posted on 13:30 by Unknown
There are books that we’ve seen, usually read, and want to own, but can’t find available (or sometimes, affordable!) copies.  Then the hunt is on, scouring the second hand lists, lurking, waiting, and, if we are lucky, pouncing.

We each had a classic example of this from our childhood.  Charles was after Martin Magnus on Mars, the third in the series, only ever published in hardback, and tough to find.  So tough that, before the advent of the web, Charles was seriously wondering if he’d just imagined it! However, he eventually spotted a copy for sale, and pounced.

I had a similar story with Annabel and Bryony, a delightful children’s book I read when much younger.  I did at least know it existed, since my sister had a copy.  Eventually, after much hunting, I got my own copy, a present from my sister who had spotted it lurking in a second hand bookshop in Robin Hood's Bay.  And later still, thanks to my review of it on the web, I got a further trilogy.

This evening, Charles announced: “Such a long challenge, rendered insignificant.  Martin Magnus on Mars is on Kindle!”  And so it is.  At least we paid only a couple of quid for the hardback.  And there is something different about a physical copy.

Wait, I thought.  If MMoM is on Kindle, what about A&B?  Sure enough, it too can now be had in non-dead tree format.

The times they are a-changin’.  But I wouldn’t part with my hardback copy, battered dust jacket and all.
Read More
Posted in books, web | No comments

Friday, 4 October 2013

a sky full of shepherd's delight

Posted on 10:50 by Unknown
Great sunset tonight.


Interestingly, this isn’t looking towards the setting sun, but about 90° west of it.

A different part of the sky:


This view is diametrically opposite the setting sun.

No photo of the setting sun itself – in that direction there’s just thick black cloud!
Read More
Posted in weather | No comments

Tuesday, 1 October 2013

mellow fruitfulness

Posted on 02:55 by Unknown
Our apple tree, in the early morning sunlight.


Read More
Posted in garden | No comments
Newer Posts Older Posts Home
Subscribe to: Posts (Atom)

Popular Posts

  • hyperbolic hyperbole
    What's with hyperbolic discounting? It's everywhere ! I first consciously noticed the term at a workshop about six weeks ago, and n...
  • better use seaweed
    As Neils Bohr is alleged to have said , “prediction is very difficult, especially about the future”. My smartphone has a weather app on it t...
  • oh dear
    We have a garden pond to help encourage frogs and other amphibians. Hedgehogs may suffer, however. :-(
  • "Windows support" -- not
    Just had another scam phone call -- someone with a strong Indian accent claiming to be calling from "Windows Technical Support" (o...
  • national stereotypes
    I've just got back from a very productive three day meeting in Paris. Just around the corner from where I was working, there was a marv...
  • retrospective holiday diary day 1: travelling north
    We went to the Lake District last “summer” ; this “summer” it was time for touring the other side of the country: Northumbria. The holiday s...
  • retrospective holiday diary day 5: trains
    Monday 24 September, and the long-threatened rain finally arrived. So this was the ideal day for the planned Carlisle-Settle rail trip . Bu...
  • funfair mirror trees
    One of the trees in our garden has died.  It died last summer in the drought, but we gave it a year to prove to us it really was dead.  It i...
  • retrospective holiday diary day 3: Lindisfarne
    Saturday 22 September, and the weather was still fine, sunny holiday weather so we decided to take advantage of the sunshine, and do Lindisf...
  • more scammers
    So not long after the scam phone call , the phone rings again. It's British Gas -- they get to call me because I'm actually a custo...

Categories

  • 3D printer
  • algorithm
  • astronomy
  • birds
  • Bonnie Tyler
  • books
  • cognition
  • computer
  • conference
  • Doctor Who
  • driving
  • ducks
  • duodecimal
  • education
  • electricity
  • estimation
  • Evernote
  • evolution
  • font
  • food
  • fractals
  • game
  • garden
  • graphics
  • grimoire
  • history
  • holiday
  • humour
  • language
  • LaTeX
  • lego
  • lol
  • mathematics
  • medicine
  • money
  • music
  • obituary
  • pedantry
  • politics
  • probability
  • psychology
  • publishing
  • python
  • quotations
  • research
  • robots
  • science
  • science fiction
  • space flight
  • statistics
  • TPS
  • trains
  • tree
  • TV
  • weather
  • web

Blog Archive

  • ▼  2013 (119)
    • ▼  December (1)
      • that's not in the least bit suspicious
    • ►  November (17)
    • ►  October (12)
    • ►  September (10)
    • ►  August (9)
    • ►  July (8)
    • ►  June (10)
    • ►  May (19)
    • ►  April (10)
    • ►  March (9)
    • ►  February (4)
    • ►  January (10)
  • ►  2012 (103)
    • ►  December (16)
    • ►  November (8)
    • ►  October (14)
    • ►  September (6)
    • ►  August (13)
    • ►  July (8)
    • ►  June (6)
    • ►  May (9)
    • ►  April (10)
    • ►  March (7)
    • ►  February (5)
    • ►  January (1)
  • ►  2011 (79)
    • ►  December (7)
    • ►  November (5)
    • ►  October (10)
    • ►  September (7)
    • ►  August (6)
    • ►  July (5)
    • ►  June (6)
    • ►  May (6)
    • ►  April (9)
    • ►  March (9)
    • ►  February (3)
    • ►  January (6)
Powered by Blogger.

About Me

Unknown
View my complete profile