LaTeX

From miki
Revision as of 15:03, 28 November 2013 by Mip (talk | contribs) (→‎Tips / How-to)
Jump to navigation Jump to search

Reference

Related pages on this wiki
External references

Install

Ubuntu

See reference page.

sudo apt-get install texlive
sudo apt-get install texlive2html                 # To support TeX to HTML conversion
sudo apt-get install texlive-xetex                # To install XeTeX

Invocation

Basic commands for LaTeX documents (using TeXlive under Linux or MikTeX under Windows):

pdflatex <file.tex>             # Convert a .tex file directly to pdf format
latex <file.tex> 		# Convert a .tex file to .dvi file
dvips <file.dvi>		# Convert a .dvi file to .ps
dvipdfm -p a4 <filetex>		# Convert a .dvi file to .pdf (using a4 paper)

For TeX documents:

pdftex <file.tex>               # Convert a .tex directly into .pdf
tex <file.tex>                  # Convert a .tex into .dvi

For XeLaTex documents (with BibTex entries):

xelatex <file.tex>              # Generate the .aux file needed by BibTex
bibtex <file.aux>               # Process bib entries
xelatex <file.tex>              # 1st pass will generate .pdf w/o references
xelatex <file.tex>              # 2nd pass will generate .pdf w/ references

Packages

Soul

Use package soul to highlight, underline, hyphenate texts, or use small caps and change kerning, letter spacing. See documentation for details (see file soul.pdf or here).

LaTeX example:

\documentclass[a4paper]{article}
\usepackage{color,soul}

\begin{document}
Some normal text.\par
\hl{Some highlighted text.}\par
Some more normal text.
\end{document}

TeX example (requires color package from CTAN, see soul.pdf — under Ubuntu, apt-get install texlive-plain-extra):

\input color
\input soul.sty

\pdfoutput=1
\pdfpagewidth=21cm
\pdfpageheight=29.7cm

Some text here\par
\hl{Some highlighted text now}\par
Some more text\par

\bye

Troubleshooting Reconstruction error:

