Difference: UsefulScripts (32 vs. 33)

Revision 332010-04-01 - BradAtcheson

Line: 1 to 1
 
META TOPICPARENT name="PsmSpace"

Useful Stuff

Line: 86 to 86
 

Matlab

Added:
>
>
When using mcc to compile standalone applications, you may have trouble running them if a different version of Java is being used. It seems as if Matlab uses the JRE in $JAVA_HOME when it compiles code, but then produces a script that sets paths so that it looks in {matlabroot} for a Java runtime. As of 21 April 2009, these are different versions. The workaround is to edit the run_progname.sh script that mcc outputs, and change the MCRJRE variable to point to $JAVA_HOME/lib/{amd64|i386}. For 32bit this would be/usr/lib/jvm/jre/lib/i386 and for 64bit it would be /usr/lib64/jvm/jre/lib/amd64

Producing publication-quality figures

Old information:

 Export a figure to eps file. The 'save' option on the file menu of the figure window tends to behave erratically, especially if exporting very large size. To export figures for publication, use these scripts instead. Or use the laprint script for better LaTeX documents (using psfrag).
Changed:
<
<
When using mcc to compile standalone applications, you may have trouble running them if a different version of Java is being used. It seems as if Matlab uses the JRE in $JAVA_HOME when it compiles code, but then produces a script that sets paths so that it looks in {matlabroot} for a Java runtime. As of 21 April 2009, these are different versions. The workaround is to edit the run_progname.sh script that mcc outputs, and change the MCRJRE variable to point to $JAVA_HOME/lib/{amd64|i386}. For 32bit this would be/usr/lib/jvm/jre/lib/i386 and for 64bit it would be /usr/lib64/jvm/jre/lib/amd64
>
>
New information:

So far I've only found one to produce decent-quality matlab figures for use with pdflatex. To get axes and figure labels to use latex fonts, you need to use psfrag, which is only available through latex/dvi2ps/ps2pdf. But if you want to use pdflatex then the psfrag package is unavailable. A solution is to compile a separate pdf file using the latex...ps2pdf and then insert that into the pdflatex project. The following makefile code could be used to do this transformation. It takes a sample.m file and produces a sample.pdf image (with as-tight-as-possible cropping) that can be included in your tex file.

%.pdf: %.m
   # default size here is 12cm wide but that can be overridden by a comment
   # in the m file of the form: "% FigureWidth 20"
   # this ridiculously convoluted sequence of latex programs appears to be the
   # only way to get the bounding boxes correct. pdfcrop and epstool sometimes make
   # serious errors when given the output of latex|dvips|ps2pdf, so we have
   # to use ps2epsi.
   echo "set(0,'defaulttextinterpreter','none');" >$*_0.m
   cat $< >>$*_0.m
   echo -n "laprint(gcf,'$*','asonscreen','on','width'," >>$*_0.m
   echo -n $(shell grep FigureWidth $< | sed 's/.*[^0-9]\([0-9][0-9]*\).*/\1/') >>$*_0.m
   echo ",'keepfontprops','on');" >>$*_0.m
   matlab -nodesktop -nosplash -r "$*_0; exit;"
   echo "\documentclass{minimal}" >$*.0.tex
   echo "\usepackage{graphicx,color,psfrag}" >>$*.0.tex
   echo "\pagestyle{empty}" >>$*.0.tex
   echo "\begin{document}" >>$*.0.tex
   echo "\input{$*.tex}" >>$*.0.tex
   echo "\end{document}" >>$*.0.tex
   latex $*.0.tex
   dvips $*.0.dvi
   ps2epsi $*.0.ps
   ps2pdf -dEPSCrop $*.0.epsi
   mv $*.0.epsi.pdf $@
   rm $*_0.m $*.{0.aux,0.log,0.pfg,0.tex,0.dvi,0.epsi,0.ps,tex,eps}
 

SSH without typing in passwords

