Feeds:
Posts

## Archive for the ‘LaTeX’ Category

On a previous post I described how to change the LaTeX options of the Cadabra notebook.

I collaborate with a colleague, who uses the standard cadabra installation. Therefore, If I write a Cadabra notebook, he needs to pullback the personalised notebook to the standard one. The pullback script can be downloaded here!!!

Created: 2014-02-18 Tue 20:20

Emacs 24.3.1 (Org mode 8.2.5h)

Validate

Just by playing around with CADABRA, I found out the existence of a super-useful LaTeX package, called breqn, which allows to break long equations at the edge of the page… like the wraping feature of most text editors.

However, when one manipulates really long expressions, I’d like to break these long equations through the page. I’m still looking for this feature… in that case I can improve even more the behaviour of cadabra‘s notebook, when compiling it to LaTeX.

Any suggestions???

Cheers!

Goal: a cadabra notebook more LaTeX friendly.

1. I run a Debian system. Don’t know why, but the original source code in the git repo didn’t work!!!What did I do? I downloaded the code from the Debian repository.
$sudo apt-get build-dep cadabra # Install all dependences$ mkdir -p ~/Software # Create a folder to download the source
$cd ~/Software # Move to the folder$ apt-get source cadabra # Download the source code (from Debian)
2. On the cadabra folder created through the last command line, I looked for the window.cc file and open it
$emacs cadabra-1.29/gui/window.cc & 3. On the window.cc file I changed: • The LaTeX package color by the improved xcolor, by changing the string << "\\usepackage[usenames]{color}\n" by << "\\usepackage{xcolor}\n" • I added the LaTeX package listings, which improves the verbatim properties (among other things). Right after the mentioned xcolor line, I added the following << "\\usepackage{listings}\n" << "\\lstset{\n" << " basicstyle=\\small\\color{blue}\\ttfamily,\n" << " breaklines=true,\n" << " columns=fullflexible,\n" << " commentstyle=\\color{gray!60},\n" << " morecomment=[l]{\\%\\%},\n}" This allows the Cadabra code to break at the end of the line instead of going out of the page, when compiled to LaTeX (similar to what breqn does on equations). • Now, I changed on the DataCell::c_input: case,1 the strings {\\color[named]{Blue}\\begin{verbatim}\n by \\begin{lstlisting}\n, and \n\\end{verbatim}}\n by \n\\end{lstlisting}\n.Far below, the lines with the code if(ln=="{\\color[named]{Blue}\\begin{verbatim}") { should be changed to if(ln=="\\begin{lstlisting}") {, as well as else if(ln=="\\end{verbatim}}") { should be changed to else if(ln=="\\end{lstlisting}") {. • Save all the changes 4. Finally, time to compile $ ./configure
$make$ sudo make install
5. If your compilation/installation went through, and you try to open an old cadabra notebook (a notebook created with the original cadabra code), the program will complain that the file is not compatible… but I created a small script to transform the old files into new files! Download it here!!USAGE:
$./transf_cadabra oldfile.cnb newfile.cnb ## Footnotes: 1This is located a few lines below the lines where the LaTeX preamble is defined Created: 2014-02-18 Tue 10:09 Emacs 24.3.1 (Org mode 8.2.5h) Validate Read Full Post » ## LaTeX Tip: Dynkin Diagrams using Tikz Hi everyone, I’ve include the code for drawing Dynkin diagrams using Tikz package in LaTeX \begin{center} \begin{tikzpicture}[scale=.4] \draw (-1,0) node[anchor=east] {$A_n$}; \foreach \x in {0,...,5} \draw[xshift=\x cm,thick] (\x cm,0) circle (.3cm); \draw[dotted,thick] (0.3 cm,0) -- +(1.4 cm,0); \foreach \y in {1.15,...,4.15} \draw[xshift=\y cm,thick] (\y cm,0) -- +(1.4 cm,0); \end{tikzpicture} \end{center} \begin{center} \begin{tikzpicture}[scale=.4] \draw (-1,0) node[anchor=east] {$B_n$}; \foreach \x in {0,...,4} \draw[xshift=\x cm,thick] (\x cm,0) circle (.3cm); \draw[xshift=5 cm,thick,fill=black] (5 cm, 0) circle (.3 cm); \draw[dotted,thick] (0.3 cm,0) -- +(1.4 cm,0); \foreach \y in {1.15,...,3.15} \draw[xshift=\y cm,thick] (\y cm,0) -- +(1.4 cm,0); \draw[thick] (8.3 cm, .1 cm) -- +(1.4 cm,0); \draw[thick] (8.3 cm, -.1 cm) -- +(1.4 cm,0); \end{tikzpicture} \end{center} \begin{center} \begin{tikzpicture}[scale=.4] \draw (-1,0) node[anchor=east] {$C_n$}; \foreach \x in {0,...,4} \draw[xshift=\x cm,thick,fill=black] (\x cm,0) circle (.3cm); \draw[xshift=5 cm,thick] (5 cm, 0) circle (.3 cm); \draw[dotted,thick] (0.3 cm,0) -- +(1.4 cm,0); \foreach \y in {1.15,...,3.15} \draw[xshift=\y cm,thick] (\y cm,0) -- +(1.4 cm,0); \draw[thick] (8.3 cm, .1 cm) -- +(1.4 cm,0); \draw[thick] (8.3 cm, -.1 cm) -- +(1.4 cm,0); \end{tikzpicture} \end{center} \begin{center} \begin{tikzpicture}[scale=.4] \draw (-1,0) node[anchor=east] {$D_n$}; \foreach \x in {0,...,4} \draw[xshift=\x cm,thick] (\x cm,0) circle (.3cm); \draw[xshift=8 cm,thick] (30: 17 mm) circle (.3cm); \draw[xshift=8 cm,thick] (-30: 17 mm) circle (.3cm); \draw[dotted,thick] (0.3 cm,0) -- +(1.4 cm,0); \foreach \y in {1.15,...,3.15} \draw[xshift=\y cm,thick] (\y cm,0) -- +(1.4 cm,0); \draw[xshift=8 cm,thick] (30: 3 mm) -- (30: 14 mm); \draw[xshift=8 cm,thick] (-30: 3 mm) -- (-30: 14 mm); \end{tikzpicture} \end{center} \begin{center} \begin{tikzpicture}[scale=.4] \draw (-1,0) node[anchor=east] {$G_2$}; \draw[thick] (0 ,0) circle (.3 cm); \draw[thick,fill=black] (2 cm,0) circle (.3 cm); \draw[thick] (30: 3mm) -- +(1.5 cm, 0); \draw[thick] (0: 3 mm) -- +(1.4 cm, 0); \draw[thick] (-30: 3 mm) -- +(1.5 cm, 0); \end{tikzpicture} \end{center} \begin{center} \begin{tikzpicture}[scale=.4] \draw (-3,0) node[anchor=east] {$F_4$}; \draw[thick] (-2 cm ,0) circle (.3 cm); \draw[thick] (0 ,0) circle (.3 cm); \draw[thick,fill=black] (2 cm,0) circle (.3 cm); \draw[thick,fill=black] (4 cm,0) circle (.3 cm); \draw[thick] (15: 3mm) -- +(1.5 cm, 0); \draw[xshift=-2 cm,thick] (0: 3 mm) -- +(1.4 cm, 0); \draw[thick] (-15: 3 mm) -- +(1.5 cm, 0); \draw[xshift=2 cm,thick] (0: 3 mm) -- +(1.4 cm, 0); \end{tikzpicture} \end{center} \begin{center} \begin{tikzpicture}[scale=.4] \draw (-1,1) node[anchor=east] {$E_6$}; \foreach \x in {0,...,4} \draw[thick,xshift=\x cm] (\x cm,0) circle (3 mm); \foreach \y in {0,...,3} \draw[thick,xshift=\y cm] (\y cm,0) ++(.3 cm, 0) -- +(14 mm,0); \draw[thick] (4 cm,2 cm) circle (3 mm); \draw[thick] (4 cm, 3mm) -- +(0, 1.4 cm); \end{tikzpicture} \end{center} \begin{center} \begin{tikzpicture}[scale=.4] \draw (-1,1) node[anchor=east] {$E_7$}; \foreach \x in {0,...,5} \draw[thick,xshift=\x cm] (\x cm,0) circle (3 mm); \foreach \y in {0,...,4} \draw[thick,xshift=\y cm] (\y cm,0) ++(.3 cm, 0) -- +(14 mm,0); \draw[thick] (4 cm,2 cm) circle (3 mm); \draw[thick] (4 cm, 3mm) -- +(0, 1.4 cm); \end{tikzpicture} \end{center} \begin{center} \begin{tikzpicture}[scale=.4] \draw (-1,1) node[anchor=east] {$E_8$}; \foreach \x in {0,...,6} \draw[thick,xshift=\x cm] (\x cm,0) circle (3 mm); \foreach \y in {0,...,5} \draw[thick,xshift=\y cm] (\y cm,0) ++(.3 cm, 0) -- +(14 mm,0); \draw[thick] (4 cm,2 cm) circle (3 mm); \draw[thick] (4 cm, 3mm) -- +(0, 1.4 cm); \end{tikzpicture} \end{center} Bye DOX Read Full Post » ## LaTeX Tip: New name after compilation If you want to compile a file, say Base.tex, and get the PDF with other name, use the -jobname option $ pdflatex -jobname MyBook Base.tex

In the example you’ll get a PDF file called MyBook.pdf

Enjoy

## Organization of LaTeX documents

When I started to write documents in $\LaTeX$, I found myself diving into .tex, .out, .aux, .pdf, .jpg files and so on. Thus I developed a system for organizing the files.

(If you are starting with $\LaTeX$ might find useful my previous post here)

## The Basic

First, I create a LaTeX folder in my personal Documents directory,

$mkdir ~/Documents/LaTeX where all my $\LaTeX$ related files have to be moved. Since I used to write a lot of reports, articles and letters, the next step is to write a template for each of them (Of course, you could use pre-defined templates, from your LaTeX editor, borrowed from a friend or downloaded from internet). As an example, I’ve defined • base-art.tex • base-rep.tex • base-PRD.tex: for articles to be send to Physical Review journal. • base-book.tex • base-beamer.tex • base-lett.tex ### More Folders Now, more folder should be created to keep files ordered. $ cd LaTeX
$mkdir Docs Pics Finished Here I’m describing just three, Docs contains the .tex files other than the base-*.tex, Pics contains all figures, and Finished is a place where you can move the PDF files when they are finished. NOTE: Clearly, you could create folders inside Docs and Pics… say, one for Geography-hw and other for Zen-Martial-arts, and so on. ### The base-*.tex File This is the file which contains the structure of the document, that is: • the class • the preamble packages, definitions and so on… • the begin and end document. but not the body content… except for the maketitle, tableofcontents, and similars. So, Where is the content? The content is written is separated tex files saved in the Docs folder. None of this files have class definitions or, package calls, or begin and end document… they have the written part, example: %%% UFO saved as UFO.tex %%% in the ~/Documents/LaTeX/Docs folder \chapter*{Introduction} In the last years, UFO activity has been increased due to the lack of faith in the world. Do you believe? \chapter{What is UFO?} UFO stands for Unidentified Flying Object \section{UFO activity} blah blah blah and this should be included into the base-rep.tex file, with the input command, \documentclass{report} \begin{document} \input{Docs/UFO.tex} \end{document} NOTE: When you want to insert a file, which is not in the same folder than the base-*.tex one, the directory to that file must be given. #### And the figures? Now, figures are part of the body, thus they are included in the UFO.tex file, suppose we want to add the figure1.jpg, then our UFO.tex should contain a line like, \includegraphics{Pics/figure1.jpg} NOTE: although UFO.tex is located in Docs folder, the figure file is referred as Pics/figure1.jpg because the compiler starts looking at the “mother” folder, a.k.a., LaTeX. ## Compiling the Thing Of course, for compiling you should type in the terminal, $ pdflatex base-rep.tex

however, the PDF document will have the same name as their parent tex file, i.e., base-rep.pdf

If you’d like to have a final PDF file with a different name, use instead,

$pdflatex -jobname UFO base-rep.tex to get a UFO.pdf file. Enjoy! DOX Read Full Post » ## Document edition with LaTeX I define myself as a $\LaTeX$ lover. I write all my documents using $\LaTeX$. In this post I’d like to review some features about $\LaTeX$ writing and compilation. Since I’m a Linux user, and don’t have any idea on how does windows work, I’ll restrict myself to Linux OS… particularly Debian based ones, such as, Ubuntu, Mint, and so on. ## Installing the Compiler The easiest way of installing the $\LaTeX$ compiler in Debian based Linux, is through the Terminal, (you should have sudoes power) $ sudo apt-get install texlive

or if you prefer to install all the possible packages,

## First LaTeX Document

From now on, I’d restrict to Emacs editor (which is my favourite), the terminal for compiling the document, and evince as viewer.

NOTE: In case you choose to try emacs yourself, I recommend to check some old post of mine, about an emacs error, about environments, or emacs and LaTeX.

### Three first lines

All $\LaTeX$ document has the three very first lines which define it.

\documentclass{report} \begin{document} \end{document}

The first one define the type of document one’d like to write, some classes are

• report: a book-like document, probably less complex
• book: specially for writing books
• article: for scientific articles
• letter: for writing letters
• beamer: for presentations (see for example this post)
• currvita: for writing curricula vitae
• and many more…

All that is written between the begin and end document is called the body of the document, in there all chapters, sections and so on is included.

A special part of the document is the area between the documentclass and the begin document. This is called preamble, and there all the special request about our document are specified.

### Giving some Format

In order to start giving structure to our document, we need to know the kind of structures defined in $\LaTeX$,

• part: for book and report classes
• chapter: for book and report classes
• section: for book, report and article classes
• subsection: as above
• subsubsection: as above
• paragraph: as above
• subparagraph: as above

by now, we restrict ourself to these three classes, because the other are quite different.

Each structure is understand as a command, thus it must be presided by the backslash and include into the body of the document,

\documentclass{report}

\begin{document}

\chapter{Introduction}

\end{document}

As you might notice, the name of the chapter is enclosed by curly brackets.

NOTE 1: From part to subsubsection, structures are numbered by default. If you’d like to avoid the number, use an asterisk as shown below,

\documentclass{report}

\begin{document}

\chapter*{Introduction}

\end{document}

NOTE 2: A huge difference between a chapter (which I’m calling structure) and environment (such as document), is that the former ends when a new structure is given, while the later has a beginning and an end.

#### Some Environments

There are lots of different environments that might be used while writing a document, such as,

• equation: for writing a single numbered equation. Use equation* for unnumbered ones.
• eqnarray: for writing multiple numbered aligned equations. Use \nonumber for avoid a numbered line, \\ split the line, and && for telling where to align(the sign could be surrounding a sign).
• quote: for quotations.
• itemize: for unnumbered list.
• enumerate: for numbered list.
• figure: for adding numbered and possibly captioned figures.
• table: for adding numbered and possibly captioned tables.
• tabular: for constructing tables.
• minipage: allows to construct a mini-paga on the document, like a post it!
• and a long standing list which cannot be possible cover in a post!

### Compiling the Document

Since $\LaTeX$ is a programming language, one necessarily has to compile the document to get a PDF or PS (human) readable file.

The very fist step is to save the plain text file, the extension must be .tex, as it’s customary, I’ll call our foo.tex. Since compilation usually generates a lot of trash files, the best place to saave the plain text is in a folder dedicated for latex files.

In Emacs the keys

Ctrl-x Ctrl-s

abbreviated by  C-x C-s, saves the file… or buffer in Emacs jargon. The first time you save the file, a name must be given, ex.,  ~/Latex/foo.tex.

NOTE: I assume that a folder Latex was created in your home folder (~).

Once saved, go to the terminal and change the promt to the Latex folder,

 $cd ~/Latex and compile the file with pdflatex command $ pdflatex foo.tex

Finally open the document, with evince,

 \$ evince foo.pdf &

😀 Yeah babe!!!! That’s right… your first document written in $\LaTeX$.

### Writing Equations

I’m a physicist, so I’m used to write lots of equations. I’ll explain some examples,

$$\vec{F} = m \vec{a}$$

results in

$\vec{F} = m \vec{a}$

or the famous Einstein’s relation,

$$E = m c^2$$

results in

$E = m c^2.$

More complicated examples,

$$\frac{\partial^2 }{\partial t^2}x(t) + \omega^2 x(t) = 0\;\Rightarrow\; x(t) = A\sin(\omega t)+ B\cos(\omega t)$$

results in

$\frac{\partial^2 }{\partial t^2}x(t) + \omega^2 x(t) = 0\;\Rightarrow\; x(t) = A\sin(\omega t)+ B\cos(\omega t)$

With this example we opened the gate of Greek alphabet in mathematical mode, and Calculus notation… nevertheless, there exist endless possibilities. I encourage you to check symbols-a4.

The best of the compiled text, is that numbers (of section, chapter, equations, tables, or figures) are assigned by the compiler… therefore, you don’t need to remember those damn numbers. So, How do I refer to an equation?

First, give a name to the equation, with the label command

$$E = m c^2 \label{emc2}$$

and then, call it with the ref command,

As we saw before, the mass relation (\ref{emc2}), bla bla bla...

After the compilation the precise number appears.

NOTE: The same principle work for any other structure of the document or numbered environment.

### And the Title Page?

As you have notice, there’s a huge difference between WYSIWYG editors (Office-like) and WYWIWYG ones (which must be compiled). The maketitle command orders to the compiler to create a title page. The data should be included in the preamble, whilst the command form part of the document body,

\documentclass{report}
\title{My first document in \LaTeX{}}
\author{Dox Drum}
\date{\today}

\begin{document}

\maketitle

\chapter*{Introduction}

The harmonic oscillator is driven by the differential equation,
$$\frac{\partial^2 }{\partial t^2}x(t) + \omega^2 x(t) = 0\;\Rightarrow\; x(t) = A\sin(\omega t)+ B\cos(\omega t).$$

\end{document}

### Listing

As we saw above, list are made with the commands itemize or enumerate, whether you want it to be numbered or not.
Ex.:

\begin{itemize}
\item This got no number
\item Neither does it!
\begin{enumerate}
\item This is number one
\item number two
\end{enumerate}
\item Another with no number
\end{itemize}

which is a numbered list inside a unnumbered one.