Showing posts with label OpenSource. Show all posts
Showing posts with label OpenSource. Show all posts

Friday, July 25, 2014

Veusz: Awesome Plotting Software

As a working scientist, I do a lot of data plotting. Most of these plots are for internal consumption, as I try to tease meaning out of data.

I tend to use gnuplot a lot, because I've gotten extremely used to it.

However, every once in a while I have to make a plot for external consumption.

For the longest time, I've relied on Grace for my journal quality plots.

Last week, I discovered Veusz (pronounced "views"). It is a python based program for 2D plots, which feels truly modern.

Grace hasn't been updated in a while, and while it works fine for the most part, from an aesthetic standpoint, it feels like your friend from the eighties, who did not realize that bell-bottoms went out of fashion.

It is multiplatform (runs on Linux, MacOS and Windows), exports to a wide variety of useful formats (EPS, PDF, SVG, TIFF), and is unfettered by some of the legacy issues surrounding Grace (multiple plots) such as:
  • multiple plots/insets are a cinch
  • subscripts/superscripts use latex notation
  • presence of an undo button
  • more concise and readable scripts
  • import from a wide variety of formats
  • ability to link to data files instead of loading them in
It is also possible to write "script" files, and use the program from the command line. All in all, I think this is a program that I will use a lot more in the future. I will post about my experiences after I use it for a while.

Friday, July 26, 2013

Octave/Matlab: Loop through Files in a Directory

Looping through files that match a certain pattern is an easy and routine operation for a BASH shell for example:

One can mimic this feature from within an Octave or Matlab program by using the command "glob". Here's how:


Monday, July 15, 2013

GeoGebra Worksheet

GeoGebra makes building JavaScript or HTML5 applets a piece of cake.

I recently wrote a quick program to dynamically "analyze" the effect of additional monthly prepayments on a loan, on the amortization schedule. The formulae are available on this wikipedia page.

Here is a link to the GeoGebra worksheet on GeoGebraTube. You can download the file, or merely play with it in (either JavaScript or HTML5).


Thursday, June 20, 2013

Exploring GeoGebra

I've known about the existence of GeoGebra for a while now, but this summer I've spent some time taking it out for longer rides. I really like the program - it is very intuitive to use, and there is a lot of help available online.

It does make math (algebra, calculus, geometry) very interactive and fun.

One thing I am very excited about is the ability to export GeoGebra worksheets into dynamic HTML5 webpages with the press of a button. This means you can make all those interactive JavaScript or HTML5 applets *very* easily.

You can already go to GeoGebraTube, and explore many shared worksheets either as Java or HTML5 applets, or download the "ggb" files and open them using GeoGebra installed on your computer.

I could not help but notice that its creator Markus Hohenwarter was at Florida State University (where I work) between 2008–2009. It is unfortunate that I did not get to meet him then.

Monday, January 7, 2013

TeX Directory Structure or Where to Install Packages?

If you are a regular TeX user, there are many good reasons to understand and exploit the TeX directory structure (TDS). Let me offer some:

  • You download a package from CTAN (or somewhere else). This could be a style file, for example. Is there some central place you could put it, so that it is in the "path" (so that you can avoid making multiple copies of the same style file in all your working directories)?
  • You make a bibliography style file to suit a journal's requirements (using custom-bib). Can you put this in the "same" central place?
  • You have a bibliography (bib) file with all your references. Can you put this in the path too? And can you do that without completely cluttering that central place?
  • You have an account that is administered by a university or department, and the TeX installation is common to all users. Can you make sure that the .sty, .bst, .bib files that we talked about above do not get wiped off, when the systems administrator decides to upgrade the TeX installation?

If you use TDS, the answer is yes. The good news is that this works independent of the OS platform.

The first thing is to find out where this place is. You can do that by simply typing the following in a terminal.

kpsewhich -var-value=TEXMFHOME

On my Mac this is ~/Library/texmf, and on my Linux desktop it is ~/texmf.

If such a directory does not already exist, you can create it (mkdir texmf) at the above location. You then make sub-directories. The important ones are:

bibtex directory
   - bst sub-directory (put bst files here)
   - bib sub-directory (put bib files here)
