New To LaTeX

From DPWiki
Jump to navigation Jump to search

Notes for those new to LaTeX

LaTeX projects differ substantially from other DP projects, which are distributed as plain text and optionally as HTML. Like HTML, LaTeX is a markup language: A document contains textual content interspersed with "tags" or "commands" specifying how the document should be rendered on a computer screen or printed page.

However, LaTeX has completely different syntax than HTML, and therefore has separate guidelines for formatting text and math. Tutorials and manuals are essential for learning to use LaTeX. Climbing the learning curve requires effort, but you're rewarded with the capability of producing beautiful (camera-quality) printed and on-line documents.

In a LaTeX project, formatters are responsible for many details that would be handled by the post-processor in an HTML project. At a conceptual level, LaTeX and non-LaTeX formatting are roughly analogous, but as to the details of what you type in the proofing window they differ substantially.

In addition, unlike HTML, a LaTeX document must be "compiled" in advance using special software--LaTeX. The resulting human-readable document is usually distributed as a portable document format (PDF) file. Several no-cost programs allow PDF files to be read; these include Acrobat Reader (for multiple platforms), xpdf (GNU/Linux), and Apple Preview.

All modern computer operating systems come with a web browser (Firefox, Safari, Opera, Netscape, Internet Explorer, etc.), which effectively compiles and displays web pages as they're downloaded. By contrast, most operating systems do not come with LaTeX; GNU/Linux is the most common exception.

This state of affairs places a burden on you, the new or prospective formatter of DP LaTeX projects: In order to check that your formatted pages contain valid LaTeX code, you must compile them, either using software installed on your computer (preferable) or using an online compiler (which may not be as satisfactory).

This page explains how to download and install a "distribution" of LaTeX; currently only MiKTeX (for Windows) is described.


Downloaded software

How to download and install the software.

This note deals with installing MikTeX and TeXnicCenter on the following platforms:-

  • Windows Vista
  • Windows Server 2003
  • Windows XP
  • Windows 2000

Installing MiKTeX

MiKTeX bundles everything you need to compile LaTeX files.

The download link is on the left hand side. Choose the Basic MiKTeX 2.7 Installer. When the file has been downloaded double-click on it to start the installation and install to the default location. Answer the questions, (which are self-explanatory), and then installation will take at least 10 minutes to complete on a fast computer.

Then go to the Windows Start menu and find MiKTeX2.7 in the Programs list and select Update from the list of options, choosing the default settings when asked. (It is possible that selecting ‘Let me choose a remote package repository’ to choose a server near where you are based will be better than the default ‘Pick out a random repository’.)

Then close Update.

MiKTeX comes with YAP, a previewer for LaTeX files compiled to DVI ("device independent") format. Some people prefer to compile to PDF and use a PDF viewer.

Using MiKTeX is a lot easier if you can run it from inside the text editor you use to work on your LaTeX files. This is where TeXnicCenter comes in: it is a LaTeX-aware text editor that provides an integrated interface to MiKTeX. Download and install TeXnicCenter, preferably to the default location.

Installing TeXnicCenter

This program can be obtained from TeXnicCenter. There is a Download link at the top of the home page. Choose the first item in the list in the End-User Downloads section, (currently TeXnicCenter Setup, Version 1 Beta 7.50 as at July 2008).

When asked choose ‘Install all components’. This program should install in seconds. When it runs for the first time it will open the Configuration Wizard.

  • Distribution Directory – enter C:\Program Files\MikTeX2.7\miktex\bin if you have accepted the default location for installing MikTeX, or the path to latex.exe if different. (This is the path on a Vista computer so may be different on other platforms.)
  • PostScript Viewer – this can be ignored.

TeXnicCenter is now ready to be used.

Setting up TeXnicCenter

Click on the Tools menu, then Options..., and a window with seven tabs will open.

  • The File Tab allows users to ensure that documents are saved before compilation and that documents are saved at predetermined intervals.
  • Directories Tab. Users can set the Default working directory, (at the bottom of the window), to the directory of choice. The Project Template and Document Template directories are entered by default.
  • In the Editor Tab ensure the 'Show Line Numbers' box is ticked to display line numbers to the left of each line.
  • The Text Format Tab allows the default font to be changed if required.

