Author Topic: How to use Latex to write equations.  (Read 184 times)

huntersair

• Posts: 8
• Karma: +0/-0
How to use Latex to write equations.
« on: June 26, 2017, 12:55:28 PM »
Understandably getting to grips with Latex can seem a daunting task for the unfamiliar user.
As a result, one way of getting a feel of how Latex works is to use an online Latex equation editor.

As an example we will attempt to recreate:

\begin{align}
\frac{\delta S}{\delta \phi}=\frac{\partial\mathcal{L}}{\partial \phi} - \partial_{\mu}\left(\frac{\partial\mathcal{L}}{\partial \left(\partial_{\mu}\phi\right)}\right)=0
\end{align}

For those curious this is the form of the Euler-Lagrange equation used in quantum field theory..

2. As a default you should see the syntax required to produce the quadratic equation.
Click the button on the forum to reply to this post.
When you copy & paste "\frac{-b\pm\sqrt{b^2-4ac}}{2a}" into the text-box and press preview you will notice that no equation shows up.
Add to the front of the equation a slash followed by an open bracket, and at the end of the equation add a slash followed by the close bracket.
The equation now shows: $$\frac{-b\pm\sqrt{b^2-4ac}}{2a}$$.

3. Notice that "\frac{}{}" takes two arguments, numerator in the first bracket and denominator in the second.
Write "delta S" in the first bracket and "delta phi" in the second, and press preview.
What you should see is: $$\frac{delta S}{delta phi}$$.
Whoops, instead of writing the symbols we have written words.
To write symbols add a slash before each symbol so that it reads: "\frac{\delta S}{\delta \phi}".
When you preview it should now display: $$\frac{\delta S}{\delta \phi}$$.

4. The next term in the equation we are trying to write is: $$\frac{\partial\mathcal{L}}{\partial \phi}$$.
To do this write: \frac{\partial\mathcal{L}}{\partial \phi}, whereby \mathcal{L} produces the $$\mathcal{L}$$ symbol and \partial produces $$\partial$$.
Now you can put an equals sign between the two fractions to receive: "\frac{\delta S}{\delta \phi} =  \frac{\partial\mathcal{L}}{\partial \phi}".
Putting our slash-open and slash-close brackets at the beginning and end of our equation we get: $$\frac{\delta S}{\delta \phi} = \frac{\partial\mathcal{L}}{\partial \phi}$$.

5. We are now in a position to tackle our most complicated term: $$\partial_{\mu}\left(\frac{\partial\mathcal{L}}{\partial \left(\partial_{\mu}\phi\right)}\right)$$.
Go back to the equation editor, clear the Latex code, and click the subscript button.
It shows a_{b} as a demonstration.
Which can be made to be shown as: $$a_{b}$$.
Substitute "\partial" in place of "a" and "\mu" in place of "b" so that it reads as: "\partial_{\mu}".
Adding our slash-brackets we can show it as: $$\partial_{\mu}$$.
Now on the equation editor, clear the text and navigate to the "Arrow" tab.
Click the left bracket, and then the right bracket.
It should show "\left(\right)".
To enclose something in brackets we type something in-between "\left(" and "\right)".
If we do not follow this syntax convention and just use "(" and ")" we will end up with: $$\partial_{\mu}(\frac{\partial\mathcal{L}}{\partial \left(\partial_{\mu}\phi\right)})$$, which, while readable, just doesn't look as nice as it            doesn't enclose the entire inner part.
So, the numerator is trivial, and we already know how to write the first argument of our /frac{}{}.
The denominator is a little less obvious but see if you can follow the Latex of the denominator: $$\partial\left(\partial_{\mu}\phi\right)$$.
The latex code for $$\partial\left(\partial_{\mu}\phi\right)$$ is \partial\left(\partial_{\mu}\phi\right).
Putting this altogether we should now be able to construct: $$\frac{\delta S}{\delta \phi}=\frac{\partial\mathcal{L}}{\partial \phi}-\partial_{\mu}\left(\frac{\partial\mathcal{L}}{\partial\left(\partial_{\mu}\phi\right)}\right)=0$$.
The Latex code is:
"\frac{\delta S}{\delta \phi}=\frac{\partial\mathcal{L}}{\partial \phi}-\partial_{\mu}\left(\frac{\partial\mathcal{L}}{\partial\left(\partial_{\mu}\phi\right)}\right)=0"

6. Almost done! We have explored how to write Latex equation inline with text.
To write Latex equations aligned in the centre of the page put a slash before "begin{align}" and "end{align}" and put these activated functions in place of          the slash-brackets at the beginning and end of the equation.
Now it should show up as:
\begin{align}
\frac{\delta S}{\delta \phi}=\frac{\partial\mathcal{L}}{\partial \phi} - \partial_{\mu}\left(\frac{\partial\mathcal{L}}{\partial \left(\partial_{\mu}\phi\right)}\right)=0
\end{align}

7. Finally to change the size of the equation highlight over the entire Latex code in the text-box, and then click on the "Font Size" drop-down menu to select a      size.
This will add font size tags to your code and allows you the freedom to choose the size of equations.
For the example equation, I used font size 14.
These font size tags work with normal text too.

Thank you for taking the time to read this post.
Happy typesetting!

« Last Edit: November 26, 2017, 10:50:39 PM by huntersair »