# Wag the PhDog

## October 23, 2008

Filed under: Uncategorized — phbenito @ 10:59 pm
Tags: , , , , , ,

Pascual Benito, Oct., 2008

phbenito[at]gmail[dot]com

# Example of Text with Equations

The quadratic formula is a second order polynomial equation in one variable, its general form is
where x is the variable and a, b, and c are constants, and a0.Since a quadratic equation is a second degree polynomial equation, then the fundamental theorem of algebra states that two complex roots exist, counting multiplicity.

There are various analytical methods used for finding the roots of quadratic equations, one of the most common methods is the so-called quadratic formula and is derived by completing the square on the general expression shown above. The quadratic formula may be written thus,

# Instructions

I use one of the following online LaTex Equation Editors (open in another browser window) to compose the equation and also to turn the LaTex code into an image (see screen capture image below):

http://thornahawk.unitedti.org/equationeditor/equationeditor.php

http://www.codecogs.com/components/equationeditor/equationeditor.php

They are useful tools for composing equations and the appropriate LaTeX code, even if you are not familiar with LaTeX.

There are slightly different instruction for inserting your equation depending on the Internet Browser you are using:

## Firefox

After creating the equation in the editor, hit “Render Expression”, then place the mouse over the image of the equation, right-click and choose “Copy Image Location”. Then in Google Docs, choose “Insert Picture”, and select the “From the web (URL)” radio button. Paste the image URL and click OK. This will insert the image into the document.

## Internet Explorer (verified with IE7)

After creating the equation in the editor, hit “Render Expression”, then place the mouse over the image of the equation, right-click and choose “Copy”. Then in Google Docs, choose “Paste”, and this will insert the image into the document.

## Editing an Existing Equation?

If you need to edit the equation again later, you will need to go back to the external Equation Editor to do that. There is no easy work around for this right now. So what I do is “save” the equation by pasting it into a “Footnote” in Google Docs, then I can always paste it back into the editor and fix anything, and repeat the image insert process above.

Figure 1: Screen capture of the equation editor open, and pasting in the equation image URL into the Google Docs “InsertPicture” dialog box.

Figure 2. Here is a screen capture of this document as viewed while being edited.

Note that a similar approach for inserting equations can be used in Google Spreadsheets or Google Presentation.

# Advanced technique: composing the equation right in the document html

If you’re comfortable playing with the html of the file and with the latex codes, you can actually insert the equation LaTeX code or image link directly into the document’s html (choose “Edit→HTML”), as shown with the html snippet below (the equation itself has been highlighted in red):

<img src=”http://www.codecogs.com/gif.latex?x=frac{beta}{y}” alt=”x=frac{beta}{y}”/>

then you can actually have the equation embedded in the source, and can update the equation image just by editing the latex code there (so if you were to look at the html for this document you would see the embedded equation html and LaTeX codes) that create the following equation:



# Arrays & Matrices

Arrays, vectors, matrices, etc… can either be generated using the LaTeX equation editor methods described above, or you can also use nested table inserts to represent arrays as follows:

First shown with the cell borders in green so you can see the underlying table structure (note I set the table width to “fit to content”)

A =
 a11 a12 a13 a21 a22 a23 a31 a32 a33

and then without the table borders as it might be displayed:

A =
 a11 a12 a13 a21 a22 a23 a31 a32 a33

# Inserting Greek Letters and other Mathematical Symbols into the text

The Symbol font is not currently available in Google Docs, but you can get around this in a couple of ways.

Cut/Paste from a document with a “pre-existing” palette of symbols. Here is one based on