Using a PDF previewer

TeXnicCenter should come already set up to compile LaTeX to DVI (and to preview in YAP): you will see a drop-down menu in the toolbar showing "LaTeX => DVI". If you are more comfortable using a PDF viewer like Adobe Reader/Acrobat then you can change the Output Profile. At the bottom of the "Build" menu select "Define Output Profiles..." With any luck there is already a Profile labelled "LaTeX => PDF"; if not click "Add" and fill in details similar to this—

Texnicprofiles1.png

The "Postprocessor" tab should be empty. Go to the "Viewer" tab and fill in the following details (use the … button to navigate to the location of your PDF viewer).

Texnicprofiles2.png

The DDE commands are specific to Adobe Reader/Acrobat. These allow TeXnicCenter to close an already-open PDF preview before recompiling the LaTeX.

Now go to the "Build" menu and "Select Output Profile..." (or just choose "LaTeX => PDF" from the drop-down menu in the toolbar).

To Start Editing - Method 1

This method uses only one file.

Open TeXnicCenter and there should be two windows, tiled horizontally, the top one of which is where the text to be edited is placed and the lower one, labelled ‘Output’ which displays messages when the page is compiled.

Ensure that the Output Profile drop down list under the Build menu option is set to ‘LaTeX=>DVI’.

Editing window.

Paste the following into this window, (text following ‘%’ is ignored by the program so is where comments should be entered) :-

\documentclass{book}  %this line should always be at the top ****************
% the preamble is entered below this line, if there is no preamble shown in the Project Guidance then use the next 2 lines
\usepackage{amsfonts,amsmath,amssymb,amsthm}
\usepackage[latin1]{inputenc}
% end of preamble ***********************************************

\begin{document}  % this line is always required
% the text to be edited comes after this line ********************



% text to be edited entered above this line **********************
\end{document}  % 

Copy the text of the page which is being edited from DP into TeXnicCenter and then edit it. (Looking at how previous pages in the project have been coded can be useful, as well as looking at some of the documentation referred to on this page.)

When all changes have been made then compile the page by either :- · Using the menu Build, Current File, Build; or · Ctrl + F7; or · clicking the Build Current File button just to the right of the Output Profile list mentioned at the start of this section.

Output Window.

A series of messages will then be displayed in the Output window at the bottom. A typical example is shown here.


--------------------Output Profile: LaTeX => DVI--------------------------
This is pdfTeX, Version 3.1415926-1.40.8-alpha-20080323 (MiKTeX 2.7) 
entering extended mode
(Logic.tex
LaTeX2e <2005/12/01>
Babel <v3.8j> and hyphenation patterns for english, dumylang, nohyphenation, ge
rman, ngerman, french, loaded.
("C:\Program Files\MiKTeX 2.7\tex\latex\base\book.cls"
Document Class: book 2005/09/16 v1.4f Standard LaTeX document class 
("C:\Program Files\MiKTeX 2.7\tex\latex\base\bk10.clo")) (Logic.aux) 

 {Warning Image}  Package babel Warning: No hyphenation patterns were loaded for
(babel) the language 'greek'
 {Error Image} !  Missing $ inserted.
<inserted text>
 			$
1.73
 {BadBox Image} Underfull \hbox (badness 10000) in paragraph at lines 10--20
[1] (Logic.aux) )
(see the transcript file for additional information)
Output written on Logic.dvi (1 page, 2076 bytes).
Transcript written on Logic.log.
This is BibTeX, Version 0.99c (MiKTeX 2.7)
The top-level auxiliary file: C:\Users\Viv\Documents\LaTeX\Logic.aux
I found no \citation commands---while reading file C:\Users\Viv\Documents\LaTeX\Logic.aux
I found no \bibdata command---while reading file C:\Users\Viv\Documents\LaTeX\Logic.aux
I found no \bibstyle command---while reading file C:\Users\Viv\Documents\LaTeX\Logic.aux
(There were 3 error messages)
Couldn't find input index file C:\Users\Viv\Documents\LaTeX\Logic nor C:\Users\Viv\Documents\LaTeX\Logic.idx.
Usage: C:\Program Files\MiKTeX 2.7\miktex\bin\makeindex.exe [-ilqrcgLT] [-s sty] [-o ind] [-t log] [-p num] [idx0 idxl ...]

