Basic LaTeX: Difference between revisions
(→==) |
No edit summary |
||
(13 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
[[2013 | Back to 2013 Main Page]] | |||
[[2012 | Back to 2012 Main Page]] | |||
This tutorial is a "getting started" document. The TAs will give a more in depth tutorial with realtime feedback etc in the third week, before the first reports are due. | This tutorial is a "getting started" document. The TAs will give a more in depth tutorial with realtime feedback etc in the third week, before the first reports are due. | ||
Line 9: | Line 13: | ||
'''Windows.''' Several editors exists. We used WinEdt last year and this worked well. | '''Windows.''' Several editors exists. We used WinEdt last year and this worked well. | ||
== Example "report.tex" == | |||
You'll need to have this figure in the same directory as the text below. [[media:Apparatus.pdf]] [[media:Data_with_model_linear.png]] | |||
The output should look like this: [[media:example_tex.pdf]] | |||
<pre> | |||
% | % | ||
% LaTeX Example 1 for Advanced Lab | % LaTeX Example 1 for Advanced Lab | ||
Line 22: | Line 31: | ||
\usepackage{geometry} % give some flexibility to format | \usepackage{geometry} % give some flexibility to format | ||
\geometry{verbose,tmargin=1.00in,bmargin=1.00in,lmargin=1.0in,rmargin=1.0in} % needs the package geometry to work | \geometry{verbose,tmargin=1.00in,bmargin=1.00in,lmargin=1.0in,rmargin=1.0in} % needs the package geometry to work | ||
%For figures. | |||
\usepackage{graphicx} | |||
%This marks the start | %This marks the start | ||
Line 32: | Line 44: | ||
\begin{abstract} | \begin{abstract} | ||
In order to investigate Y about physical system Z, we carried out experiment X. A T apparatus was used to carry out the experiments. We measured some parameter to be 6 $\pm$ 5 J (J is units -- always remember units!). | In order to investigate Y about physical system Z, we carried out experiment X. | ||
\end{abstract} | A T apparatus was used to carry out the experiments. We measured some parameter to be 6 $\pm$ 5 J | ||
(J is units -- always remember units!).\end{abstract} | |||
%This marker indicates a section heading | %This marker indicates a section heading | ||
\section{Introduction} | \section{Introduction} | ||
Describe the phenomenon being measured and any historical info. This should not contain much information | |||
about what you did in the experiment-- just roundly what you aim to do. The intro is mainly useful background. | |||
In order to make another paragraph, leave a space between this and the previous paragraph. If you refer to a | |||
previous work on the subject, you'll want to cite it like this \cite{Erdos01}. Note the citation goes inside the | |||
sentence. See the end of the documentary for the bibliography specification along with the tag ``Erdos01". | |||
Another good use of the introduction is to introduce essential equations when going through the background science. | |||
Here is an important equation. | |||
\begin{equation} | |||
E= h\nu = E_{kin} + W_0 | |||
\label{eqn:photoelectriceffect} | |||
\end{equation} | |||
We use the ``label'' command so that we can latter use the ``ref'' command to reference this equation. | |||
\section{Experiment} | \section{Experiment} | ||
\ | \label{sec:experiment} | ||
\ | |||
%A figure (need graphicx package -- see preamble). See also ``wrapfigure" -- a useful package for saving space. | |||
\begin{figure}[ht] % the [t] says to put it at the top of the page (if possible) | |||
\begin{center} % center the figure | |||
\includegraphics[width=9cm]{apparatus} | |||
\caption{\small Apparatus. Include some valuable information here in the caption. Make sure all critical components are clearly labeled.} | |||
\label{apparatus} %this is so you can refer to the figure with a '\ref' markup. | |||
\end{center} | |||
\end{figure} | |||
In this section we describe the experiment setup and procedure, including apparatus etc. | |||
The apparatus is was incredibly complicated and impossible to describe in just words. See Figure \ref{apparatus}. | |||
See the label mark-up in the apparatus figure specification. ALWAYS use the ref/label pairs instead of putting | |||
in an absolute reference like ``Figure 1". This way if you move figures, then the numbering through out the text | |||
automatically adjusts. You should mark up your figure with text to describe the subsystems of the apparatus. | |||
Then you should use those same words (or letters that may be symbols in equations from the intro) to describe | |||
how the apparatus works here. | |||
We came up with a particularly clever way to carry out the experiment. First, we did A because of B. Then | |||
in order to C, we had to do D. In the end, for each setting of E we obtained five data points. We took the measurement | |||
at E to be the average of these five data and the error to be their scatter. The data is given in Table \ref{tab:data} | |||
\begin{table} | |||
\begin{center} | |||
\begin{tabular}{|c|c|} | |||
\hline | |||
E (Unit for E) & Measured Value (Unit) \\ \hline\hline | |||
5. & $1.32 \pm .24$ \\ \hline | |||
... & ... \\ \hline | |||
\end{tabular} | |||
\caption{Measurements of XYZ. Average measured values and errors are based on five data points obtained as described in Section \ref{sec:experiment}. } | |||
\end{center} | |||
\end{table} | |||
You can also intertwine the description of the apparatus with the procedure instead of having them in separate paragraphs | |||
as used here. | |||
\section{Analysis} | \section{Analysis} | ||
Describe the model that you used to fit the data. Discuss the goodness of the fit and, if the fit was good, | |||
the derived model parameters and errors. Here is the model for this experiment | |||
\begin{equation} | |||
m(x; a,b,c) = ax^2 + bx + c | |||
\label{model} | |||
\end{equation} | |||
This is obviously a simple model with parameters a, b and c. The model equation is linear in the parameters, so I choose | |||
to fit this with a simple linear least squares approach. The model is plotted with the deta in Figure \ref{fig:modelanddata}. | |||
The fit has a chi-sq of 8.97 for six degrees of freedom and a corresponding probability to exceed (PTE) of 0.18. The best | |||
fit parameters are $a=X.XX \pm 0.YY$, etc. | |||
If you refer to a particular analysis technique that you don't describe fully, then it's important to give a | |||
reference \cite{ConcreteMath}. | |||
\begin{figure}[ht] % the [t] says to put it at the top of the page (if possible) | |||
\begin{center} % center the figure | |||
\includegraphics[width=9cm]{Data_with_model_linear} | |||
\caption{\small Data with Model. Use the caption to say something interesting.} | |||
\label{fig:modelanddata} %this is so you can refer to the figure with a '\ref' markup. | |||
\end{center} | |||
\end{figure} | |||
\section{Discussion} | \section{Discussion} | ||
Interpret your results and discuss what may have gone wrong if, e.g., the fit in the Data Analysis section was not good. | |||
\section{Conclusion} | \section{Conclusion} | ||
A short section where you summarize the paper. | |||
\begin{thebibliography}{9} | |||
\bibitem{Erdos01} P. Erd\H os, \emph{A selection of problems and | |||
results in combinatorics}, Recent trends in combinatorics (Matrahaza, | |||
1995), Cambridge Univ. Press, Cambridge, 2001, pp. 1--6. | |||
\bibitem{ConcreteMath} | |||
R.L. Graham, D.E. Knuth, and O. Patashnik, \emph{Concrete | |||
mathematics}, Addison-Wesley, Reading, MA, 1989. | |||
\end{thebibliography} | |||
%Don't forget to end the document -- rookie mistake. | %Don't forget to end the document -- rookie mistake. | ||
\end{document} | \end{document}</pre> |
Latest revision as of 21:33, 24 February 2013
This tutorial is a "getting started" document. The TAs will give a more in depth tutorial with realtime feedback etc in the third week, before the first reports are due.
LaTeX is a documentation system in which you specify content and, for the most part, you let the LaTeX system deal with the formatting. It's a bit like a mark-up language (e.g., Hyper Text, which is used to create web pages). The general procedure for creating a document with LaTeX is to create a file (call it report.tex) with the content and special markers indicating things like sections, tables, figures, mathematical symbols, etc, and then you process this with a LaTeX formatter. (Many times you have to run the formatter twice in order to resolve cross-references in the document). LaTeX formatting programs are available freely for Linux/Unix, Mac, and Windows operating systems.
Linux. Open a terminal and, in the directory with your report, execute "pdftex report.tex". This is usually enough to generate a report.pdf under Linux.
Mac. For OSX, I like TeXShop. It has a graphic interface. Under the "Typeset" menu, select "Pdflatex". You enter your "report.tex" in their editor window and press "typeset" in order to generate a pdf.
Windows. Several editors exists. We used WinEdt last year and this worked well.
Example "report.tex"
You'll need to have this figure in the same directory as the text below. media:Apparatus.pdf media:Data_with_model_linear.png
The output should look like this: media:example_tex.pdf
% % LaTeX Example 1 for Advanced Lab % (Note the % sign denotes that the following text is a comment and will be ignored by the editor % % Document class -- specify font size (11pt) and document type (article). This should work for all reports. \documentclass[11pt]{article} % Packages augment basic latex. Here I use the geometry package to change the margins. \usepackage{geometry} % give some flexibility to format \geometry{verbose,tmargin=1.00in,bmargin=1.00in,lmargin=1.0in,rmargin=1.0in} % needs the package geometry to work %For figures. \usepackage{graphicx} %This marks the start \begin{document} \title{Experiment X} \author{Tobias Marriage} \date{Febuary 1, 2011} \maketitle \begin{abstract} In order to investigate Y about physical system Z, we carried out experiment X. A T apparatus was used to carry out the experiments. We measured some parameter to be 6 $\pm$ 5 J (J is units -- always remember units!).\end{abstract} %This marker indicates a section heading \section{Introduction} Describe the phenomenon being measured and any historical info. This should not contain much information about what you did in the experiment-- just roundly what you aim to do. The intro is mainly useful background. In order to make another paragraph, leave a space between this and the previous paragraph. If you refer to a previous work on the subject, you'll want to cite it like this \cite{Erdos01}. Note the citation goes inside the sentence. See the end of the documentary for the bibliography specification along with the tag ``Erdos01". Another good use of the introduction is to introduce essential equations when going through the background science. Here is an important equation. \begin{equation} E= h\nu = E_{kin} + W_0 \label{eqn:photoelectriceffect} \end{equation} We use the ``label'' command so that we can latter use the ``ref'' command to reference this equation. \section{Experiment} \label{sec:experiment} %A figure (need graphicx package -- see preamble). See also ``wrapfigure" -- a useful package for saving space. \begin{figure}[ht] % the [t] says to put it at the top of the page (if possible) \begin{center} % center the figure \includegraphics[width=9cm]{apparatus} \caption{\small Apparatus. Include some valuable information here in the caption. Make sure all critical components are clearly labeled.} \label{apparatus} %this is so you can refer to the figure with a '\ref' markup. \end{center} \end{figure} In this section we describe the experiment setup and procedure, including apparatus etc. The apparatus is was incredibly complicated and impossible to describe in just words. See Figure \ref{apparatus}. See the label mark-up in the apparatus figure specification. ALWAYS use the ref/label pairs instead of putting in an absolute reference like ``Figure 1". This way if you move figures, then the numbering through out the text automatically adjusts. You should mark up your figure with text to describe the subsystems of the apparatus. Then you should use those same words (or letters that may be symbols in equations from the intro) to describe how the apparatus works here. We came up with a particularly clever way to carry out the experiment. First, we did A because of B. Then in order to C, we had to do D. In the end, for each setting of E we obtained five data points. We took the measurement at E to be the average of these five data and the error to be their scatter. The data is given in Table \ref{tab:data} \begin{table} \begin{center} \begin{tabular}{|c|c|} \hline E (Unit for E) & Measured Value (Unit) \\ \hline\hline 5. & $1.32 \pm .24$ \\ \hline ... & ... \\ \hline \end{tabular} \caption{Measurements of XYZ. Average measured values and errors are based on five data points obtained as described in Section \ref{sec:experiment}. } \end{center} \end{table} You can also intertwine the description of the apparatus with the procedure instead of having them in separate paragraphs as used here. \section{Analysis} Describe the model that you used to fit the data. Discuss the goodness of the fit and, if the fit was good, the derived model parameters and errors. Here is the model for this experiment \begin{equation} m(x; a,b,c) = ax^2 + bx + c \label{model} \end{equation} This is obviously a simple model with parameters a, b and c. The model equation is linear in the parameters, so I choose to fit this with a simple linear least squares approach. The model is plotted with the deta in Figure \ref{fig:modelanddata}. The fit has a chi-sq of 8.97 for six degrees of freedom and a corresponding probability to exceed (PTE) of 0.18. The best fit parameters are $a=X.XX \pm 0.YY$, etc. If you refer to a particular analysis technique that you don't describe fully, then it's important to give a reference \cite{ConcreteMath}. \begin{figure}[ht] % the [t] says to put it at the top of the page (if possible) \begin{center} % center the figure \includegraphics[width=9cm]{Data_with_model_linear} \caption{\small Data with Model. Use the caption to say something interesting.} \label{fig:modelanddata} %this is so you can refer to the figure with a '\ref' markup. \end{center} \end{figure} \section{Discussion} Interpret your results and discuss what may have gone wrong if, e.g., the fit in the Data Analysis section was not good. \section{Conclusion} A short section where you summarize the paper. \begin{thebibliography}{9} \bibitem{Erdos01} P. Erd\H os, \emph{A selection of problems and results in combinatorics}, Recent trends in combinatorics (Matrahaza, 1995), Cambridge Univ. Press, Cambridge, 2001, pp. 1--6. \bibitem{ConcreteMath} R.L. Graham, D.E. Knuth, and O. Patashnik, \emph{Concrete mathematics}, Addison-Wesley, Reading, MA, 1989. \end{thebibliography} %Don't forget to end the document -- rookie mistake. \end{document}