\hl{match of next brace, bracket, comment, \tt\#define}             % WRONG
\hl{match of next brace, bracket, comment, \tt \#define}            % CORRECT
\hl{/$s$\enter\ ?$s$\enter}                                         % WRONG
\hl{{/$s$\enter} {?$s$\enter}}                                      % CORRECT
\hl{These are {\it italic words} and these not}                     % WRONG
\hl{These are \it italic words \rm and these not}                   % CORRECT

Texlive-science

Provides style algorithmic.sty. See more here

Basic

Special characters
\# \$ \% \^{} \& \_ \{ \} \~{} \textbackslash
LaTeX Commands
\TeX{} and         % space (tx to {})
\TeX{}nicians and  % NO space
\TeX perts.        % NO space
Document class
\documentclass[options]{class}  % See manual for reference
Packages
\usepackage[options]{package}   % See manual for list of packages
Page style
\pagestyle{style}       % plain, headings, empty
\thispagestyle{style}   % for current page only
Big project
\include{filename}           % Insert content of file - LaTeX starts a new page
\includeonly{filename,...}   % (in preamble) restrict list of included files
\input{filename}             % Simply includes the file
Breaks
\\                           % Start a new line without starting a new paragraph
\newline                     % idem
\\*                          % idem, but prohibits page break after forced line break
\newpage                     %
\linebreak[n]                % Suggest LaTeX where to break (or not) page (n=0..4)
\nolinebreak[n]              %
\pagebreak[n]                %
\nopagebreak[n]              %
\sloppy                      % Tell LaTeX to relax its layout standards
\fussy                       % Reset to default layout behaviour

\sloppy might be used to fix "overfull hbox" message and line sticking out on the right of paragraphs (although usually result is not really good). Use opton draft in document class to identify these issues more easily

Templates

Smallest

\documentclass{article}
\begin{document}
Small is beautiful.
\end{document}
  • \documentclass[options]{class} takes optional paramters options, and a mandatory document class. See manual for reference.

3-columns

Example of 3-column document, minimum margin, no page numbering (see [1])

\documentclass[a4paper]{article}
% Specify paper size univocally (for pdf output)
\special{papersize=210mm,297mm}
% Set minimum margin using package geometry
\usepackage[a4paper,landscape,top=1cm, bottom=1cm, left=0.5cm, right=1cm]{geometry}
% To support 3-column document, color and highlighting 
\usepackage{multicol,color,soul}
% Remove any footer / header (page numbers...)
\pagestyle{empty}

\begin{document}
\begin{multicols}{3}
Some text here\par
Some more text there\par
And not anymore\par
\end{multicols}
\end{document}

Realistic Journal Article

\documentclass[a4paper,11pt]{article}
% define the title
\author{H.~Partl}
\title{Minimalism}
\begin{document}
% generates the title
\maketitle
% insert the table of contents
\tableofcontents
\section{Some Interesting Words}
Well, and here begins my lovely article.
\section{Good Bye World}
\ldots{} and here it ends.
\end{document}

Tips / How-to

Quick debug

  • Check syntax rapidly by using package syntonly:
\usepackage{syntonly}
\syntaxonly                  % Comment out this line to produce pages
  • Add draft to document class to identify layout issues easily:
\documentclass[draft]{article}

Remove sub-sections from header

Simplest is to use another outer theme (here infolines):

\documentclass{beamer}

\mode<presentation>
{
  \usetheme{Antibes}
% \usetheme{Hannover}
  \setbeamercovered{transparent}
% \usefonttheme{structuresmallcapsserif}
% \usefonttheme{structurebold}
 \usecolortheme{beaver}
% tree is default outertheme - but infolines is more compact
% \useoutertheme{tree}
 \useoutertheme{infolines}
}

% slidenumbering
\setbeamertemplate{footline}[frame number]
\setbeamertemplate{sidebar right}{}

Change vertical alignment

Simply use the [t] or [c] modifier (top / center). For frames:

\begin{frame}[t]{The seven permutation army}

% Top-aligned frame
\end{frame}

For columns:

\begin{columns}[t]

\begin{column}{0.35\linewidth}
% 1st top-aligned column
\end{column}

\begin{column}{0.65\linewidth}
% 2nd top-aligned column
\end{column}

\end{columns}

Troubleshoot

  • LaTeX Error: Cannot determine size of graphic (no BoundingBox)
LaTeX does not find the BoundingBox information which is necessary to produce the .dvi file. A way to fix this is either to edit the graphic to add the bounding box information, or to use pdflatex to produce directly a .pdf file.
  • Missing table of content (file *.toc not found)
This happens when the command \tableofcontents is used in the document, but LaTeX did not produce yet a table of content file. The .toc file is produced at the first invocation. To solve this, just run LaTex a second time:
pdflatex mypresentation.tex                   # produce a pdf without toc, and a toc file
pdflatex mypresentation.tex                   # produce a pdf with toc generated in the previous pass
  • "seac" character deprecated in Type 2 charstring
We get the following error from XeTeX.
** WARNING ** "seac" character deprecated in Type 2 charstring.
** ERROR ** Type2 Charstring Parser: Parsing charstring failed: (status=-1, stack=5)

Output file removed.
This happens when using OpenType fonts (OTF) with accented characters (even i counts as accented!).
The possible fixes are either to use another font, convert the font to TTF, or fix the buggy OTF.
  • Command \sups already defined.
Occurs when compiling with xelatex. See file /usr/share/texmf/tex/latex/tipa/tipa.sty, line 478.
This is apparently a conflict between tipa and fontspec in TeXLive2012 (TeXLive2009 seems ok, see [2])

Importing MS Visio Graphics in LaTeX

Method 1: Using OpenOffice Draw

This procedure creates from a Visio drawing, a PDF file that has the correct page dimension in order to be directly imported in a LaTeX document. This procedure requires to have OpenOffice Draw installed.

  • In Visio, File → Save As, select type Enhanced Metafile (.emf), enter a file name, click Save.
(Using intermediate .emf is less convenient but gives better results than Paste Special as GDI object, which sometimes modify the pasted object)
  • In OpenOffice Draw, Open the newly saved file, Select the drawing with the mouse, and then go to menu File → Export.
  • Check the box Selection, select format EPS - Encapsulated PostScript (.eps), save the file.
  • Press OK, to accept all default options (no preview, Level 2, Grayscale, no compression)
  • In a shell, type the LaTeX command
epstopdf <filename.eps>

which will create a file <filename.pdf> with the correct page size.

Limitations
Some line formats are not correctly rendered by OpenOffice Draw when exporting to EPS format.

Method 2: Using Custom PostScript Page Size

This procedure can be used to solve problem in the 1st method where some line formats are not correctly rendered in the EPS. This procedure requires to have a PDF printer installed, such as PrimoPDF.

  • In Visio, select the drawing to print, and copy-paste it into a new document.
  • Go to menu File → Page Setup
    • Go to Page Size panel
    • Select Size to fit drawing contents, and note the page size as computed by Visio
  • Go to Print Setup panel
    • Click on Printer Paper Setup
    • Click on Printer...
    • Select the PDF printer, and click on Properties...
    • Click on Advanced...
    • For Paper size, select PostScript Custom Page Size, then click on Edit Custom Page Size
    • Select unit Millimeter, and then in Width and Height, enter the same size as computed by Visio, plus 1 or 2mm.
  • Click Ok buttons until back in the Print Setup dialog. Set Left, Right, Top and Bottom margin to be 0mm, and select Center horizontally and Center vertically.
  • If necessary, move the drawing so that it fits perfectly in the middle of the page.
  • Print the document.

The result is a PDF document with the best output quality and the correct dimension.

Limitations
Sometimes text police are rasterized.

Method 2bis: Using Visio 2007

  • Go to menu File → Page Setup
    • Go to Page Size panel
    • Select Size to fit drawing contents
  • Go to menu File → Publish as PDF or XPS

Method 3: Using Postscript printer and Perl script

This method is explained here.

  • Install the Adobe Generic Postscript Driver.
  • Configure the printer to use EPS, i.e. right click on the printer → Printer Preferences... → click Advanced button → open Document Options → PostScript Options → Under PostScript Output Option, select "Encapsulated PostScript (EPS)".
  • In Visio, print your drawing to the postscript printer.
  • The bounding box is incorrectly set to the page size. To fix it, use the perl script TightBoundingBox.pl, also copied below (requires gs command from cygwin).