====== LaTeX syntax quick references ====== [ __[[vlsi:home|Home]]__ ] [ __[[vlsi:resources:latex|Back]]__ ] ====== Comments ====== % this is a comment ====== Basic document structure ====== \documentclass[options]{class type} ... ... \begin{document} ... ... \end{document} ====== How to obtain a well organized source code ====== It is possible to recall external parts of code in order to obtain a simpler and more clear structure of your main source code by using of the ''\input{}'' command. % Preamble: \documentclass[options]{class type} \usepackage{...} ... % body of your document \begin{document} \input{section_01.tex} \input{section_02.tex} \input{section_03.tex} ... \input{section_n.tex} \end{document} :!: Please note that in each .tex document (//section_01.tex//, //section_02.tex// etc.) you have __not to put__ any line just like ''\begin{document}'' or ''\end{document}'', or packages' declarations: these are just //pieces of code// recalled in your text!!! ====== Preamble ====== The portion of code within ''\documentclass'' and ''\begin{document}'' statements. Available document classes: * **article** (chapters are not supported) * **report** * **book** (two-side document by default) * **letter** Basic class options: \documentclass[a4paper,11pt]{class type} The default font sizing is ''10pt'', but you can also specify ''11pt'' or ''12pt''. ====== Core document ====== The code within ''\begin{document}'' and ''\end{document}''. ====== Extensions (packages) ====== \usepackage[options]{package name} ====== Basic formatting syntax ====== LaTex supports **bold**, //italic// etc. LaTex supports \textbf{bold}, \textit{italic} etc. You can also //**combine** all these//, You can also \textit{\textbf{combine} all these} Note that ''\textit{}'' and ''\emph{}'' produce the same italic output. Other formats: \textsl{slanted text} \texttt{typewriter text} \textsc{small caps} ====== Sectioning ====== A document can be divided using chapters, sections, subsections, sub-subsections and paragraphs. \part{name} \section{name} \subsection{name} \subsubsection{name} \paragraph{name} New paragraphs are automatically created by leaving an empty line. If you are using the ''book'' document class you can also use: \chapter{name} ====== Breaks ====== \newline \newpage \clearpage The ''\clearpage'' command is similar to ''\newpage'', but forces LaTex to print all folating tables and pictures before the page break. ====== Spacing ====== Vertical spacing: \vspace{5mm} Horizontal spacing: \hspace{8cm} Usually you will specify spaces in ''cm'' or ''mm'', but other typographic units exist. \vfill The \vfill fill command produces a rubber length which can stretch or shrink vertically. It is equivalent to a blank line followed by \vspace\fill. ====== Alignment ====== \begin{center} ... \end{center} \begin{flushright} ... \end{flushright} \begin{flushleft} ... \end{flushleft} ====== Pictures ====== First you need to declare the package in your preamble: \usepackage{graphicx} Then you could use this code in order to insert an image __in the same path__ of your file .tex (otherwise you have to specificate __the whole path__ and not only the name of your picture): \begin{figure}[options] \centering \includegraphics[angle=-90,scale=0.80,keepaspectratio=true]{pipe.jpg} \caption{Ceci n'est pas une pipe - This is not a pipe (Magritte).} \label{fig: pipe} \end{figure} Environment ''figure'' options: * **h** - here * **t** - top of the page * **b** - bottom of the page * **p** - extra page * **!** - force positioning ''includegraphics'' main options: * angle=[+/- degree values] * scale=[value] (i.e. 0.80 means that you are resizing your picture at the 80%) * keepaspectratio=[true/false] You can refer to a picture in your text by using the \ref{labelcontents}, i.e.: \ref{fig: pipe} See also: * [[http://www.guit.sssup.it/downloads/fig_tut.pdf|Gestione di Figure e Tabelle con LaTeX [IT]]] * [[http://www.guit.sssup.it/latex/figure.php|Figure in LaTeX: una breve introduzione [IT]]] * [[http://www.farstar.it/latex/immagini.php|Guida a LaTeX Immagini [IT]]] * [[http://www.kwasan.kyoto-u.ac.jp/solarb6/usinggraphicx.pdf|How to Use the graphicx Package [EN]]] * [[http://en.wikibooks.org/wiki/LaTeX/Floats,_Figures_and_Captions|LaTeX/Floats, Figures and Captions [EN]]] * [[http://ctan.org/pkg/graphicx|CTAN - graphicx – Enhanced support for graphics[EN]]] ====== Tables ====== Simple tables: \begin{tabular}{|l|c|r|} % 'l' is for 'left', 'c' is for 'center', 'r' is for 'right' \hline first & second & third \\ \hline 1 & 2 & 3 \\ \hline \end{tabular} See also: * [[http://mnnugm.altervista.org/latex/Tabelle.pdf|Tabelle con LaTeX [IT]]] * [[http://wwwcdf.pd.infn.it/AppuntiLinux/a2550.htm|LaTeX: tabelle [IT]]] * [[http://www.guit.sssup.it/downloads/fig_tut.pdf‎|Gestione di Figure e Tabelle con LATEX - GuIT [IT]]] * [[http://www.lorenzopantieri.net/LaTeX_files/TabelleRipartite.pdf|L'arte di ripartire una tabella su più pagine con LaTeX [IT]]] * [[http://www.tug.org/pracjourn/2007-1/mori/mori.pdf‎|Tables in LaTeX: packages and methods [EN]]] * [[http://en.wikibooks.org/wiki/LaTeX/Tables|LaTeX/Tables (WikiBooks) [EN]]] ====== Math formulas ====== If you want to obtain some mathematical text without using some special packages directly in your text: $ e^{i\pi}+1=0 $ \begin{math} \vec{F} = m \vec{a}\end{math} \S = \int{L \: dt} \) $ \lim_{x \rightarrow \infty} \frac{\sin{x}}{x} = 1 $ ... or in a different text block: \begin{displaymath}e^{i\pi}+1=0 \end{displaymath} \[\vec{F} = m \vec{a}\] $$S = \int{L \: dt} $$ ... or in a different block of text with the number of the equation flagged: \begin{equation}\lim_{x \rightarrow \infty} \frac{\sin{x}}{x} = 1 \end{equation} Some utilities: * [[http://www.codecogs.com/latex/eqneditor.php|LaTeX Equation online generator]] * [[http://www.texify.com/|TeXify]] See also: * [[http://kogler.wordpress.com/2008/03/21/latex-multiline-equations-systems-and-matrices/|Multiline equations, matrices, etc. [EN]]] * [[http://www.math.tamu.edu/~harold.boas/courses/math696/LaTeX-formatting-equations.html|Formatting equations in LaTeX [EN]]] * [[ftp://ftp.ams.org/ams/doc/amsmath/short-math-guide.pdf|Short Math Guide for LaTeX [EN]]] * [[http://www.guit.sssup.it/arstexnica/download_ars/articoli_ars_08/Simboli%20matematici%20in%20TEX%20e%20LATEX.pdf|Simboli matematici in TeX e LaTeX [IT]]] * [[http://wwwcdf.pd.infn.it/AppuntiLinux/a2552.htm|LaTeX: ambienti matematici [IT]]] ====== Coding ====== If you want to add some code listings into your text you can use the ''listings'' package putting \usepackage{listings} in your preamble. Then you can define some setting for your code; for instance: \lstset{ language=VHDL, numbers=left, numberstyle=\tiny, stepnumber=1, basicstyle=\small\ttfamily, keywordstyle=\color{red}\bfseries, commentstyle=\color{blue}, stringstyle=\color{green}, showstringspaces=false} The listings package supports highlighting of all the most common languages and it is highly customizable. \begin{lstlisting}[frame=lines] entity eqcomp is port (a, b: in bit_vector (3 downto 0); eq, neq : out bit); end eqcomp; architecture dataflow of eqcomp is signal aux1 : bit; begin neq <= not aux1; -- low active aux1 <= ‘1’ when (a = b) else ‘0’; eq <= aux1; end dataflow; \end{lstlisting} You can find [[http://en.wikibooks.org/wiki/LaTeX/Source_Code_Listings#Supported_languages|here]] the complete list of the supported languages. See also: * [[http://www.lorenzopantieri.net/LaTeX_files/Codici.pdf|L'arte di scrivere codici con LaTeX [IT]]] * [[ftp://ftp.tex.ac.uk/tex-archive/macros/latex/contrib/listings/listings.pdf|The Listings Package [EN]]] * [[http://kar2905.wordpress.com/2010/03/23/installing-listings-package-for-latex/|Installing Listings Package for LaTeX]] * [[http://en.wikibooks.org/wiki/LaTeX/Source_Code_Listings|LaTeX/Source Code Listings (WikiBooks) [EN]]] * [[http://www.ctan.org/pkg/listings|CTAN listings – Typeset source code listings using LATEX [EN]]] ====== Non-formatted text ====== Verbatim environment permits to insert large sections of preformated text in a LaTeX file (for example, also symbols like '%', '&', '#' and much more): \begin{verbatim} Roses are #FF0000 & violets are #0101DF sugar is sweet and so are you. \end{verbatim} ====== Graphs ====== See: * [[http://www.math.ufl.edu/~mgluck/GraphingInLatex.pdf|Graphing in LATEX using PGF and TikZ]] * [[http://www.grad.iit.edu/latex/LaTeX/FigureHelp1.pdf|Creating Figures and Graphs with LaTeX]] * [[http://www.texample.net/tikz/examples/tag/graphs/|Examples]] ====== Feynman diagrams ====== See: * [[http://adamgetchell.blogspot.it/2012/09/feynman-diagrams-in-latex.html|Feynman diagrams in LaTeX]] * [[http://xml.web.cern.ch/XML/textproc/feynmf.html|Drawing Feynman Diagrams with LaTeX and METAFONT (or METAPOST)]] * [[http://www.fi.infn.it/pub/tex/doc/orig/fmfman.pdf|Drawing Feynman Diagrams with LATEX andMETAFONT]] * [[http://osksn2.hep.sci.osaka-u.ac.jp/~taku/osx/feynmp.html|feynMF/feynMP - Drawing Feynman Diagram]] * [[http://osksn2.hep.sci.osaka-u.ac.jp/~taku/osx/fmfsamples.pdf|Examples]] ====== Table of contents ====== A table of contents (TOC) is automatically created using the command \tableofcontents Note that two consecutive compilation are required to update the table of contents Other similar commands are ''\listoftables'' and ''\listoffigures'' which produce a list of tables (LOT) and a list of figures (LOF) respectively. ====== Supported Languages ====== \usepackage[languages]{babel} \selectlanguage{choosenlanguage} i.e. \usepackage[italian, english]{babel} \selectlanguage{english} ====== Numerical references ====== To create references inside your text, use the ''\cite{refLabel}'' command wherever you want an external reference to something (books, papers, Web sites, etc.). It is a good practice to use the surname of the first author followed by the last two digits of the year of publication. Each reference will be numbered and each citation will correspond to the number. Then you can build a **bibliography** with the LaTex built-in environment ''thebibliography'', \begin{thebibliography}{n} \bibitem[label]{refKey} Author(s), \emph{Work title}, detailed reference coordinates ... ... \end{thebibliography} Here ''{n}'' is the maximum number of expected references in the list, usually ''{100}'' works fine. This parameter is mandatory (compile error otherwise). By default the name of the page will be //Bibliography//. If you want to change it in //References// use \renewcommand{\bibname}{References} % print "References" instead of "Bibliography" \begin{thebibliography}{n} ... ... \end{thebibliography} Furthermore, by default the bibliography is not automatically added to the table of contents. \clearpage \addcontentslin{toc}{chapter}{References} \renewcommand{\bibname}{References} \begin{thebibliography}{100} ... ... \end{thebibliography} Each item of the bibliography is referenced with a number within square brackets. You can assign custom labels to your reference indeed, simply add the ''[label]'' option in ''\bibitem'', e.g. \bibitem[Krummenacher, 1991]{Krummenacher1991} F. Krummenacher, \emph{Pixel detectors with local intelligence}, NIM A305, 1991, 527-532 As an alternative you can use a **BibTex** database. See [[http://www.bibtex.org/]]. ====== Harvard referencing ====== Use the ''natbib'' package. Add \usepackage[option(s)]{natbib} in your preamble. To create references you can use different versions of the basic ''\cite{}'' command to display the type of citation you want. Common options: * ''round'' round parenthesis () * ''square'' square parentheses [] * ... ====== ====== \\ ---- Last update: [[panati@to.infn.it|Serena Panati]] Nov 6th, 2013 // ~~NOTOC~~