Eberly College of Science Mathematics Department, Center for Interdisciplinary Mathematics
REU banner

LaTex, and writing a math paper

History

References

Contents

Useful LaTex packages

For practice, follow all of the directions below using commands in the terminal that we learned about yesterday. You may find it useful to use more than one terminal window (one for your text editor and one for shell commands).

  1. Create a new directory on your Desktop called "LaTex".

  2. Change your current working directory to your new "LaTex" directory.

  3. Create a new file called "hello.tex" in your new directory. This will be your first LaTex document. LaTex files traditionally end with the ".tex" suffix.

    The common work-flow for creating documents with Latex is

    1. Edit your .tex file.

    2. Compile your .tex file with the pdflatex command.

    3. If you get compile errors, fix them and recompile.

    4. Inspect your .pdf output in a pdf viewer.

    This is the same kind of work-flow used in writing Fortran and C programs, so it is a good introduction. Here is how it goes...

  4. Type the following code into your "hello.tex" file.

        \documentclass[]{article}
        \begin{document}
        hello world!
    
    
        My favorite book is
        Solaris
        by
        Stanislaw
        Lem
        \end{document}
        

    Be sure to save your changes.

    LaTex is a "markup" language, which tells printers and other tools what you want your document to look like. None of the tags above beginning with a backslash will appear in your final pdf document.

  5. At your shell command line, compile "hello.tex" using the following command.

            pdflatex hello.tex
            

    This compiles your LaTex file. It creates a bunch of new files in the process.

  6. Use the Preview or Acrobat portable document format viewers to inspect your new "hello.pdf". Compare what you got out with what you put in and see if you understand what happened. How does the arrangement of the text you got out differ from what you put in?

  7. Make a backup copy of the file "hello.pdf" for future reference.

  8. Update "hello.tex" file to be the following.

        \documentclass[]{article}
        \begin{document}
        hello world!
    
    
        \begin{enumerate}
        \item
        should be number one in the list
        \item
        should be number two in the list
        \end{document}
        

    Be sure to save your changes.

  9. Compile "hello.tex" like you did above. This time, however, you are going to get an error. Read the error message, see if you can figure out what is wrong with your changes, and fix things.

  10. Once you have fixed things, you can inspect "hello.pdf" to see how LaTex typesets an enumerated list. Notice that we did not have to do the numbering ourselves – LaTex handled all that.

  11. Remove hello.log and hello.aux.

    (you do not really need to do this - pdflatex with overwrite them as needed, but it is another chance to practice shell commands)

  12. The reason we have used LaTex for decades is that it provides a free common platform for writting pretty mathematical equations, and that it allows us to focus on what we mean rather than what we see.

    Create a new file "myfirstmath.tex" with the following content.

    \documentclass[12pt]{report}
    % comments in LaTex are started by the percent symbol
    % if you want to type "%" in Latex, use \%.
    
    \usepackage{amsmath} % this is a library package for math commands
    % The "ams" in amsmath stands for American Mathematical Society
    
    \begin{document}
    my first equation is not 100\% true.
    \begin{equation}
        \label{eq1}
        2 + 2 = 5 + \sqrt{3 + x^2} = 45 \leq \frac{z_6}{3 + \beta}.
    \end{equation}
    My second equation is inline: $ 2 + 3 > 5 \times 1 $
    My 3rd equation is the system
    \begin{gather}
        \label{eq3a}
        x + y = 5,
        \\
        \label{eq3b}
        10 x - 10 y = 30.
    \end{gather}
    But we could also typeset  this system as
    \begin{align}
        \label{eq4a}
        x + y &= 5,
        \\
        \label{eq4b}
        10 x - 10 y &= 30.
    Maybe Equations~\eqref{eq4a} and \eqref{eq4b} look better than
    Equations~\eqref{eq3a} and \eqref{eq3b}
    \end{document}
  13. Compile "myfirstmath.tex" once and inspect "myfirstmath.pdf" What commands did what? Also, notice that there are a few question marks.

  14. Compile "myfirstmath.tex" a second time and inspect "myfirstmath.pdf". What happened to the question marks?

Exercise:

That is basic LaTex. To get some practice, create your own LaTex document explaining how the quadratic formula is used to solve a quadratic equation using the commands above.