Difference between revisions of "LaTeX:Math"

Line 1: Line 1:
 
{{Latex}}
 
{{Latex}}
  
To place something written in TeX in '''math mode''', use <nowiki>$</nowiki>s to open and close the segment in math mode.
+
LaTeX uses a special math mode to display mathematics. To place something written in TeX in '''math mode''', use <nowiki>$</nowiki> signs to enclose the math you want to display. For example, open a new source file in TeXnicCenter and type or copy/paste the following: 
  
 
For example, look at the following segment of code:
 
For example, look at the following segment of code:
Line 8: Line 8:
 
\documentclass{article}
 
\documentclass{article}
 
\begin{document}
 
\begin{document}
If we take the square root of $\sqrt{4}$, the answer is $x=2$.
+
The solution to $\sqrt{x} = 5$ is $x=25$.
 
\end{document}  
 
\end{document}  
 
</nowiki></pre>
 
</nowiki></pre>
 +
Save the document (press Ctrl-S or click File, then Save) as 'mymath' (don't include the quote marks in the name) in a folder of your choice. The file will appear in your folder as 'mymath.tex.'
 +
 +
Compile the document just as you compiled your [[LaTeX:Basics|first document]]. When you view the output file, you should see
 +
<math>
 +
  
 
This results in:
 
This results in:
  
If we take the square root of <math>\sqrt{4}</math>, the answer is <math>\displaystyle x=2</math>.
+
<math>\text{The solution to } \sqrt{x} = 5 \text{ is } x=25</math>
 +
If you remove the <math> symbols from your source file then try to compile, you should get 'Missing </math> inserted' error messages in the Output window of TeXnicCenter (try it and see - you may have to scroll up in the Output window to see the errors).
 +
 
 +
Nearly all mathematical items, such as variables, expressions, equations, etc., should be written in math mode. In fact, most math will generate errors if you don't remember to put it in math mode.
  
 
== Style ==
 
== Style ==

Revision as of 18:25, 10 July 2007

LaTeX
About - Getting Started - Diagrams - Symbols - Downloads - Basics - Math - Examples - Pictures - Layout - Commands - Packages - Help

LaTeX uses a special math mode to display mathematics. To place something written in TeX in math mode, use $ signs to enclose the math you want to display. For example, open a new source file in TeXnicCenter and type or copy/paste the following:

For example, look at the following segment of code:

\documentclass{article}
\begin{document}
The solution to $\sqrt{x} = 5$ is $x=25$.
\end{document} 

Save the document (press Ctrl-S or click File, then Save) as 'mymath' (don't include the quote marks in the name) in a folder of your choice. The file will appear in your folder as 'mymath.tex.'

Compile the document just as you compiled your first document. When you view the output file, you should see $This results in:

<math>\text{The solution to } \sqrt{x} = 5 \text{ is } x=25$ (Error compiling LaTeX. Unknown error_msg) If you remove the $symbols from your source file then try to compile, you should get 'Missing$ inserted' error messages in the Output window of TeXnicCenter (try it and see - you may have to scroll up in the Output window to see the errors).

Nearly all mathematical items, such as variables, expressions, equations, etc., should be written in math mode. In fact, most math will generate errors if you don't remember to put it in math mode.

Style

Eqnarray

Additional packages

Next: Style