Home
Main website
Display Sidebar
Hide Ads
Recent Changes
View Source:
LatexExample
Edit
PageHistory
Diff
Info
LikePages
This is a short worked example on how to write and build a [LaTeX] document. ''Note that this is not a primer on the language!'' You should get hold of the [Not so short Introduction to Latex|http://www.ctan.org/tex-archive/info/lshort/english/lshort.pdf] for a more complete introduction. !! Writing your <tt>.tex</tt> file Because this is just a trivial example on how to use [LaTeX], not on how to actually write [LaTeX] documents, my example <tt>.tex</tt> file won't contain a lot. [LaTeX] can do plenty more than I'm demonstrating below -- make sure you read the better references mentioned above. Edit a file called <tt>example.tex</tt>, and put the following text in it: <verbatim> \documentclass[12pt,a4paper]{report} \pagenumbering{roman} \title{Latex Example} \author{Daniel Lawson} \date{\today} \begin{document} \maketitle \begin{abstract} \end{abstract} \tableofcontents \newpage \section{Introduction} This is a quick introduction to using Latex. \subsection{Example} Here is a subsection. \section{Conclusion} In conclusion, this example doesn't show a lot. Go read the Not So Short Introduction to \LaTeX for more information. \end{document} </verbatim> !! Building it Seeing as we're not doing anything complicated with [LaTeX], we only need to parse the file once. If you were doing more complicated things, such as including a bibliography, you'd need to run a few more programs. See LatexMakefiles on more tips for that. Run <tt>latex example.tex</tt> in the directory you saved your <tt>example.tex</tt> in earlier. <verbatim> $ latex example.tex This is TeX, Version 3.14159 (Web2C 7.3.7) (./example.tex LaTeX2e <2001/06/01> Babel <v3.7h> and hyphenation patterns for american, french, german, ngerman, n ohyphenation, loaded. (/usr/share/texmf/tex/latex/base/report.cls Document Class: report 2001/04/21 v1.4e Standard LaTeX document class (/usr/share/texmf/tex/latex/base/size12.clo)) No file example.aux. [1] [1] No file example.toc. [1] [2] (./example.aux) ) Output written on example.dvi (4 pages, 1180 bytes). Transcript written on example.log. </verbatim> This completed successfully, outputting some extra files created by [LaTeX] on the way -- the <tt>.aux</tt> and <tt>.toc</tt> files are used for internal references. The <tt>.dvi</tt> file is the first output file. You can view this with a program called xdvi: <verbatim> xdvi example.dvi </verbatim> !! Making it useful DVI is a __D__e__v__ice __I__ndependent format, which in theory makes it really useful. However, it tends to be harder to view in Certain OperatingSystem~s. Instead, you should convert your <tt>.dvi</tt> to a PostScript or [PDF] file: <verbatim> $ dvips example.dvi -o example.ps This is dvips(k) 5.86e Copyright 2001 Radical Eye Software (www.radicaleye.com) ' TeX output 2004.12.16:1220' -> example.ps $ dvipdf example.dvi example.pdf $ ls *ps *pdf example.pdf example.ps <texc.pro>. [1] [1] [1] [2] </verbatim> You can now view these with a PostScript or [PDF] viewer, such as GhostView or AcrobatReader. ---- !!! Dates and times The ~LaTeX command <code>\today</code> prints the date that the document is processed in a format determined by your language settings. There is a time record, but this gives the number of minutes since midnight and this isn't particularly useful in itself. !! Solutions There are a number of ways to include the current time in your document. In order of potential usefulness they are: ! Using the <code>datetime</code> package The [datetime|http://www.ctan.org/tex-archive/macros/latex/contrib/datetime/] package provides commands for not only easily reformatting the date but for printing the time in several formats. ! Inserting your own time calculation code in the document The most satisfying approach for a coder. Programming in ~TeX is an interesting challenge. The following code (included in a ~LaTeX file preamble) can be used to print the time in 24-hour format: <pre> \newcount\c@HOUR \newcount\c@FINALHOUR \newcount\c@MINUTE \newcount\c@HOURSINMINUTES \newcount\@INTVAL \newcommand{\twodigit}~[1]{\@INTVAL=#1\relax\ifnum\@INTVAL<10 0\fi\the\@INTVAL} \c@FINALHOUR=\time\divide\c@FINALHOUR by 60\relax \c@HOUR=\time\divide\c@HOUR by 60\relax \c@HOURSINMINUTES=\c@HOUR\multiply\c@HOURSINMINUTES by 60\relax \c@MINUTE=\time\advance\c@MINUTE by -\c@HOURSINMINUTES\relax \def\THEHOUR{\the\c@FINALHOUR} \def\THEMINUTES{\the\c@MINUTE} % time in HH:MM (24 hour clock) \newcommand\rightnow{\twodigit{\THEHOUR}:\twodigit{\THEMINUTES}} </pre> Anywhere in the document <code>\rightnow</code> may be used to print the time the document was assembled (or more correctly, the time on the system clock when the document assembly began). ! Modifying the source <code>.tex</code> file when processing the file. Calling an editor like <code>awk</code> or <code>sed</code> to pre-process the source file is potentially popular with command-line geeks, but is rather clunky and has the feeling of a kludge about it. Not recommended.
One page links to
LatexExample
:
LaTeX