LaTeX-Result: 2 Error(s), 1 Warning(s), 1 Bad Box(es), 1 Page(s)


After Compiling

Check the last line showing the number of Errors, Warnings and Bad Boxes.

Error Image - a red circle with a white cross superimposed.
Warning Image - a yellow triangle containing a black exclamation mark.
BadBox Image - a white thought balloon containing a blue letter i.

Errors need to be found and corrected, (it is possible that there is only one error and the other errors will disappear when that one error is corrected). Look at the Warnings to see if any can be corrected, (some cannot), and ignore the Bad Boxes. (It is safe to ignore (There were 3 error messages) which refers to the 3 previous lines regarding the file Logic.aux.)

The last six buttons on the top row of buttons allow the user to jump automatically to the next/previous Error, next/previous Warning or next/previous Bad Box. The description of the problem is not always helpful to new users but the number, e.g. 1.73 shows that the problem is on, (or the program thinks it is on), line 73 and where the problem should be on that line. Use Search, Go To… to move the cursor to the indicated line in the top window. (Sometimes a red arrow appears on the left margin next to the error line.

To see the Output to check what the compiled page looks like either :- · Using the menu Build, View Output; or · F5; or · clicking the View Output button to the right of the Build Current File button.

If there are too many errors when compiling then no output file will be generated, and a message to this effect will be shown in the Output window. It is possible to combine the previous steps by :- · Using the menu Build, Build and View Output, (if not greyed out); or · Ctrl + F5; or · Clicking the Build and View Current File button to the left of the last six buttons.

All of these options cause the Yap viewer, (which is part of MiKTeX), to launch to display the output.


The Finished Page

Displaying the output enables comparison with the image of the page in DP. When all errors have been removed and the output is similar to the original then the text in the editing window between the lines :-

% the text to be edited comes after this line ********************

and

% text to be edited entered above this line **********************

should be copied to DP to replace the proofread text.


To Start Editing - Method 2

Using this method two files are required - snippet.tex and wrapper.tex. Create both files and save them to the default directory. (There will be tabs at the bottom of the Edit window showing the file name.) The first file, snippet.tex, will contain ONLY the text from the page being formatted, but wrapper.tex will contain this code, unless a different preamble is needed :-

%% wrapper.tex
% ********** Preamble (replace with any project specific preamble) ******************

\documentclass{book}
\usepackage{amsfonts,amsmath,amssymb,amsthm}
\usepackage[latin1]{inputenc}
 
% ************ end of Preamble ****************************


\begin{document} % ********** Do not change this line or the next two ***************

\input{snippet.tex}

\end{document}

Compile as in the previous method but ensure that the wrapper.tex file has the focus, i.e. the text in the tab showing the file name is in black, not grey. (Compiling the file from the snippet.tex will always generate errors.) If there are errors with the text in snippet.tex then the line numbers shown in the Output window will refer to that file, not wrapper.tex.

Refer to the sections Output Window, After Compiling and The Finished Page above for further information.

When satisfied that formatting has been completed it is only necessary to copy everything from snippet.tex and paste into DP to replace the P3 text. This method makes it easier to ensure that the correct text is pasted into DP, but does require the user to switch between the two files when editing, compiling and correcting errors.


An Online Compiler

If you want to try your Latex-skills without installing software, you can use this online compiler, (or here if you prefer German).

Some errors may be generated if this compiler does not have all of the packages required for the text which is being compiled, but for most projects it is adequate.