Feeds:
Posts

## Posts Tagged ‘Emacs’

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 Advertisements Read Full Post » ## Emacs tip: Global indentation # Global Indentation In order to get what people like to call smart indentation on Emacs, the easiest way is to add a couple of lines to the .emacs configuration to declare that every newline should be indented. (define-key global-map (kbd "RET") 'newline-and-indent) (setq-default indent-tabs-mode t) The first line defines a global1 shortcut 2 for the command newline-and-indent assigned to the RET key (known Enter). The second line turns-on (the t at the end means true) the TAB indentation… if it’s not turned-on by default! #### Footnotes: 1global means that it is valid for any emacs mode 2In emacs-lisp it is called define-key Created: 2013-11-07 Thu 15:08 Emacs 23.4.1 (Org mode 8.2.1) Read Full Post » ## Emacs Tip: Using Macros Yesterday I started to edit an old $\LaTeX$ file, and it happened that in my set of definitions I changed a bold math-operator with no arguments \df, by a math-operator with one argument (which happens to by the following word) \de{#1}. ## The problem The issue now is that I should go all over the text finding the \df command and replaced by \de{#1}. But note that the is a delimiter with the curly bracket! ## The solution A while ago I found a page called , and I learn about emacs’ macro, i.e., a set of rules you define and then can be applied recursively. ### How is it done? A short explanation is given at . In my case I follow that rules below: • Press F3 to start recording the macro. • Look for the initial command and change it by the other using M-% \df (press enter) \de{ (press enter) • Move the cursor forward until the end of the next word using the command M-f • In that cursor place close the curly bracket } • Finish the recording of the macro by pressing F4. Finally, to apply the macro use F4 to apply it once, M-4 F4 to apply it 4 times or M-0 F4 to apply it until it fails. 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. Download the PDF document! Read Full Post » ## Increase TeX’s main memory I was looking the last version of the book “Algorithmic Graph Theory”, and one of the comments was about an error in the compilation… due to a lack of TeX memory. I’ve not heard of that problem before, so… just in case some of you is puzzled with this, here is the solution (thx. to mvngu) To increase TeX’s main memory, you need to locate the active texmf.cnf file for your TeX/LaTeX distribution. For example, on Ubuntu you can do so via the command $ kpsewhich texmf.cnf
Then open the file as root with the command

$sudo emacs /usr/share/texmf/web2c/texmf.cnf which will most likely prompt you for an administrator password. Enter the password and search for the line that begins with something such as main_memory = 3000000 % words of inimemory available; also applies to inimf&mp Change the value “3000000″ to “10000000″, i.e. change from 3 million to 10 million. Save your edit and quit your editor. Then issue the command $ sudo fmtutil-sys --all
and compile the book again.

Enjoy!

Dox

## Comment regions of a LaTeX file in Emacs

Usually, when writing in LaTeX, one would like to comment and/or un-comment a section of the manuscript.

There is a package which allow you to comment a portion of the file. However, I found out that one can customize Emacs for inserting/remove a percentage sign at the beginning
of each line of a selected region.

## Change the .emacs file

In order to do so, one should change the .emacs file.

• Open the file .emacs with your favourite text editor (say emacs, gedit, nano… vi?)
(defun uncomment-region (beg end)
"Uncomment a region of text"
(interactive "r")
(comment-region beg end -1));

(global-set-key "\C-c;"      'comment-region)
(global-set-key "\C-c:"      'uncomment-region)
• Save changes and close the editor
• ## Start using the new feature

Next time you open Emacs, you could select a region and use C-c ; for comment the region. Or if it is commented, use C-c : for un-comment it.

Enjoy

Dox

## SAGE tip: GR-module. Day 03.

In the last two post I introduce the classes formalTensor (which has been not that useful) and Tensor, the latter include a series of attributes.

Now is time to get started with GR 😛

# Metric Class

I left this class just as Sergei defined, it looked weird to me at the beginning, but again I decipher it 😉 with the help of Reinteract, b.t.w., those who want to play around with Reinteract, it’s in Ubuntu repositories, so just type in your console,

\$ sudo apt-get install reinteract

Ok. Continuing… here is the code,

class Metric(Tensor):
'''Represents a metric. Note that coordinates now MUST be provided'''

def __init__(self,coord,rank=(0,2),sh=(-1,-1),symbol='g'):
self.coord=coord
super(Metric,self).__init__(symbol,rank,sh,coords=coord)

def invert(self):
'''Find the inverse of the metric and store the result in a
Metric object self.inverse'''

'''Create a unit matrix of dimension dim'''
temp = sympy.eye(self.dim)

'''Assign the values of the metric to temp'''
for key in self.components.keys():
id = tuple(np.abs(key))
temp[id] = self.components[key]

'''invert the matrix with inv() from sympy'''
inv = temp.inv()
'''convert the matrix in a dictionary'''
inverse = self._dictkeycopy(self.components)
for i in range(self.dim):
for j in range(self.dim):
inverse[i,j] = inv[i,j]
self.inverse = Metric(self.coord,rank=(2,0),sh=(1,1),symbol='g_inv')
self.inverse.components = inverse

## Inherit…

The first I notice, as a non-expert programmer (or non-programmer at all 😛 ) was the word Tensor inside the brackets of the Metric class. This means that Metric is a Tensor… just as a Tensor is an Object. Thus, all methods defined in the Tensor class are applicable to the Metric class.

## Coordinate system needed

The __init__ method define the rank, shape and symbol of the metric, which are always the same. However, the set of coordinates must be given.

#### Example of implementation

Coordinated should be entered like a tuple, and the name of coordinates MUST be “declared” as sympy.Symbol

 t = Symbol('t')
r = Symbol('r')
th = Symbol('theta')
ph = Symbol('phi')
g = Metric((t,r,th,ph))

Given the this data, the Metric class calls the Tensor class and create a covariant rank 2 tensor. And we should give the components. For example, the easiest Schwarzschild metric (the metric is easier than the name!!!),

g[0,0] = -(1 - 2*M/r)
g[1,1] = 1/(1 - 2*M/r)
g[2,2] = r**2
g[3,3] = r**2*(sin(th))**2

WAIT!!!! Don’t forget to declare the mass parameter, so, again…

M = Symbol('M')
g[0,0] = -(1 - 2*M/r)
g[1,1] = 1/(1 - 2*M/r)
g[2,2] = r**2
g[3,3] = r**2*(sin(th))**2

… Sorry guys, it’s again too late! and is already Monday!

Ok, tomorrow we’ll continue with the inverse metric 😉

Get GRmodule.py
and the proof-file.py.

Cya tomorrow!

Dox