Part of being a professional physicist is learning to use professional tools. One of these tools is LaTeX, a professional typesetting program that is commonly used in the sciences. To teach you how to use this tool, we will ask you to produce a short article (with nonsense content) in order to learn how to create and edit a LaTeX manuscript. At the end of the exercises, you will have a fully-functional template to use on analyses, reports, and journal articles.
For this class, we are suggesting you use Overleaf, an online LaTeX editor and compiler. While it is possible to create a local installation of LaTeX on your computer, Overleaf is just so, so easy and provides a nice online platform that allows you to work on your documents across multiple computers and even collaborate with others (e.g. in the future when you may write a journal article as part of a research group). |
To use Overleaf, head to the homepage and either register for an account or click “Log in through your institution” to log in with your UChicago CNet ID and password.
Once you are logged in, click the New Project button in the upper left corner, and choose Blank Project. Give the project a name and hit Create. You should now see a bare-bones document.
On the left side of the screen is the directory corresponding to your project. Right now, the only file is “main.tex”. You can upload additional files (e.g. images) by clicking the Upload button, or you can create supplementary *.tex files by clicking New.
In the middle is the LaTeX source code (i.e., what is contained in “main.tex”). Right now, the code there just gives the paper its basic outline structure. This file contains the instructions for how to create your final paper, with the TeX engine interpreting these instructions and doing most of the important formatting for you when you compile the code into a PDF.
Finally, on the right is the compiled PDF. After you make edits to the source file, you can hit Recompile and it will generate a new PDF. Any errors will appear at the document icon next to that button (“Logs and output files”), and the final PDF can be downloaded by hitting the button next to that.
Try to edit the LaTeX file by adding a little bit of sample text on a new line under line 12 (\section{Introduction})
. Maybe say something like “Hello world!” Hit Recompile. Does your change appear?
There are many online guides for getting started with LaTeX. The main resources we recommend are the following:
Overleaf's guide will help you get started and Not So Short… is a great reference to look at later when you have questions. Keep in mind that just like with Python, no one remembers all the syntax… it is normal (and encouraged) that you just look up examples or specific commands as you need them.
When in doubt, just Google “LaTeX [whatever your problem is]”.
Start from a New Project (as above), then begin reading through the tutorial “Learn LaTeX in 30 minutes”. Use the guidance there to complete a sample LaTeX document that includes the following:
Feel free to use nonsense text or nonsense images in the body of the article.
In case you are confused about any of the things we're asking for, here is a sample PDF showing the completed assignment – sampleassignment1.pdf
At this point you have a template that should work for writing a general analysis or report for PHYS 211. You do not need to move on to Assignment 2 unless want practice putting together a more formal journal article.
Return to your document from Assignment 1. Follow the instructions below to make changes, and consult the help documents on Overleaf (or any other online LaTeX resources) if you have questions about how things work.
Remember to frequently recompile your document as you make edits. It's easier to find an error in the code if you recompile after a small change (when the error is confined to only a small piece of code you've been working on) rather than waiting until you made lots of big changes (when the error could be anywhere).
We started by using LaTeX's built-in “article” document class, but we now want to switch to a class called REVTeX, which is the document class created by the American Physical Society (APS) for articles published in their journals. To do this, make the following changes:
\documentclass{revtex4-2}
\begin{document}
up so that it occurs before the \title{…}
line.
You shouldn't see any dramatic changes… the font size and margins are a little different, but overall it still looks like your article from before. However, REVTeX has many built-in options to easily make all the specific style and formatting settings needed for each individual journal published by APS. For example, if you were to add the “prl” option (done by changing the first line to read \documentclass[prl]{revtex4-2}
), you will see that the section headings and subheadings are no longer numbered or lettered (since APS has decided that is the style for articles in the journal Physical Review Letters).
For the purposes of PHYS 211, you don't need to specify a specific journal style, but there are two other REVTeX options we want to talk about in more depth :
When you write a journal article, it is common to format your first draft using “preprint” (which will make it easier for your peer reviewers to add comments) and your final draft using “reprint” (which will make the article more attractive and professional-looking).
For today's assignment, use the reprint option: \documentclass[reprint]{revtex4-2}
.
Next, add the following “special” sections to your paper.
At the top of your document (somewhere after the “\title{}” and “\author{}” lines, but before the line that reads “\maketitle”), add an abstract section as follows:
\begin{abstract} Blah, blah, blah \end{abstract}
Where we wrote “blah, blah, blah” above, you should write a sentence or two that will serve as your nonsense abstract for now. We'll cover how to write a good abstract another time.
At the end of your document (after your last normal section, but before the \end{document}
command), add the acknowledgements section as follows:
\begin{acknowledgments} Thanks to all my physics \textit{ph}ans... I couldn't have done it without you! \end{acknowledgments}
The acknowledgements is where you would acknowledge funding sources if your work was supported by a grant, or its a place to thank collaborators (who weren't authors) or others you had conversations with. It is also common for authors to thank the peer reviewers. You may wish to use this space to thank the lab partners you worked with on your project.
An appendix is a section that comes after the main body of the paper is complete, and it is used to hold “extra” information that you don't want to put in the main text. Add an appendix after your acknowledgements section as follows:
\appendix* \section{Not just a useless organ} Here is my appendix text
If you have multiple appendices, they should be labeled in sequence, (e.g. Appendix A, Appendix B,…), but if there is only one, it should just read “Appendix”. LaTeX will enumerate the sections automatically by default, so if the case where there is a single appendix, we add the asterisk (e.g. “\appendix*”) to tell LaTeX not to give it a number or letter.
A handy thing to do is to reference a previous (or future) section by number in the text. (For example, “In Section 42, we will cover the answer to life, the universe and everything”.) In LaTeX, you can give a section (or a subsection, or a subsubsection) a label just like you give to a figure or table, and reference it in in the same way.
Create a new section called “Callback” and write a short string of text that references a previous section by number using the \ref{sec:label}
command. Note that you can add the section label right inside the curly brackets of the section command, as shown in the following example:
There are two methods for adding references to your LaTeX document.
The Overleaf page on this topic gives a nice overview for both methods.
For this assignment, we'd like you to work with the full BibTeX format and place your references in a separate *.bib document. This is a little more work than is needed for a small project like this, but it's good practice for future work you may do on a thesis or other research project.
To start, download this file (which has been provided by APS as part of their REVTeX sample template) and upload it to your project on Overleaf:
It includes many, many examples of different types of sources – e.g. articles, books, theses, private communications.
Using the examples there as a guide, add at least 3 reference entries of your own to the *.bib file. They can be articles (e.g. the articles we used for journal club), books (e.g. a textbook), websites (e.g. the PHYS 211 wiki), or any other source you want to add. You may delete the entries you don't want, or keep them in the file so you can refer back to them later as examples.
Many journal websites make exporting complete citations in BibTeX format easy. For example, if you go to any article on the APS site – e.g., this one – you can push the “Export Citation” button and copy the full BibTeX entry right into your own document.
Alternately, (as pointed out by one of our own PHYS 211 students!), you can also get the BibTeX information directly off any Google Scholar entry by clicking the quote icon (“cite”) below the entry and selecting “BibTeX”.
Within your main text, add the bibliography to your paper by including the following line (after the appendix, but before the \end{document}
command:
\bibliography{references}
When you recompile, you may notice that no references have appeared in your paper! That is because the bibliography command will only add those sources which have been cited in the paper… and right now you are not citing any sources. So let's add some citations.
Somewhere in the text of your paper (it doesn't matter where), add some citations like the following: text text text\cite{sourcename}
. Note that you can also reference multiple sources at once, e.g. text text text\cite{source1, source4, sourceJ}
. Now when you recompile, you should see these references added to the reference list.