Copyright (C) 2007 by Steve Litt, All rights reserved. Material provided as-is, use at your own risk.
hello world |
[slitt@mydesk lyx]$ tex hello_tex.tex |
dvips -o hello_tex.ps hello_tex.dviIf you have a postscript printer, it will directly print the .ps file, but for other printers you need to further convert it to a .pdf file:
ps2pdf hello_tex.psHere's a diagram of this process:
\font\normfont = cmbx12 |
To the left is an example TeX file using fonts, indentation, a header, and vertical skipping. First we define several fonts (normfont, bigfont and titlefont). Then we create a one line header with \headline. The header has a page number on the left, a large title in the center, and the author on the right. See the two \hfil commands? They act like compressed air, pushing elements away from each other. That's how you can left, center and right align the three components. The text of the file starts with the first paragraph, which uses normfont, a 12 point font. The first paragraph's margins are shrunken 1.5 inches on each side (\leftskip 1.5in\rightskip 1.5in). The second paragraph uses bigfont, a monstrous 18 pointer. This paragraph has the normal margins (\leftskip 0in\rightskip 0in). The word "always" in the second paragraph is italic, because of the \it inside of a block delimitated by curly braces. Intuitively one would assume the current font would be italicized, but in fact it replaces the current font with the document's default font, italicized, hence the smallness. The paragraphs that follow are just filler so you can see that the header shows up on page 2 also, and the page number changes. Note that subsequent paragraphs are separated not by blank lines, but by \vskip commands. The switch from horizontal commands (the letters) to a vertical command (\vskip) ends the paragraph. |
\font\normfont = cmbx14 |
To the left is code to write a
short essay on musicians, athletes and intellectuals, complete with
correctly numbered sections and subsections. The code starts out by
defining four fonts that will be used throughout. It then declares and
initializes three global variables, sectno, subsectno and secttext. sectno and subsectno are counts, while technically secttext is a macro because it's comprised of commands, even though those commands are just letters. The header, created with a \headline command, shows the header name (\secttext) and the page number. The heart of this document is the \section macro and the \subsection macro. Both print their argument (#1), but in addition they also increment and print their respective counters. The \section macro also zeros out the subsection counter, because generally speaking subsections are subservient to sections and therefore should restart upon section change. Subsection numbers are printed in the section.subsection format. Below the \subsection definition, the actual text of the document begins. You'll notice that thanks to the header and macros, writing of the document itself is rather straightforward. This example, while understandable, doesn't even begin to scratch the surface of TeX macro capabilities. You'll notice that \section and \subsection commands automatically terminate the macro that came before, so there's no necessity to insert a blank line, although blank line insertion would neither harm nor change anything, but simply make the source more readable. To see how this works, copy and paste the code to the left into a file, and compile the file with TeX. The first page looks like this: ![]() As you can see, sections print their section numbers and then the section name, which is an argument sent from the main document. Subsections print the section number in section.subsection format, and then the name. If you compile the source to the left and look at all pages, you'll see that the header of each page contains the section name of the section in force at the bottom of the page. |
\documentclass[12pt]{article} |
\newenvironment{environment_name}{stuff to do before text}{stuff to do after text}
|
|
||||
Trait | LaTeX
(command mode) |
LaTeX
(argument mode) |
Default? | Comment |
Family | \rmfamily | \textrm{text} | Default | Roman |
\sffamily | \textsf{text} | Sans Serif | ||
\ttfamily | \texttt{text} | Teletype (monospaced) | ||
Series | \mdseries | \textmf{text} | Default | Normal weight |
\bfseries | \textbf{text} | Bold | ||
Shape | \upshape | \textup{text} | Default | Upright |
\itshape | \textit{text} | Italics | ||
\slshape | \textsl{text} | Slanted | ||
\scshape | \textsc{text} | Small caps | ||
Size | \tiny | |||
\scriptsize | ||||
\footnotesize | ||||
\small | ||||
\normalsize | Default | |||
\large | ||||
\Large | ||||
\LARGE | ||||
\huge | ||||
\Huge |
\newcommand{\tweak}[2]{ |
The new command on the left prints the command's first argument centered in huge print, then skips 0.3 inches and prints the second argument in normal print. Centering is removed at the end. |
\tweak{Why?}{or why not?}In LaTeX, an environment is an entity that happens over a range of text. A new environment is created like this:
\newcommand{\tweak}[2]{ |
The new command on the left prints the command's first argument centered in huge print, then skips 0.3 inches and prints the second argument in normal print. Centering is removed at the end. |
\let\oldtweak = \tweak
|
The first thing we do is store the old \tweak command, because we want to tack something on before it. Then we use \renewcommand to change it, throw up a dotted line, and then execute the old command. |
\let\oldtweak = \tweak |
Here we call \oldtweak before making the dotted line. Note that we need the \par after the call to \oldtweak in order to make it work right. In general, if something doesn't work right, try a \par after every line that should be a paragraph on its own. Experiment. |
\let\oldtweak = \tweak |
Here we do the dotfill before and after the old command. |
\let\oldtweak = \tweak |
Here you increase the number of arguments for command \tweak (#3), and then call \oldtweak, which has only two argument, using a concatination with fill for the old command's arg2. |
\let\oldbreakoutbox = \breakoutbox % Save old environment |
The first two statements save the old environment. Note that
the second statement is a piece of fantastic magic that saves the
executable part of the original end -- in this case the printing of
dots. You must prepend the word "end" to each variable. Yes, I know \endoldbreakoutbox is never used again, but internally the macros call it. We begin by slanting the text, then running the old environment beginning, switching back to upright shape, then adding the subtitle (centered and large), and adding a skip below the subtitle, after which the range of text is printed. The ending features the printing of a line of dots, and then the original end of environment formatting. |
DANGER:
POTENTIAL DEBUGGING NIGHTMARE See these two lines: Both lines are vital, and their variables must be named **EXACTLY**!!!! Yes, I'm shouting. Even though you never see the \endoldbreakoutbox variable mentioned again, it must be assigned the value of \endbreakoutbox, because the \end{oldbreakoutbox} command secretly accesses \endoldbreakoutbox in the bowels of LaTeX. In general, if you're modifying an environment called \myenv, then those two lines should look like this: \let\oldmyenv = \myenv |
#% Do not delete the line below; configure depends on this |
Remember: Layout files or symlinks to them must be in the .lyx/layouts directory below your home directory. I use symlinks myself. The second line is a LyX comment, but a special one that declares the document class of this layout, gives it the name tarticle, and declares that it's based on the article document class, meaning that it's identical to article except for what's changed, which in this case is the addition of the LyX storylyx environment. Next, a LaTeX file called stdclass.inc is included. This file contains some LyX (not LaTeX) code, and also contains several other input statements to include several other files. The vast majority of those files contain only LyX code, no LaTeX. One, lyxmacros.inc, contains a little bit of LaTeX to go along with the LyX commands and environments it defines. Back to tarticle.layout . All LaTeX code must be contained within a Preamble/EndPreamble pair. In this case, the LaTeX is simply the story environment coded in the LaTeX Story Exercise earlier in this document. The only change is I reduced the margins by 1/2 on each side so that the story environment wouldn't be squeezed too tight. Outside the Preamble/EndPreamble pair goes the LyX code, which is primarily expressed as styles. Each style occurs within a Style/End pair. The LyX code within a style primarily does performs two tasks:
It is possible to place a Preamble/EndPreamble pair within a Style/End pair. In such case, the Preamble/EndPreamble pair typically defines the LaTeX environment to which the LyX style is a wrapper. The theory is that you have all code for the LyX style in one place. I don't like doing it that way, because there are too many places where you switch between LyX and LaTeX, and it ends up confusing. |