tex directory
   - latex sub-directory (put packages here)
doc directory
     put doc files from packages installed in the tex directory here.

You can make further sub-directories.

For example, you can make a "tools" directory within texmf/tex/latex/tools and put, for example, the tools package files here (tex and sty), and move the corresponding doc files to the texmf/doc folder.

In newer systems you don't even have to run texhash or mktexlsr to "update" the path if you do this.

Monday, December 3, 2012

Howto: Convert EPS from Grace to PDF (for pdfLaTeX perhaps?)

I am a big fan of the 2D plotting program Grace, as attested by some of my previous posts.

It lets you create high-quality graphs, which can be exported to a variety of formats. One conspicuous export format missing from the list is PDF.

Even if you use pdfLaTeX for example, this is only a minor issue - worth a grumble, but probably not a rant, since you know that Linux has a whole slew of methods you can throw at the problem.

Like ps2pdf.

Let's work through an example. Say you have an EPS image (fig.eps) that looks like so:

You say ps2pdf fig.eps and get fig.pdf. You open it up and it looks like, yikes!!!
The bounding box has been obliterated! And no, the -dEPSCrop flag does you no good!

You open up fig.eps in a text editor, and the first two lines you see ("at end") tell you all that is going on.

%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: (atend)

The specs of the actual bounding box are hidden at the way end of the EPS file.

%%BoundingBox: 29 51 716 529

There are two ways to fix this. If this is just a one off file, then you can replace the second line (with the "atend") with the actual line containing the definition of the bounding box. Save the figure (say as fig1.eps) and say:

ps2pdf -dEPSCrop fig1.eps

And all your troubles are gone.

Another method which does the same thing, but may be more useful if you have to do this to 100 files is as follows:

1. Use the ps2eps tool to "convert" the image to EPS (this automatically bring the BoundingBox to the top)

ps2eps fig.eps fig1.eps

Note: This may result in a huge fig1.eps, but if your intention is to get a PDF you can delete fig1.eps soon enough.

2. Use ps2pdf tool

ps2pdf -dEPSCrop fig1.eps

And you get a nice cropped PDF image.


Thursday, November 15, 2012

Exporting Matrices in Octave/Matlab to LaTeX format

I often need to include vectors or matrices computed during GNU Octave sessions in my lectures or presentations. Here is a quick program called matrixTeX.m (stored on Google Drive) that takes in a matrix A and spits out the matrix form in LaTeX.

In the simplest form, matrixTeX(A), it simply takes in a matrix  A, checks whether the elements are integers or floats, and prints out to the screen in the appropriate format using the amsmath matrix environment bmatrix.

If you'd like the elements of the matrix displayed in a particular format, you can optionally use a second input argument to specify a C-style formatting string: e.g: matrixTeX(A, '%10.4e'), or matrixTeX(A, '%d').
In addition, you can also specify a third argument to specify alignment of columns as or matrixTeX(A, '%d','r'), where the 'r'  stands for right alignment. This option uses the bmatrix* environment provided by the mathtools package, which needs to be included in the LaTeX preamble.

Monday, September 17, 2012

How to: Crop PDF Images

If you use Matlab (or some other program) to make a plot and then export the figure to a PDF (for inclusion in a TeX document for example), you will end up with plenty of whitespace around the image as below.

It is easy to find out the "bounding box" using ghostscript as:

gs -sDEVICE=bbox -dNOPAUSE -dBATCH file.pdf

which after a bunch of messages yields something like:

%%BoundingBox: 89 231 491 545
%%HiResBoundingBox: 89.766138 231.192063 490.841915 544.769913

You can use those dimensions, and use the TeX command

\includegraphics[bb = 89 231 491 545 ]{file.pdf}

to trim the image within TeX.

Alternatively, you can also use ghostscript to crop the image itself by using:

gs -sDEVICE=pdfwrite \
   -o trimmedFile.pdf \
   -c "[/CropBox [89 231 491 545] /PAGES pdfmark" \
   -f file.pdf

where the output file trimmedFile.pdf is generated. You then don't have to worry about the bounding box inside the TeX document.

Another route is to use the perl script pdfcrop.

pdfcrop file.pdf

