Showing posts with label latex. Show all posts
Showing posts with label latex. Show all posts

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 }\)

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!