Originaltext | Björn Åsen | Augusti 2000 |
Introduktion |
Textbehandling med LaTeX |
Flera kommandon |
Exempel 1. Liten artikel
Exempel 2. Stor artikel
Exempel 3. Rapport
Under er utbildningstid kommer ni att få skriva ett flertal rapporter. Det viktigaste är ju givetvis innehållet, men en snygg rapport med god läslighet, ökar chansen för att läsaren tar till sig innehållet. Utgångspunkten bör vara att rapporten görs med dator. En handskriven rapport med dålig handstil är inte kul att läsa. Tänk på följande sätt: Om ni skulle betygsätta en rapport, vilka vore era krav på läslighet och utseende?
Textbehandling kan generellt delas in i fyra olika steg:
WYSIWYG = What You See Is What You Get.
Namnet kommer av att du direkt när du skriver in texten ser
hur layouten blir.
Man skriver alltså in texten och den formatteras samtidigt.
WYSIWYG-program är byggda för att även klara av att visa och skriva ut
resultatet.
Exempel på WYSIWYG-program av
ordbehandlare är Word, Framemaker,
WordPerfect, StarOffice etc.
Denna typ av ordbehandlare kommer inte att läras ut, då det finns
en mängd olika program med olika för och nackdelar.
Ett annat förhållningssätt är att använda LaTeX, som står för Layman's
TeX, dvs lekmanna TeX. TeX står för i tur och ordning de grekiska
bokstäverna tau, epsilon och chi.
Skillnaden mot WYSIWYG-ordbehandlare är att man skriver in sin
text i en editor (t.ex emacs) tillsammans med ett
antal kommandon som beskriver hur texten skall se ut, ungefär
som HTML. Därefter låter man programmet LaTeX formattera texten.
Fördelarna med detta är flera:
Nackdelen är att det tar längre tid och är jobbigare att arbeta med
texten och få den snygg innan man lärt sig att jobba med LaTeX
effektivt.
Det kan nämnas att flera stora fysiktidskrifter t.ex Physical Review,
endast tar emot manuskript skrivna i LaTeX.
Starta en editor
Använd förslagsvis emacs, och skriv in texten och
formatteringskommandona.
Döp din fil med ändelsen .tex , exempelvis rapport.tex
Emacs kan fås känna av att det är en LaTeX fil och en speciell meny
med vissa hjälpmedel läggs till. Läs mera
här
När du skrivit in texten, låter du programmet LaTeX formattera texten.
Detta görs med kommandot latex rapport
Om LaTeX inte hittar några fel i koden genereras en
så kallad .dvi fil, i vårat fall rapport.dvi .
DVI står för Device-Insensitive, vilket betyder att .dvi filen är
skapad oberoende av utskriftsformat och utskriftsenhet.
Ibland händer det att man gjort fel. Programmet stannar då
och ett felmeddelande visas, samt på vilken rad felet är.
Prompten är ett frågetecken (?) och man kan här välja vad
man vill göra:
Om formatteringen gick bra kan du titta på resultatet med kommandot xdvi rapport
Om du vill kunna skriva ut filen i Unix-miljö, måste den vara i PostScript-format. Detta görs med kommandot dvips rapport
Den nyskapade filen rapport.ps kan skrivas ut med kommandot lpr rapport.ps
Följande tecken är reserverade i LaTeX : $ &
% # _ { }
~ ^ och \.
Dessa kan användas i text om man skriver "backslash" \ före, ex: \&
LaTeX-kommandon är känsliga för om de ingående tecknena är
versaler eller gemener.
Det finns två format på kommandon :
En typisk mall för ett LaTeX-dokument ser ut så här:
\documentclass{....} \begin{document} Här skriver man text.... \end{document}
Ett LaTeX-dokument börjar alltid med kommandot
\documentclass{....}
som anger vilken dokumenttyp man vill ha.
Det finns fyra olika dokumenttyper:
Ex:
\documentclass{article}
Textmassan inleds med kommandot
\begin{document}
och avslutas med
\end{document}
Det finns ett näst intill oändligt antal kommandon och tillägg till LaTeX,
och det är givetvis omöjligt att lära sig allt. Man får helt enkelt
lära sig det man själv tycker är användbart för stunden. Förutom ett
flertal olika böcker finns givetvis resurser på internet:
Djungeldatas sida om LaTeX:
LaTeX@DjungelData
En mycket bra sida med mycket info. Laddat ner lshort.ps:
The not so Short
Introduction to LaTeX
Nedan finns tre exempel på LaTeX-kod och färdiga resultat där man hittar
användbara kommandon. För att ni ska kunna skriva en rapport bör ni bland
annat kunna göra följande :
LYCKA TILL !!
% This is a small sample LaTeX input file (Version of 10 April 1994) % % Use this file as a model for making your own LaTeX input file. % Everything to the right of a % is a remark to you and is ignored by LaTeX. % The Local Guide tells how to run LaTeX. % WARNING! Do not type any of the following 10 characters except as directed: % & $ # % _ { } ^ ~ \ \documentclass{article} % Your input file must contain these two lines \begin{document} % plus the \end{document} command at the end. \section{Simple Text} % This command makes a section title. Words are separated by one or more spaces. Paragraphs are separated by one or more blank lines. The output is not affected by adding extra spaces or extra blank lines to the input file. Double quotes are typed like this: ``quoted text''. Single quotes are typed like this: `single-quoted text'. Long dashes are typed as three dash characters---like this. Emphasized text is typed like this: \emph{this is emphasized}. Bold text is typed like this: \textbf{this is bold}. \subsection{A Warning or Two} % This command makes a subsection title. If you get too much space after a mid-sentence period---abbreviations like etc.\ are the common culprits)---then type a backslash followed by a space after the period, as in this sentence. Remember, don't type the 10 special characters (such as dollar sign and backslash) except as directed! The following seven are printed by typing a backslash in front of them: \$ \& \# \% \_ \{ and \}. The manual tells how to make other symbols. \end{document} % The input file ends with this command.
% This is a sample LaTeX input file. (Version of 11 April 1994.) % % A '%' character causes TeX to ignore all remaining text on the line, % and is used for comments like this one. \documentclass{article} % Specifies the document class % The preamble begins here. \title{An Example Document} % Declares the document's title. \author{Leslie Lamport} % Declares the author's name. \date{January 21, 1994} % Deleting this command produces today's date. \newcommand{\ip}[2]{(#1, #2)} % Defines \ip{arg1}{arg2} to mean % (arg1, arg2). %\newcommand{\ip}[2]{\langle #1 | #2\rangle} % This is an alternative definition of % \ip that is commented out. \begin{document} % End of preamble and beginning of text. \maketitle % Produces the title. This is an example input file. Comparing it with the output it generates can show you how to produce a simple document of your own. \section{Ordinary Text} % Produces section heading. Lower-level % sections are begun with similar % \subsection and \subsubsection commands. The ends of words and sentences are marked by spaces. It doesn't matter how many spaces you type; one is as good as 100. The end of a line counts as a space. One or more blank lines denote the end of a paragraph. Since any number of consecutive spaces are treated like a single one, the formatting of the input file makes no difference to \LaTeX, % The \LaTeX command generates the LaTeX logo. but it makes a difference to you. When you use \LaTeX, making your input file as easy to read as possible will be a great help as you write your document and when you change it. This sample file shows how you can add comments to your own input file. Because printing is different from typewriting, there are a number of things that you have to do differently when preparing an input file than if you were just typing the document directly. Quotation marks like ``this'' have to be handled specially, as do quotes within quotes: ``\,`this' % \, separates the double and single quote. is what I just wrote, not `that'\,''. Dashes come in three sizes: an intra-word dash, a medium dash for number ranges like 1--2, and a punctuation dash---like this. A sentence-ending space should be larger than the space between words within a sentence. You sometimes have to type special commands in conjunction with punctuation characters to get this right, as in the following sentence. Gnats, gnus, etc.\ all % `\ ' makes an inter-word space. begin with G\@. % \@ marks end-of-sentence punctuation. You should check the spaces after periods when reading your output to make sure you haven't forgotten any special cases. Generating an ellipsis \ldots\ % `\ ' is needed after `\ldots' because TeX % ignores spaces after command names like \ldots % made from \ + letters. % % Note how a `%' character causes TeX to ignore % the end of the input line, so these blank lines % do not start a new paragraph. % with the right spacing around the periods requires a special command. \LaTeX\ interprets some common characters as commands, so you must type special commands to generate them. These characters include the following: \$ \& \% \# \{ and \}. In printing, text is usually emphasized with an \emph{italic} type style. \begin{em} A long segment of text can also be emphasized in this way. Text within such a segment can be given \emph{additional} emphasis. \end{em} It is sometimes necessary to prevent \LaTeX\ from breaking a line where it might otherwise do so. This may be at a space, as between the ``Mr.'' and ``Jones'' in ``Mr.~Jones'', % ~ produces an unbreakable interword space. or within a word---especially when the word is a symbol like \mbox{\emph{itemnum}} that makes little sense when hyphenated across lines. Footnotes\footnote{This is an example of a footnote.} pose no problem. \LaTeX\ is good at typesetting mathematical formulas like \( x-3y + z = 7 \) or \( a_{1} > x^{2n} + y^{2n} > x' \) or \( \ip{A}{B} = \sum_{i} a_{i} b_{i} \). The spaces you type in a formula are ignored. Remember that a letter like $x$ % $ ... $ and \( ... \) are equivalent is a formula when it denotes a mathematical symbol, and it should be typed as one. \section{Displayed Text} Text is displayed by indenting it from the left margin. Quotations are commonly displayed. There are short quotations \begin{quote} This is a short a quotation. It consists of a single paragraph of text. See how it is formatted. \end{quote} and longer ones. \begin{quotation} This is a longer quotation. It consists of two paragraphs of text, neither of which are particularly interesting. This is the second paragraph of the quotation. It is just as dull as the first paragraph. \end{quotation} Another frequently-displayed structure is a list. The following is an example of an \emph{itemized} list. \begin{itemize} \item This is the first item of an itemized list. Each item in the list is marked with a ``tick''. You don't have to worry about what kind of tick mark is used. \item This is the second item of the list. It contains another list nested inside it. The inner list is an \emph{enumerated} list. \begin{enumerate} \item This is the first item of an enumerated list that is nested within the itemized list. \item This is the second item of the inner list. \LaTeX\ allows you to nest lists deeper than you really should. \end{enumerate} This is the rest of the second item of the outer list. It is no more interesting than any other part of the item. \item This is the third item of the list. \end{itemize} You can even display poetry. \begin{verse} There is an environment for verse \\ % The \\ command separates lines Whose features some poets % within a stanza. will curse. % One or more blank lines separate stanzas. For instead of making\\ Them do \emph{all} line breaking, \\ It allows them to put too many words on a line when they'd rather be forced to be terse. \end{verse} Mathematical formulas may also be displayed. A displayed formula is one-line long; multiline formulas require special formatting instructions. \[ \ip{\Gamma}{\psi'} = x'' + y^{2} + z_{i}^{n}\] Don't start a paragraph with a displayed equation, nor make one a paragraph by itself. \end{document} % End of document.
\documentclass[a4paper,11pt]{article} \usepackage[dvips]{graphicx} \usepackage[swedish]{babel} \begin{document} \selectlanguage{swedish} % %----------------------------------------------------------------------- % \section*{Mitt roligaste datorintroduktionsminne} % Hej Martin! \\ \\ Jag uppskattar verkligen datorintroduktionen, speciellt MATLAB-laborationen var extra bra. Funktionen konstig % \begin{equation} \label{eq:konst} y = \frac{1}{(x-0.3)^{2}+0.01} + \frac{1}{(x-0.9)^{2}+0.04} - 6 \end{equation} % har ett lustigt utseende, vilket illustreras i Fig.~\ref{fig:konst}, men jag tycker att $\sin(\theta)$ verkar roligare. % \begin{figure}[htbp] \begin{center} \includegraphics[width=0.9\textwidth]{konstig.eps} \caption{Funktionen konstig, se Ekv.~(\ref{eq:konst}).} \label{fig:konst} \end{center} \end{figure} % Vilket fysikaliskt problem beskriver konstig? Kordinaterna f\"or funktionens lokala maxima och minima ges i Tab.~\ref{tab:konst}. % \begin{table}[htbp] \begin{center} \caption{Funktionen konstigs extrempunkter.} \begin{tabular}{c r@{,}l r@{,}l} \hline\hline Extrempunkt & \multicolumn{2}{c}{$x$} & \multicolumn{2}{c}{$y$} \\ \hline maxima & 0&3004 & 96&5014 \\ minima & 0&6370 & 11&2528 \\ maxima & 0&8927 & 21&7346 \\ \hline\hline \end{tabular} \label{tab:konst} \end{center} \end{table} Jag avslutar med sex svenska tecken: \\ {\aa}, \"a, \"o, {\AA}, \"A, \"O. % \end{document}