produces the appropriately cropped file file-crop.pdf



Monday, August 13, 2012

TeXcount: Number of words in a LaTeX document

Since TeX is really a markup language, counting the number of words in a document is tricky. Obviously, you don't want to literally count words in tags like \chapter{}, \begin{center}, \cite{reference1, reference2} etc.

You may have macros, which need interpretation.

You may have external files that you are collecting together in a master document by using \input{} etc.

In short, it is not as simple as it seems.

You could try to use front-end programs like kile or TeXShop which will give you a simple total count. My front-end program of choice --- TeXMaker --- does not do it for me.

If your document is very simple, you could try to "detex" the LaTeX tags, and use a simple Linux utility like "wc".

The best solution seems to be TeXcount.

There is a web-interface that lets you paste your TeX document in a web-form.

Alternatively you can download the script. It is essentially a small perl program (400kB download in all, the actual script is about 90kB) called texcount.pl, which you can run quite simply as

perl texcount.pl filename.tex

Here's the form (default) output it spits out


Encoding: ascii
Words in text: 10324
Words in headers: 81
Words in float captions: 219
Number of headers: 30
Number of floats: 5
Number of math inlines: 198
Number of math displayed: 18
Subcounts:
  text+headers+captions (#headers/#floats/#inlines/#displayed)
  14+9+0 (1/0/0/0) _top_
  89+1+0 (1/0/0/0) Section: Introduction
  419+2+44 (1/1/0/0) Subsection: Analytical Rheology
  646+2+38 (2/1/3/0) Subsection: Polymers
  236+3+0 (1/0/0/0) Subsection: Scope and Organization
  35+3+0 (1/0/0/0) Section: Motivation and Background
  355+2+19 (1/0/2/0) Subsection: Linear Polymers
  657+2+24 (1/1/17/1) Subsection: Branched Polymers
  205+3+45 (1/1/0/0) Subsection: Model-driven Analytical Rheology
  97+6+0 (1/0/0/0) Section: Models for Polymer Dynamics and Rheology
  597+2+0 (1/0/2/0) Subsection: Historical Development
  872+5+25 (2/1/8/0) Subsection: The Tube Model
  211+4+0 (1/0/0/0) Subsection: State of the Art
  273+2+0 (1/0/5/0) Subsection: Computational Models
  162+3+0 (1/0/0/0) Section: Methods and Progress
  1774+5+0 (3/0/108/15) Subsection: Linear Polymers
  2955+24+24 (9/0/51/2) Subsection: Branched Polymers
  727+3+0 (1/0/2/0) Section: Summary and Perspective


You can exercise significant control over the way it parses the document and reports the results by using options that are described in the manual.

Monday, August 6, 2012

Don't use gnuplot "fit" blindly!

Gnuplot is a great plotting/data-analysis program. It has a fairly robust tool called "fit" which can be used to perform nonlinear least-squares regressions very conveniently.

It does what it advertizes, and infact, does it quite well.

But let us consider a simple cautionary example.

Consider a linear model \(Y = P_1 + P_2 X\), with \(P_1\) = 2, and \(P_2\) = 1.5. Let us generate data using this model, and add some white noise to it. In particular we assume that \(Y_e = N(Y,\sigma=0.5)\) is the experimental data which is normally distributed about the linear model with a standard deviation of 0.5.

The red line is the model, the error-bars denote the standard deviation of the Gaussian noise, and the circles represent a particular realization of experimental data.
We can generate experimental data using the prescribed model and noise profile. This is shown in the figure above.

If we use gnuplot "fit" to fit through the data-points above we get:


Final set of parameters Asymptotic Standard Error
======================= ==========================
P1 = 1.98866 +/- 0.1156 (5.812%)
P2 = 1.4667 +/- 0.03817 (2.603%)

This looks quite good. Even the parameter estimates look quite sharp.

In a way, this is expected because "fit" assumes that the error in \(Y\) is distributed normally (which in this case it is!).

Now let us convert this idealized problem, which we grok completely, into something slightly more complicated.

Let us apply a nonlinear transformation on all the participating variables. Thus, we define \(x = \exp(X)\) and \(y=\exp(Y)\). A replotting of this transformed problem looks like:
This picture is the same as the first figure with the exponential transformation applied. The location of the circles and the red line is the same, except that they are transformed. The location of the bottom and top tips of the error bars are also the same, except that they too are transformed. In short, if I plotted this figure on a log-log plot, it would "look" identical to the first figure.

However notice two important differences. One, the size of the error bars is not the same. It covaries with the magnitude of \(y\). Two, the error bars are not even symmetrical. In fact, it can be shown that if the variable \(Y \sim N(\mu,\sigma)\), then \(y = \exp(Y) \sim \text{lgN}(\mu,\sigma)\), where \(\text{lgN}\) refers to the log-normal distribution.

Let us throw this non-linear problem at gnuplot. Clearly, we don't expect things to go as smoothly as before, because the distribution of the error violates the Gaussian assumption in gnuplot's "fit".



Final set of parameters Asymptotic Standard Error

======================= ==========================
p1 = 4.68963 +/- 0.7653 (16.32%)
p2 = 1.63074 +/- 0.03327 (2.04%)


Note that not only are the parameter values wrong (\(p_1 = \exp(P_1)\) should be 7.39 and not 4.69, and \(p_2 = P_2\) should be 1.5 not 1.63), but the error bars are quite meaningless.

It is particularly important to realize that this is *bad* even though the "fit" visually looks better than the actual model!

But lift the veil by replotting the figure above on a log-log scale, and you can guess what exactly is going on!


Tuesday, June 5, 2012

TeXmaker: Setting up user tags

Texmaker is a really nice LaTeX editor, and has become my default choice. It has many things to recommend itself, including the fact that it is platform independent, has auto-complete (commands, references, and citations), is easy to configure and use etc.

A particular feature that I have grown to depend on is command shortcuts. Texmaker allows the user to define keyboard shortcuts to commands and environments, by going to User > User Tags > Edit User Tags.

Simple commands are quite easy. For example, if you find yourself using the command "\pause" (in beamer presentations) very frequently, you can go to User > User Tags > Edit User Tags, pick a function key (1-10 - say "1"), enter "\pause" in the LaTeX content box. Pressing Shift+F1, automatically inserts \pause at the cursor.

Let us say you have a lot of vectors in your equations, and you like to bold-face your vectors with \mathbf{}. You can create a shortcut to this by saying "\mathbf{@}" in the LaTeX content box. When you press Shift+FX (X=1-10, as appropriate), you get the \mathbf{} tag, and your cursor lies between the curly braces. You can also select some text and press Shift+FX and the \mathbf{} tag does what you would like/expect it to to.

You can also define shortcuts to environments. Say you use the "\begin{frame} \end{frame}" environment a lot. All you do is say "%frame" in the LaTeX content box.

Friday, June 1, 2012

Grace Tutorial: How to plot a graph with two different y-axes?

Say you have a dataset that looks like

x1, y1, Y2
x2, y2, Y2
...
xn, yn, Yn

and you want to plot (x,y) and (x,Y) with the same x-axis but different y-axes. As an example, consider the following graph (bigger versions of graphs upon clicking) where (x,y) are on a linear scale, and (x,Y) are on a logarithmic scale.


How do you make such a picture in Grace?

The strategy is very similar to making inset plots, which I wrote about a while ago. In fact, we could use essentially the same method, where the "inset" is the size of the main graph.

But we can do slightly better (and not have to deal with manually cleaning up extra tics) by using the "overlay" feature.

1. Read in the (x,y) dataset into the default graph G0 using Data -> Import -> ASCII dialog box.
2. In the same dialog box (Grace:Read Sets), right click on the "G0" graph, and choose "Create new" and create a new graph "G1"


3. Read in the other dataset (x,Y) into this graph. At this point, the graph looks somewhat garbled as seen below.


4. Click the Edit -> Overlay graphs to open up the overlay dialog box which looks like the following picture. I chose to overlay G1 on G0, and use a common x-axis. You can make different choices.


5. Once you do that, you essentially get what you need. You can go ahead and edit the appearance of the axes and sets. Since the graphs are on top of each other, it is sometimes hard to figure out which graph you are changing. Remember that clicking on the screen lets you toggle through the graphs. If you have widely varying y-axis (as in this example) you can figure out which one is active by looking at the co-ordinate marker right below main menu on the top left side.

6. Alternatively, you can open the Plot -> Graph appearance dialog box and changes the co-ordinates of the viewport so that the two graphs are non-overlapping. It makes clicking easier. You will have to repeat step 4, and undo changes to the viewport, once you've modified the graphs to your satisfaction.







Wednesday, May 2, 2012

User-defined Colors in Grace

Last week, I was working on a manuscript with a collaborators. As we approached the final draft, we decided to make the "colors" in our figures consistent. Unfortunately, we used different programs to make our graphs, and "red" in program X is not the same shade of "red" in program Y.

Grace (the program I use) offers a choice of 16 standard colors, from the usual pull down menu.

However, it allows for endless fine-tuning.

Once you save your graph (as graph.agr), open it up in a text editor. The color-definitions are clustered in lines that look like:
@map color 0 to (255, 255, 255), "white"
@map color 1 to (0, 0, 0), "black"
@map color 2 to (255, 0, 0), "red"
Let us say, we were not happy with the shade of grey available (it does seem a little too light). Look for the line:
@map color 7 to (220, 220, 220), "grey"
and change it to something like:
@map color 7 to (100, 100, 100), "grey"
You can tweak all the other color definitions to suit your taste or requirements.

Wednesday, April 4, 2012

Nested Subfunctions in Matlab and Octave

In a previous post, I mentioned subfunctions in Octave and Matlab.

Nested functions are an interesting new beast. I can see situations where they can be useful as explained in this short video, and this longer, more detailed blog.

They are currently not featured in GNU Octave. Here's their reasoning:
There was discussion in Octave of having these even prior to Matlab, and the decision was made not to have these in Octave at the time for compatibility.
Now that Matlab has recently introduced nested functions, Octave will probably have them soon as well. Until then nested functions in Octave are treated as sub-functions with the same scoping rules as sub-function.

The authors of Octave consider the nested function scoping rules of Matlab to be more problems than they are worth as they introduce diffiult to find bugs as inadvertantly modifying a variable in a nested function that is also used in the parent is particularly easy.

Friday, March 23, 2012

TexMaths: A LaTeX plugin for Open/LibreOffice

I have been a big fan of an OpenOffice extension called OOoLaTeX - which lets you typeset equations in OpenOffice Writer and Impress (the word-processing and presentation software, respectively).
I love it because equations look beautiful, and I can cut-paste from my LaTeX manuscripts (and wikipedia sources for lectures).
Getting fonts to work, does require some gymnastics - but is not a deal-breaker. The trouble with OOoLaTeX however is that it is no longer actively maintained (the last updates date back to late 2007), and getting it to work with newer releases has started to get increasingly painful. In fact, late last year, I reluctantly gave the LaTeX presentation class "beamer" a shot, and actually found it very usable.

I found out last week that there is a new LaTeX plugin for LibreOffice (version >= 3.3) called TeXMaths
TexMaths is a LaTeX equation editor for LibreOffice. It is derived from OOoLatex, originally developed by Geoffroy Piroux (see here). 
As its predecessor, TexMaths is a LibreOffice extension that allows you to enter and edit LaTeX equations directly into LibreOffice documents. All you need is a working LaTeX installation, at least one of the two programs dvipng or dvisvgm and of course the TexMaths LibreOffice extension.
It looks like what OOoLaTeX should have looked like by now, if it were maintained. The primary advantage of TexMaths over OOoLaTeX is that equations are rendered either in png or svg (instead of emf). This simplifies the installation process a great deal, because you don't have to wrestle with the issue of getting fonts right.

SVG is scalable (so you can resize the equation without screwing it up), and you can drag and drop it into other programs (Inkscape has its own native LaTeX support).

The whole episode points to the both the pitfalls and strength of open source software. One can get accustomed to programs (especially those with single authors) that subsequently become obsolete, because the principal coder has moved on to better things. However, if the program fills an important demand, often, someone else steps up, and builds and improves the older program.


Tuesday, March 13, 2012

Subfunctions in Octave/Matlab

Consider the contents of the following Matlab program "mainFunction.m".

%
% A function that integrates the function
% given by the routine subFunction(x)
% over the range a and b
%

function I = mainFunction(a,b)
   a = -5;
   b = 5;
   I = quad('subFunction', a, b)
%  keyboard  % uncomment if needed
endfunction
 
%
% some nontrivial function
%

function y=subFunction(x)
   if( x > 0)
      y = x^2;
   else
      y = x;
   endif
endfunction

The function to be integrated, subFunction(x), can be saved as a separate file called subFunction.m, or, as in this case, it can be included in the same file as the main function. There are advantages to both these techniques.

If I store functions in their own individual files, I can call them from any other function. However, I can very easily end up with a lot of files. This may not necessarily be a bad thing, but it can be a challenge beyond a point.

If I use the subfunctions (as above), then the subfunctions themselves remain invisible outside the file in which they are contained. They may be accessed by the main function and other subfunctions within the same file.

Unfortunately, you cannot use "subfunctions" with script files. A useful workaround is to wrap a function declaration around your script, and use the command keyboard (as shown in the commented line in the example above) to transfer control out.

From here you can examine all the variables local to the "script".

When you are done, say dbquit, or return.

Friday, February 10, 2012

EPS figures: Embedding Fonts

Many journal publishers, including AIP, now demand EPS figures with fonts embedded. If you have Adobe Acrobat, then this is a trivial issue.

But Acrobat is not free.

[Side Note: Most of my figures for journal articles come from two programs: Inkscape for schematics, and Grace for plots. Inkscape supports embedding fonts in EPS directly. Grace currently does not (v5.1), but will do so in the near future (apparently v5.99 already has it).]

But here let us assume you have a generic EPS file which does not have fonts embedded. The process described here (which seemed to satisfy AIP) involves converting the EPS to a PDF, embedding fonts, and then converting back again.

But first, how would you find out whether your fonts are embedded? There are at least two ways. But first you need to convert the EPS to a PDF.

epstopdf unembed.eps [creates unembed.pdf]

Once you have a PDF you can:

(i) pdffonts unembed.pdf: On the particular file I am working on I get:

name           type         emb sub uni object ID
-------------- ------------ --- --- --- ---------
Times-Roman    Type 1       no  no  no       8  0
Symbol         Type 1       no  no  no       9  0
Times-Bold     Type 1       no  no  no      10  0


The key thing to note is the "no no no" under the "emb"(edded) field.

(ii) or, you can open the PDF in Adobe Reader. If you look at File -> Properties -> Fonts tab (in Adobe Reader 9 running on Linux), you will see something that looks like:
The key is you don't see the word "embedded" anywhere.

The next step is to embed the fonts in the PDF using some ghostscript black magic. You say (change only the filenames in red):

gs -dSAFER -dNOPLATFONTS -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sPAPERSIZE=letter -dCompatibilityLevel=1.4 -dPDFSETTINGS=/printer -dCompatibilityLevel=1.4 -dMaxSubsetPct=100 -dSubsetFonts=true -dEmbedAllFonts=true -sOutputFile=embed.pdf -f unembed.pdf

Now you check whether fonts have been embedded in "embed.pdf".

pdffonts embed.pdf
 
name               type         emb sub uni object ID
------------------ ------------ --- --- --- ---------
KKRTRL+Times-Roman Type 1C      yes yes no       9  0
VMUCKG+Symbol      Type 1C      yes yes no      11  0
CNFCZN+Times-Bold  Type 1C      yes yes no      13  0


As you can see fonts have been "emb"edded. Or you can check it in Adobe Reader.


Finally, we convert the PDF back to EPS with:

pdftops -eps embed.pdf embed.eps

One caveat: As decribed here, you could have trouble (the ghostscript step may complain with some warnings, for example) embedding the font if your system doesn't have a mapping for it.
This usually happens with fonts like Helvetica, Times, and Symbol; these are proprietary font names, so their mappings aren’t found in most open source systems. But you can fix this problem, as described in this excellent font reference, by replacing the font names with their open-source equivalents:

Replace proprietary font names with their open-source equivalents. Since .eps is a text format, you can just open the .eps file in a text editor and search/replace the font names. Markus Neteler makes this even easier with a handy bit of sed:

cat b4unembed.eps | sed 's+Times-Bold+NimbusSanL-Bold+g' |\
sed 's+Times-Roman+NimbusSanL-Regu+g' |\
sed 's+Times+NimbusSanL-Regu+g' |\
sed 's+Helvetica-BoldOblique+NimbusSanL-BoldItal+g' |\
sed 's+Helvetica-Oblique+NimbusSanL-ReguItal+g' |\
sed 's+Helvetica-Bold+NimbusSanL-Bold+g' |\
sed 's+Helvetica-Bold-iso+NimbusSanL-Bold+g' |\
sed 's+Helvetica+NimbusSanL-Regu+g' |\
sed 's+Helvetica-iso+NimbusSanL-Regu+g' |\
sed 's+Symbol+StandardSymL+g' > unembed.eps

Wednesday, February 8, 2012

Layers in Inkscape

A very handy tutorial on how (and why) you should use layers in Inkscape.


Personally, I find layers handy in three situations:
  • when there are too many objects in the illustration, I find myself inadvertently clicking on the wrong ones. Controlling layers can make some objects unclickable, while still being viewable.
  • when I want to experiment with an illustration without messing up the original. Sure, I could save a copy, and work on a new copy, but layers provide a more natural solution.
  • when I am making multiple schematics that share most of the illustration. Of course, I could save each incremental difference as a new drawing, but again - layers allow me to do that in a more economical fashion. Also if I decide to make some changes to the "shared part" of the illustration, I don't have to go about changing it in a dozen different files.

Friday, December 2, 2011

Text in Inkscape

Inkscape is a fantastic program for creating vector graphics. It is free, platform independent, refreshingly clean and efficient once your master some keystroke shortcuts, and amazingly powerful in terms of the things it can do for you.

It does have a few pesky features though, particularly with "text". For example there is no intrinsic way of creating subscripts or superscripts, and sometimes Greek symbols just do not render properly.

This post explains my workarounds.

1. Subscripts and Superscripts: While there is no natural way of getting these, you can always select some text, and then press Alt + arrow-key (up, down, left, or right arrows) to move the selection in that particular direction. Here is a screenshot of how that works.


2. Greek Symbols: You can try to select the Symbol font from the font dialog box, but very often, it won't get you anywhere. A handy but inconvenient workaround is to use Unicode. If you know the Unicode Standard (pdf), then you can directly enter the code of the particular character. For example, the symbol for "beta" is 03B2.
To enter this in Inkscape, first open a text dialog box as usual. Then press Ctrl + U. The status bar at the bottom of the screen prompts you to enter the code. You type 03B2 (or 03b2), and you will see it echoes the symbol "beta". You press enter, and the symbol is inserted near the text cursor.

3. LaTeX Support: Inkscape supports LaTeX expressions by default. I did not know this until recently, but you can go to Extensions > Render > LaTeX formula... (in some cases it may be under Effects > instead of Extensions >).

It opens up a dialog box, in which you can enter your formula. Inkscape calls LaTeX and con­verts the DVI out­put to SVG, and em­beds it in the document. Since it is a scalable equation (or any other LaTeX object), you can now interact with it natively in Inkscape.


Wednesday, November 2, 2011

Two GNU Octave Tips

1. Changing directories 

The standard command looks very much like the *nix "cd".

cd NameOfDirectory;

But if "NameOfDirectory" was stored in a variable (DirName  = "NameOfDirectory";), then trying something like,

cd DirName;

would fail because Octave would try to literally look for a directory named DirName. In *nix command lines one would circumvent this issue by "cd $DirName", but this does not work in Octave.

The solution is to use parenthesis. So the following does the trick:

cd (DirName);

2. Quotes: One can use the system command to issue instructions to the shell from within a Octave program. So to list the files in the present working directory one would say:

system('ls');

However, if one wanted to use a Unix program or utility that itself uses quotes, then there are problems in parsing. So something like,

system('awk '{print $0}' infile > outfile')

would not work. The solution is again quite simple. Use double quotes which cause the argument within the double quotes to be interpreted. Hence,

system("awk '{print $0}' infile > outfile")

does what one would expect it to do.