Wednesday, February 20, 2013

Defining Custom Commands in LaTeX


\( \LaTeX \) is a very powerful typesetting system. Its power is greatly augmented by the fact that it allows you to define your own commands. In general, a custom command will be placed in your document's preamble (meaning before \begin{document}) and will follow the form:

\newcommand{\command_name}[number_of_arguments]{command_definition}

If your command has no arguments, then you exclude the [number_of_arguments] section. In the {command_definition} section you refer to passed arguments by using  #n where n is the number of the argument you are passing. To pass down multiple arguments, you simply tack on new curly braces for each one. Here are some examples:

Example 1: Automate left and right parenthesis

 

Definition

 

\newcommand{\p}[1]{\left( #1 \right)}

In Use


\p{ 5.0 \times 10^3 } + \p{ 2.1 \times 10^{18} }

Output

 

\( \left( 5.0 \times 10^3 \right) + \left( 2.1 \times 10^{18} \right)\)



Example 2: Define Kilohms

 

Definition


\newcommand{\ko}{k \Omega}

In Use


R = 50 \ko

Output

 

\( R = 50 k \Omega \)


Example 3: Pythagorean's Hypotenuse

 

Definition


\newcommand{\hyp}[2]{ \sqrt{ #1^2 + #2^2 } }

In Use


\hyp{500}{12}

Output

 

\( \sqrt{ 500^2 + 12^2 }\)

Sunday, February 17, 2013

Write ISO Files to USB from Linux Command Line

Here's a command that I use too often not to post about it:

dd if=my_iso_file.iso of=/dev/sdx

This little gem is pretty straight-forward. It uses dd (properly termed "Disk Destroyer") to write your ISO file, block by block, to your USB drive. Of course you have to replace the "x" in "sdx" to whatever your drive letter is.

To discover your drive letter, as a root user (or using sudo), type:

fdisk -l

Which will list the available, block-type partitions on your system. You should be able to conclude (usually from the size of the device) exactly what your USB drive's mount point is named (this will usually just be "sdb"). Be sure not to overwrite your hard-drive!

Once you have written the ISO file, you should run the following to clean the systems writing buffers:

sync

Saturday, February 9, 2013

Deploying Aspen Projects with Heroku

Aspen is a very cool and intuitive web framework and server for building Python-powered sites. It is one of those genuine, non-MVC, "what you see is what you get" kinda things.

Heroku is a free (for basic usage) web hosting site.

For my school's math club, we needed something simple and free to post a fund-raising app and I decided that putting up an Aspen site on Heroku would be a good idea. Now that the site's up and I have ironed out those gory details, I am very happy with the results. Here are some of those details:

  • To use Heroku and Python in conjunction you need python-virtualenv. So make sure you get it online or run a pip install virtualenv, or a apt-get install python-virtualenv.
  • After you create a site using Heroku, you will have to link up git and login to Heroku (this is described on Heroku's site). Next be sure to start up your Python virtualenv
  • When you're in the virtualenv, run pip install aspen.
  • Next, run pip freeze > requirements.txt, which will tell Heroku what Python dependencies are needed server-side.
  • Alright, this is the tricky part. You now need to create a file called ProcFile in your Heroku project's root directory. This file's contents should be:

         web: aspen -p . -w www -a :$PORT
    That line tells Heroku to make the ProcFile's directory the project's root directory and to run Aspen over whatever port Heroku chooses. You now need to make a directory called "www" which will contain all your code files. Of course, you can call this directory whatever you want, you just need to change the contents of the ProcFile (the above line) to match.
    Given a successful linking of git and Heroku, and that you are logged into Heroku, you can run git push heroku master which sends your Aspen pages to the web, and foreman start which lets you test your app locally.
     

    Friday, February 1, 2013

    Adding MathJax to Blogger

    What is MathJax?

    MathJax is a cool JavaScript program that allows bloggers and other people who edit websites to enter math typesetting text (like \( \LaTeX \)) onto their site. So, if used properly it can make equations and other mathematical formula look cool. Meaning...

    Instead of this:
    E = mc^2

    You get this:
    \[
      E = mc^2
    \]

    Adding MathJax to Blogger

    • Navigate to the main Blogger page for your blog and click on the "Template" tab, as highlighted below:
      

    • Next, click on the "Edit HTML" button below the little thumbnail of your blog:

    • Once the editing window comes up (this should contain raw HTML code), hit Ctrl+F, and then type "</script>" (without the quotations).
    • Now, in the editing window you should see the "</script>" text highlighted. Paste the following line of HTML code directly below the "</script>" tag:
    <script src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML' type='text/javascript'/>
    • Here's what mine looked like after I pasted the code:
      
    •  If your configuration looks right, then save the template. You should now be able to use math formatting languages in your blog, hurray!

    Latest Project: Ultimate Dev. Machine Script

    The latest thing I have been working on is pretty cool. It's simply a Python script called udm.py that you toss onto a virtual machine (Debian based) and run using:

    sudo ./udm.py

    Then, it works its magic and installs compilers, interpreters, IDEs, editors, documentation generators, source control software, and much more! So far, it has been successfully tested on Linux Mint 14.1. Here's a brief view of it:


    As it stands, it is very configurable. You can add and remove packages, and even include special installation instructions all with plug-and-play-like ease. Packages are organized by topic, in simple, struct-like objects I call containers. In the udm_script/desired_packages.py script, entire containers can be added or removed from the installation. In the containers, specific packages can be added or removed. If you know of any interesting development packages that I should add, let me know!

    All code is available on my github account.