(SGML character entities supported by most modern browsershttp://www.zipcon.net/~swhite/docs/math/math.html)

Most of the Greek alphabet:

α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ σ ς τ υ φ χ ψ ω Α Β Γ Δ Ε Ζ Η Θ Ι Κ Λ Μ Ν Ξ Ο Π Ρ Σ Τ Υ Φ Χ Ψ Ω ϑ ϒ ϖ

a fairly rich selection of math symbols:

∀ ∴ ∃ ¬ ∋ ∅ ∈ ∉ ∧ ∨ ∩ ∪ ∂ ∇ ∏ ∑ ∫ √ − ∗ × ÷ ⋅ ± ⊕ ⊗ ∝ ∞ ∼ ≅ ≈ ≠ ≡ ≤ ≥ ⊂ ⊃ ⊄ ⊆ ⊇ ∠ ⊥

arrows:

← ↑ → ↓ ↔ ↵ ⇐ ⇒ ⇓ ⇔

fancier brackets:

⌈ ⌉ ⌊ ⌋ 〈 〉

a few fancy script letters:

ℵ ℘ ℑ ℜ µ

and these:

◊ ♠ ♣ ♥ ♦

Note, that the appearance of the symbol characters changes depending on the font used (above is Verdana). But they would look slightly different, more elegant and formal perhaps, with “Serif”.

Or you can also use the Google Docs command “insertSpecial CharacterAdvanced” to enter the Unicode number for a symbol. (e.g. ∭ was inserted by:

See this link for a comprehensive list of Unicode symbols that you can paste/insert into Docs.

You can also use that same link as a “palette” and just cut/paste from there to your document.

# General Suggestions

I suggest making an equation and symbol “library” document where you keep a collection of all your most commonly used equations and symbols, then you can just copy and paste from here into your current document. You could actually make a “template” document that has the palette of symbols in it, and use this as the starting point for all your new documents.

Caveat Emptor: for all the LaTeX methods outlined above when you export the doc to another format such as Word, or Open Office, etc., the equations will be saved as images and you will not be able to edit them again (except by re-creating them in that program). This does not apply to inserted symbols.

1. Thank you. I found your tips very useful in using equations in google docs.

Comment by David — April 21, 2009 @ 3:58 pm

2. Your tips are very useful!

Tank you.

Ciao

Comment by Mauro — May 16, 2009 @ 1:18 pm

• Hi glad you found this useful! I wrote it up last summer while I procrastinated writing my thesis (in LaTex, not googledocs)!

Comment by phbenito — May 16, 2009 @ 5:51 pm

3. […] May 21, 2009 Filed under: Uncategorized | Tags: equation, google docs, greek letters | Really nice tutorial on how to add equations, tables and greek letters in Google […]

Pingback by Equations in Google Docs « Luis Gustavo Martins’s Blog — May 21, 2009 @ 6:27 pm

you can see that the math symbols are off line a little bit (still readable though). Any idea about how to fix it would be highly appreciated!

Thanks,

Zhiyuan

Comment by Zhiyuan Dong — July 6, 2009 @ 3:05 pm

• Hi Zhiyuan,
The problem you encountered with the vertical alignment of the equations when they are inline with the text is a result of the bounding box around the image of the equation, which actually contains some white space. It can be improved by changing the vertical alignment properties of the images to “middle”, this will center the equation image vertically with the text. In the html code it would look something like this:

Let <img style="width: 142px; height: 18px;" alt="" src="http://www.codecogs.com/gif.latex?X=%28X_1,%20%5Ccdots,%20X_k%29" align="middle"> be a random vector. 

-Pascual

Comment by phbenito — July 6, 2009 @ 5:27 pm

• So, just a heads up that Zhiyuan wrote back that using “absmiddle” instead of just “middle” works even better to fix the issue of vertical alignment. Thanks Zhiyuan.

Also, just a shout out that WordPress supports inline LaTex expressions natively as 2007 (http://en.blog.wordpress.com/2007/02/17/math-for-the-masses/)
e.g. $i\hbar\frac{\partial}{\partial t}\left|\Psi(t)\right>=H\left|\Psi(t)\right>$
-P

Comment by phbenito — July 8, 2009 @ 2:46 am

5. Thanks a lot! Very useful.

Comment by Soniuca — August 18, 2009 @ 2:40 pm

6. As of September 2009, Google Docs allows us to insert TeX equation directly from its menu bar.
It is very handy since Greek symbols are available for selection in its user interface.
Furthermore, we can edit and see the change immediately anytime we want. No need to switch back and forth between two web sites.

The allowed equation, however, cannot be lengthy (an error will occur).

In my opinion, if a math expression is simple, stick with the Google Docs tool.
If not, a suggested method in this web page will become a better choice.

Comment by pinyotae — September 21, 2009 @ 3:49 am

• Hey thanks for the update on that, it looks like Google has added this somewhat limited TeX functionality using the google charts API. It’s essentially similar to the LaTex examples I’ve shown, where the equation is stored saved as the Tex code, and rendered as an image. But as you mentioned, it does not seem to be a full implementation of LaTex.
Here’s a little discussion I found that highlights some of the limitations: http://www.mail-archive.com/google-chart-api@googlegroups.com/msg01476.html
-pascual

Comment by phbenito — September 21, 2009 @ 6:57 am

Blog at WordPress.com.