Tuesday, January 29, 2013

Sublime Snippet: LaTex template

Instruction

a very useful Sublime Text snippet to save your time inputing latex templates.

<snippet>
    <content><![CDATA[

\documentclass[]{article}
\usepackage[letterpaper, margin = ${1:1}.in]{geometry}
\begin{document}
\title{${2:Title}}
\author{${3:YourName}}
\date{Today}
\maketitle

${4:Content}

\end{document}
]]></content>
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    <!-- <tabTrigger>hello</tabTrigger> -->
    <!-- Optional: Set a scope to limit where the snippet will trigger -->
    <!-- <scope>source.python</scope> -->
</snippet>

Instruction

Open sublime text 2. Tool -> New Snippet . Copy and paste the above codes, save it in the recommended path when you press Command + S , remember to add the suffix ".sublime-snippet"

I personally recommend : latex.sublime_snippet

To use it

In any new document, Command + Shift + P , type in : latex ( or any other name you saved your snippet file), and press tab.

Keep pressing tab to see magics.

On modifying

Feel free to modify the above code, for example add packages you use very often, for the very magical placeholder like, the format is

${#:Predefined value}

where # is the number of the placeholder, Predefined value is any string you would probably use.

Say I don't always use \Today, I prefer manually enter it, I change the corresponding line to this following one:

\date{${4:Today}}

And I will make the original "Content" placeholder into # 5, which is: #{5:Content} rather than 4.

Special Thanks to Web-design-Weekly

Tuesday, January 1, 2013

Installing Python and its friends on Mac

1 Installing Homebrew, Python, and PIP

1 Installing Homebrew, Python, and PIP

Both Homebrew and PIP are package managers available on Mac.

  • Homebrew makes plenty of softwares and packages more accessible.
  • PIP makes packages/modules for Python easier to manage.

1 Homebrew

Paste this into the terminal:

sudo ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"

And set the path so the Homebrew knows where to put your stuff:

export PATH=/usr/local/bin:/usr/local/share/python:$PATH

Normally you will find your scripts and packages installed under:

/usr/local/share/python/

2 Python

This is a one liner:

brew install python

3 PIP

We will install PIP using Homebrew:

easy_install pip

2 Installing NumPY, SciPY

1 NumPY

sudo pip install numpy

2 SciPY

brew install gfortran
sudo pip install scipy

3 Running Python

Start the IDLE that came with the installation of Python, and try these following lines:

import numpy
import scipy

Try to build it. It should work.

The references to these two very useful modules are easily accessible by one or two google search. I don't want to bother you guys with functions detail. Try this:

help(numpy)

3 Make a cosy room for Py

The original IDLE isn't great enough for running Python, I personally recommend you to use Sublime Text. It's just simply awesome.

Remember to select the build system to be Python or Automatic (which selects the correct one based on the extension of the filename).

Happy coding with Python!

BTW, happy new year!