Modifica questa pagina Puntano qui Rename Page Fold/unfold all ====== LaTex syntax quick references ====== [ __[[vlsi:home|Home]]__ ] [ __[[vlsi:resources:latex|Back]]__ ] ====== Comments ====== <code> % this is a comment </code> ====== Basic document structure ====== <code> \documentclass[options]{class type} ... ... \begin{document} ... ... \end{document} </code> ====== 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: <code> \documentclass[a4paper,11pt]{class type} </code> 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) ====== <code> \usepackage[options]{package name} </code> ====== Basic formatting syntax ====== LaTex supports **bold**, //italic// etc. <code> LaTex supports \textbf{bold}, \textit{italic} etc. </code> You can also //**combine** all these//, <code> You can also \textit{\textbf{combine} all these} </code> Note that ''\textit{}'' and ''\emph{}'' produce the same italic output. Other formats: <code> \textsl{slanted text} \texttt{typewriter text} \textsc{small caps} </code> ====== Sectioning ====== A document can be divided using chapters, sections, subsections, sub-subsections and paragraphs. <code> \part{name} </code> <code> \section{name} </code> <code> \subsection{name} </code> <code> \subsubsection{name} </code> <code> \paragraph{name} </code> New paragraphs are automatically created by leaving an empty line. If you are using the ''book'' document class you can also use: <code> \chapter{name} </code> ====== Breaks ====== <code> \newline </code> <code> \newpage </code> <code> \clearpage </code> The ''\clearpage'' command is similar to ''\newpage'', but forces LaTex to print all folating tables and pictures before the page break. <code> \vfill </code> 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. ====== Spacing ====== Vertical spacing: <code> \vspace{5mm} </code> Horizontal spacing: <code> \hspace{8cm} </code> Usually you will specify spaces in ''cm'' or ''mm'', but other typographic units exist. ====== Alignment ====== <code> \begin{center} ... \end{center} </code> <code> \begin{flushright} ... ... \end{flushright} </code> <code> \begin{flushleft} ... ... \end{flushleft} </code> ====== Pictures ====== First you need to declare the package in your preamble: <code> \usepackage{graphicx} </code> 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): <code> \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} </code> 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.: <code> \ref{fig: pipe} </code> 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 ====== ====== Math formulas ====== ====== Graphs ====== ====== Coding ====== If you want to add some code listings into your text you can use the ''listings'' package putting <code> \usepackage{listings} </code> in your preamble. Then you can define some setting for your code; for instance: <code> \lstset{ language=VHDL, numbers=left, numberstyle=\tiny, stepnumber=1, basicstyle=\small\ttfamily, keywordstyle=\color{red}\bfseries, commentstyle=\color{blue}, stringstyle=\color{green}, showstringspaces=false} </code> The listings package supports highlighting of all the most common languages and it is highly customizable. <code> \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} </code> 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): <code> \begin{verbatim} Roses are #FF0000 & violets are #0101DF sugar is sweet and so are you. \end{verbatim} </code> ====== Feynman diagrams ====== ====== Table of contents ====== A table of contents (<nowiki>TOC</nowiki>) is automatically created using the command <code> \tableofcontents </code> 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. ====== 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'', <code> \begin{thebibliography}{n} \bibitem[label]{refKey} Author(s), \emph{Work title}, detailed reference coordinates ... ... \end{thebibliography} </code> 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 <code> \renewcommand{\bibname}{References} % print "References" instead of "Bibliography" \begin{thebibliography}{n} ... ... \end{thebibliography} </code> Furthermore, by default the bibliography is not automatically added to the table of contents. <code> \clearpage \addcontentslin{toc}{chapter}{References} \renewcommand{\bibname}{References} \begin{thebibliography}{100} ... ... \end{thebibliography} </code> 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. <code> \bibitem[Krummenacher, 1991]{Krummenacher1991} F. Krummenacher, \emph{Pixel detectors with local intelligence}, NIM A305, 1991, 527-532 </code> As an alternative you can use a **BibTex** database. See [[http://www.bibtex.org/]]. ====== Harvard referencing ====== Use the ''natbib'' package. Add <code> \usepackage[option(s)]{natbib} </code> 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 1st, 2013 // ~~NOTOC~~