Mostrando entradas con la etiqueta latex. Mostrar todas las entradas
Mostrando entradas con la etiqueta latex. Mostrar todas las entradas

martes, 10 de mayo de 2011

latex code listings in org-mode

I already talked about inserting code listings in latex some time ago. At @work
(in a ruby meaning, not a perl one), I try to write as much as I can
in org, and then export it to html, or pdf.

org-mode is fully capable of assisting you when writing code listings,
and it will export them with fancy syntax highlighting. When exporting
to html, it uses htmlize (emacs-goodies if you're in ubuntu). But when
exporting to LaTeX, things are not so straightforward. Of course,
there's extensive documentation, but sometimes, you just don't want to
read through hundreds of details. You just want something that
'WorksForMe (c)'.

(setq org-export-latex-listings t)
(add-to-list 'org-export-latex-packages-alist '("" "listings"))
(add-to-list 'org-export-latex-packages-alist '("" "color"))


I don't know if it's enough or there's another configuration related
to this sunken in my .emacs (now 609 lines long), but you know... It
WorksForMe.

viernes, 8 de enero de 2010

bibtex is too smart for me

I've been struggling for some minutes with an error when compiling a bibtex file (the LaTeX bibliography system).

The error reads like:
Too many commas in name 1 of "Abhishek Verma, Xavier Llora, Roy H. Campbell, David E. Goldberg" for entry VLCG09
Well, after scratching my head and a few change-compile-fail-swear loops, I found out that bibtex notices the "and" token and the commas in the author tag.

The trick was changing
author="Abhishek Verma, Xavier Llora, Roy H. Campbell, David E. Goldberg",
to
author="Abhishek Verma, Xavier Llora, Roy H. Campbell and David E. Goldberg",
It's cool that bibtex knows so much about correct formating, but... yeah, maybe it's too smart for me.

----------

Update


The lazyweb returned me a clarification about all that mess. In fact, the "proper" way to insert the authors of a bibliography entry is spliting different authors with "and", no matter if it's the last or not, and commas are used to separate surnames and names.

So you can forget everything before this "update".
Thanks D.A. for the tip.

viernes, 23 de octubre de 2009

insert code listings in latex



I've been strugling with it for last 2 days, and finally found a solution (I should have googled before , and not so much blind guessing).

Depending on what you're writing about, you probably will have to put code in your documents. Inserting code in latex is not that trivial, because you have to tell latex that a given block has to be left 'as is' (that means not formating it, not squeezing the newlines, indenting it correctly, and syntax highlighting it).

My first attempts where quite hand-crafted solutions, mixing a verbatim environment and fitting it into a table with just one row and one column.

Then I found a package called listings. It's a farily complex package, with lots of options and parameters, but for me, I just can use it nearly vanilla.

\usepackage{listings}
\usepackage{textcomp}
\usepackage[]{color}

\lstset{language=c++,
tabsize=4}
\lstset{commentstyle=\textit}



If you want, you can use pretty complex configurations:

\lstset{ language=C++,
keywordstyle=\bfseries\ttfamily\color[rgb]{0,0,1},
identifierstyle=\ttfamily,
commentstyle=\color[rgb]{0.133,0.545,0.133},
stringstyle=\ttfamily\color[rgb]{0.627,0.126,0.941},
showstringspaces=false,
basicstyle=\small,
numberstyle=\footnotesize,
numbers=left,
stepnumber=1,
numbersep=10pt,
tabsize=2,
breaklines=true,
prebreak = \raisebox{0ex}[0ex][0ex]{\ensuremath{\hookleftarrow}},
breakatwhitespace=false,
aboveskip={1.5\baselineskip},
columns=fixed,
upquote=true,
extendedchars=true,
% frame=single,
% backgroundcolor=\color{lbcolor},
}

Then, you just embed your code inside a lstlisting environment


\begin{lstlisting}[frame=trbl]{}
class Funcio{
private:
map dict;
public:
Funcio(){};
~Funcio(){};
operator()(int param1){
if( dict.exist(param1)){
return dict[param1];
}
double resultat;
// calcular i omplir resultat ...

dict[param1]=resultat;
return resultat;
}
}

\end{lstlisting}


With this you can paste codes with a great look.

As always, here are the sources I read to write this howto.

Ah, I know the code in the screenshot does not work, but it's just a kind of pseudocode to illustrate memoize, closures, and the c++ functors aproach (a half-solution to emulate closures and stateful functions in c++)

Bye!

viernes, 24 de abril de 2009

Fully vim style linux (part 2) - Vim for latex

Writing documents with latex with vim is fairly pleasant because you have your usual maps available, and you can configure most things with scripts but, as always, someone has already done that (don't reinvent the wheel).

latex-suite


Latex-suite is a great and very complete set of plugins for vim that helps writting faster latex with vim. It has lots of options and configuration bits, but you only need to remember a tiny set of shortcuts to use it (at least at a beginner level)

Environment complete (F5) . you're in a document and you want to insert a tabular environment. Just type 'tabular' and press F5. a full tabular environment will be placed right there, with the appropiate number of params and placeholders (you can navigate to the next placeholder with ctrl-j).

Package inserting (F5): in the preamble section, if you press F5 after typing a word, latex-suite will enclose it into a \usepackage{word}
snipMate

Compiling (ll) : to compile a document, just press your leaderkey followed by 'll' (that's two 'els').

View the compiled doc (lv): just type leader lv to open your viewer program with your dvi/pdf file in it.

There are lots of other useful things in latex-suite. you can find further info in its website.

LaTeX::Table

Tabulars can go from the simplest things to fairly complicate structures. Let there be perl.

There's a small module named LaTeX::Table that helps us to make pseudo ascii tables, and put some options embedded in a comment, and it converts them to fully functional tables.

Try cpan:

sudo cpan LaTex::Table
It uses Moose (a great modern OOP system for Perl 5), so if you don't use perl regularly, cpan will probably install a big bunch of perl modules.

If you have any problem installing those modules from cpan, you can always install them (or at least, the one that fails) with the good old method:

perl Makefile.PL, make, make install

Now a usage example.

theme=Berlin;caption_top=1;caption=foo
one & Two & Three
CAN I & haz a & CHEEZBURGER
& OH & KTHX
FOO & bar & Baz
Just visually select it and apply the !ltpretty filter. You're done

Latexhelp

With latexsuite, there is a latex reference in vim help format, so you can access the syntax of latex commands easily in vim. It doesn't need additional configuration, provided you placed the latex reference file in your doc/ directory and ran helptags on it. Probably :helptags ~/.vim/doc will do.

you can find the separate doc files here.

vim config

There are lots of possible configurations depending on your workflow and/or preferences. My configs are just theese lines.

let g:tex_flavor='latex'
let g:Tex_CompileRule_pdf = 'pdflatex -interaction=nonstopmode $*'

More things

As you probably know, learning to use vim effectively has many paths to go, and what is useful for me, can be painful for you. You can combine plenty of other vim plugins to help you writting faster latex.

For example, using snippetsEmu/snipMate/whatever snippets plugin can be useful, using supertab can speed up your (general) writting, or even little maps like the ones explained in my previous post 'Fully vim style linux (part 1)' can enhance your typing experience.

Please post comments about comments/improvements, and I'll make the appropiate updates.

See ya in the next post.