Line: 149 to 185
  You can generate a rasterised version of arbitrary LaTeX code with this script: https://www.cs.ubc.ca/wiki/core/pub/Imager/UsefulScripts/tex2png
Added:
>
>

Converting xfig, inkscape and gnuplot figures

Here is makefile code to convert .fig, .gpl and .svg files to .pdf for inclusion in latex documents with pdflatex Note that when converting xfig files, the ONLY formats that correctly support latex strings are the various combined ps/pdf/latex formats and metapost (mp). The former will require that you use psfrag/latex/ps2pdf or that you compile a separate pdf file like in the gnuplot case. It's just simpler to use metapost.

%.pdf: %.fig
   fig2dev -L mp $< >$*.mp
   mptopdf --rawmp --latex $*.mp
   mv $*-0.pdf $@
   rm $*.{log,mp,mpx,0}

%.pdf: %.svg
   inkscape -f $< --export-pdf=$@

%.pdf: %.gpl
   echo "set terminal epslatex colour" >$*.0.gpl
   echo "set output \"$*.tex\"" >>$*.0.gpl
   cat $< >>$*.0.gpl
   gnuplot $*.0.gpl
   epstopdf $*.eps
   echo "\documentclass{minimal}" >$*.0.tex
   echo "\usepackage{amsmath,graphicx,color}" >>$*.0.tex
   echo "\pagestyle{empty}" >>$*.0.tex
   echo "\begin{document}" >>$*.0.tex
   echo "\input{$*.tex}" >>$*.0.tex
   echo "\end{document}" >>$*.0.tex
   pdflatex $*.0.tex
   pdfcrop $*.0.pdf
   mv $*.0-crop.pdf $@
   rm $*.{0.gpl,0.aux,0.log,0.pdf,0.tex,eps,tex}
 

EPS files

If the bounding boxes on EPS figures you export are too large, you can manually correct them. Load the eps file in gv and position the mouse curson at the bottom left (lx,ly) corner, and then the top right (rx,ry) corner. The coordinates will be displayed in the box at the top left of the window. Open the file in a text editor and find the %%BoundingBox line. Change the 4 values after it to read lx ly rx ry. The first two are xy coords of lower left corner, next pair is coords of upper right. 0,0 is bottom left of page. For more info, see online.redwoods.cc.ca.us/instruct/darnold/staffdev/Tips/tip10.pdf

Added:
>
>
Alternatively convert to pdf and use the pdfcrop perl script (it's floating around on the web somewhere). Sometimes it makes mistakes and crops off too much. I suspect the problem lies with the source eps file in those cases, and can be fixed by using ps2epsi instead of ps2eps. The epsi files contain binary rather than human-readable data and are larger, but pdf files generated from them are the same as those produced from eps files.
 

Profiling Applications

Line: 231 to 302
 The photocopier code is 8541. There is no password. This is the code for Imager, and it should work on all dept copiers. 1831 is for copying for courses.
Deleted:
<
<

How to print test patterns

Printers are WYSIMDNWYG devices (What You Send Is Most Definitely Not What You Get). Following these instructions might help you get slightly more accurate output for calibration patterns:

  • Use print-to-file from Gimp
  • Select letter paper, and click "original size" button
  • Open the output ps file in a text editor and change "interpolation" to "false"
Printer "points" are 1/72 inch, so you can get 612x792 points on a letter page (actually a little less due to borders). The printer uses dithering, but is unable to accurately generate every shade of grey in such a small block. 2x2 point "pixels" look better, so you can take a 300x390 pixel image, resize to 600x780 using nearest neighbour sampling, print it, and get reasonably accurate results.
 
META FILEATTACHMENT attr="h" comment="" date="1175212968" name="exportfig.m" path="exportfig.m" size="15495" user="atcheson" version="1.1"
META FILEATTACHMENT attr="" comment="Rasterise LaTeX formulae" date="1226129133" name="tex2png" path="tex2png" size="2967" user="atcheson" version="1.1"
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2025 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback