Tammo 80

Home / Weblog / Java / Reizen / Taalverhaspelingen

30 January 2009

MathPSfrag en Mathematica 7

Plaatje met MathPSfrag
Ik gebruik voor m’n proefschrift het pakket MathPSfrag om wiskundige labels aan figuren toe te voegen (dit is een Mathematica-variant op PSfrag). In versie 7 van Mathematica werkte dit pakket plotseling niet meer, doordat er een nieuw object Image was geïntroduceerd. Dit heb ik opgelost met het volgende stukje code. Misschien heeft iemand er iets aan.

BoundingBoxFromRaster[gr_Image, extramargin_Integer] :=
  Module[
    {bgcolor = ImageData[gr][[1, 1]],
    wholedim = Reverse[ImageDimensions[gr]]},
      {{countlines[Transpose[ImageData[gr]], bgcolor],
      countlines[Reverse[ImageData[gr]], bgcolor]} – extramargin,
      {wholedim[[2]] –
      countlines[Reverse[Transpose[ImageData[gr]]], bgcolor],
      wholedim[[1]] – countlines[ImageData[gr], bgcolor]} + extramargin
    }
  ]

4 Comments »

  1. Hi
    Coud you please explain some details. I don’t how to use it. I use mathematica7 and MathPsfrag (MathPSfrag-Test.nb) cause to
    following error:
    StringForm::sfq: Unmatched backquote in “\!\(\*StyleBox[\”\\\”`Could not determine bounding box from file \\\”\”, \”MT\”]\)\!\(\*StyleBox[`1`, \”MT\”]\)\!\(\*StyleBox[\”\\\” in directory \\\”\”, “\[Ellipsis] [`2`, “MT”]\). I intentionally did not clean up temporary files, which will have to be removed manually.. >>

    UnPSfrag::bboxfailed: `Could not determine bounding box from file `1` in directory `2`. I intentionally did not clean up temporary files, which will have to be removed manually.

    Best Regards
    Mojtaba Nasiri

    Comment by mojtaba — 8 February 2010 @ 11:22

  2. Great, this works! Did have a nasty copy and paste problem, which turned some of the minuses into characters that confused Mathematica.

    Ad Mojtaba: Replace function BoundingBoxFromRaster in MathPSfrac.nb by this code. Then delete each ‘minus’ character and type it again.

    Comment by Tim — 19 April 2010 @ 17:26

  3. Hi, thanks for this workaround!

    Btw, has anyone managed to get MathPSfrag and Mathematica >= 6 to properly export logscale plots
    when using a closed frame box (Frame->True)?

    I failed badly to accomplish this. Mathematica/MathPSfrag always quits with an error in this case.

    Cheers,
    Timo

    Comment by entropy — 23 July 2010 @ 22:23

  4. Grazie di cuore!!!

    Comment by Roberto — 5 March 2012 @ 21:16

RSS feed for comments on this post. TrackBack URL

Leave a comment