Nicolás Brailovsky


A modern blog

Archive for June, 2009

LaTeX: LyX Revisited

author Posted by: nico on date Jun 29th, 2009 | filed Filed under: LaTeX
lyx_logo_hi Seeing I’m publishing a new LaTeX series it seems appropiate to review my old LyX article. This is just a copy & paste from http://debaday.debian.net/2008/01/20/lyx-a-text-editor-that-stays-out-of-the-way/

Did you ever get to struggle against your text editor’s random format feature while trying to write a document? Open Office may be a great project, but when you want to focus on the content, it can be annoying to have your editor format or unformat your text, seemingly at random.

Well there are good news for those of us using Vim to create content and then Abiword to format it: LyX is a text editor that produces beautiful documents, without the need of being a designer, and yet manages to stay out of the way. From the tutorial and the homepage (www.lyx.org):

LyX is the first WYSIWYM (What You See Is What You Mean) document processor. The basic idea of LyX is that you do not need to handle style, or actually, you use a set of predefined styles and concentrate on your document content, This makes sure that your resulting document will be typographically correct and good looking visually. […] LyX uses Latex as its back end typesetting mechanism.

Sounds great already, doesn’t it?

A first look into LyX

Upon start LyX looks more or less like any other graphical text editor in the universe:

Well, it’s logo may look nicer, but that’s about it. Anyway, the magic starts just as you start writing: you’ll notice most of the common format options seems missing, but you can define what you’re writing instead:

Note that we don’t tell it to center it or to make the font larger and bold. LyX takes care of all that automatically. Simply click on the format menu (below File, and it has the default value of “Standard”).

So instead of defining Times New Roman 12px bold centered, you say «Title». WYSIWYM, remember? In the homepage there is a «Graphical Tour» with all the basic functions, it’s quick and it’s great: www.lyx.org/LGT

Some useful features

LyX also provides a great support for math formulas (and all the weird symbols you can think off). Just click the button «Insert Equation» and a box to enter math symbols will appear. No more struggle to align the dividend and the divisor!

Of course, LyX provides the usual features such as tables, spell checking, footnotes and many more. The tutorial of the application is more than complete, and easy to follow.
LyX documents formats

LyX documents can be exported to a wide variety of formats, mainly because being based on Latex it takes advantage of the already existing conversion programs. Some of the possible export plugins installed by default are PS, PDF, DVI, Latex, HTML and Plain text, but custom ones may be defined.
What LyX isn’t for

Although LyX may be a valuable piece in anyone toolkit it’s worth noticing it isn’t exactly the Swiss army knife of the text editors. If you need to define a very customized layout or format, like slides for a presentation, this is the wrong tool for the job.

Availability

According to it’s homepage, LyX 1.5.3 was released the 16 th of December, 2007. It’s available in Debian since Sarge (packages.debian.org/LyX). Lyx Version 1.5.1, released 4 th of August, 2007, is available in the repository of Ubuntu 7.10. Development is still active. There’s also a Windows version for those of us stuck with primitive a OS at work.

Welcome!

author Posted by: nico on date Jun 27th, 2009 | filed Filed under: Meta-post

A good friend of mine (a programming junkie just like me) just started his blog, so this is kind of a welcome. Actually there’s already a link somewhere in this page so this post is just an excuse to post this recommendation about writing articles for a blog:

> Remember you didn’t like books without pictures as a child? Well, Internet’s mental
> age isn’t a day over four years old, use pretty pictures whenever you can.

avestruz3zv

Unique var name with C/C++ macros

author Posted by: nico on date Jun 25th, 2009 | filed Filed under: C++, Programming
cpp So, you’re working on some macro magic incantation and you need a unique variable name in you C program? Though it may seem simple at first, using __LINE__ for a variable name, the ## operator (concatenation in the preprocesor) won’t let you. There’s a secret spell to do it anyway:
  1. // Do magic! Creates a unique name using the line number
  2. #define LINE_NAME( prefix ) JOIN( prefix, __LINE__ )
  3. #define JOIN( symbol1, symbol2 ) _DO_JOIN( symbol1, symbol2 )
  4. #define _DO_JOIN( symbol1, symbol2 ) symbol1##symbol2

Great, now you can keep obscuring your programs even more – have fun!

LaTeX: format basics

author Posted by: nico on date Jun 22nd, 2009 | filed Filed under: LaTeX

Basic structure

tex So, what’s the most basic structural elements for any document you write? Paragraphs, of course. I ussualy use LyX for writing paragraph-based documents (i.e. most of them) and presentations don’t have many, so perhaps this is the structural element I use the least. Oh, wait, there’s no element, just a “\n\n”. Point for LaTeX (take that, HTML).

You’ll also need to put titles, sections, subtitles and all that stuff to give your document a nice structure. Well, that’s easy too, just use

  • \section{name}
  • \subsection{name}
  • \subsubsection{name}

Easy, right? Check the example at the end of the post. There are some other commands you’ll use in any LaTeX document:

  • Footnotes
    1. \footnote{ Footnote text }

    Just write your text, it’ll be there when you compile the document

  • Vertical skip
    1. \bigskip

    Because, some times, LaTeX default formatting won’t be enough.

  • Align text Center:
    1. \begin{center}TEXT\end{center}

    Right:

    1. \begin{flushright}TEXT\end{flushright}

    Again, some times you may need it. Not too often, though.

You should now be able to write your first LaTeX document, starting from a template (always start with a template… it’s easier). I’m attaching to this post an example document in LyX, LaTeX and its compiled pdf, in case you’re wondering what does it look like in the end. For the next entry: some “advanced” tips and tricks, now let’s see an example LaTeX document:

  1. \documentstyle[11pt]{article}
  2. \title{LaTeX Example}
  3. \author{Nicol\’as Brailovsky}
  4. \setlength{\topmargin}{-.5in}
  5. \setlength{\oddsidemargin}{.125in}
  6. \setlength{\textwidth}{6.25in}
  7.  
  8. \begin{document}
  9.  
  10. \maketitle
  11. This is just a LaTeX kick off, with some basic commands.
  12.  
  13. \section {Section one}
  14. For example, this is a paragraph.
  15. \begin{quotation}
  16. { \em Lorem ipsum dolor sit amet, consectetur adipiscing elit.}
  17. Donec porta, enim eget tempus tempor, eros sem dapibus diam, vitae lacinia mauris metus id nulla.
  18. \end{quotation}
  19.  
  20. \subsection{Subsection}
  21. You can have subsections too \ldots
  22.  
  23. \subsection{Subsection’}
  24. \ldots as many as you want
  25.  
  26. \subsection{Random stuff}
  27. You can even create a shopping list in LaTeX, if you wish
  28. \begin{center}
  29. \begin{itemize}
  30. \item Beer
  31. \item Beer
  32.         \begin{itemize}
  33.                 \item (Another brand of beer)
  34.         \end{itemize}
  35. \item Pizza
  36. \item Beer
  37. \end{itemize}
  38. \end{center}
  39.  
  40. Or even better, use it to do the homework. \\
  41. Math is a breeze in LaTeX: $x_n = \sqrt{a + b}$ can be typeset inline.
  42. \end{document}

You can download the compiled document from this link. May be it doesn’t look too useful (I’d use LyX instead) but soon we’ll start doing some cool stuff LyX can’t handle. Keep tuned for the next LaTeX article.

Vim Tip: Easy Indent

author Posted by: nico on date Jun 14th, 2009 | filed Filed under: Vim, Vim Tips
vim_editor Editing source code means you’ll be doing a lot of indenting and reindenting. There’s an easy way to indent or de-indent a block, using just “<” and “>”.

Using “>” without anyother command will indent that line by itself; use visual mode (Shift + V) to select several lines and indent them in one keystroke. You could also press “v%>” while sitting at the beggining of a block to indent it. The same applies to “<”.

vimrc: Vim startup file

author Posted by: nico on date Jun 11th, 2009 | filed Filed under: Linux, Programming, Vim
vim_editor I usually create a partition for /home, so whenever I decide to foobar my OS (i.e. do a kernel update on Ubuntu, or start playing with compiz too much) there’s no need to copy my home folder to another disk and back again. Regardless of this, there are some essential files which I’d be dead without. One of these is my .vimrc, the startup file for Vim.

My .vimrc file has been organically growing since I started using this editor, a couple of years ago, so I’ve decided to clean it up a little bit and post it here, just to be sure I won’t be loosing it. It’s got some tweaks to use Vim as an IDE, feel free to download it and change it or use it anyway you want.

  1. colorscheme torte
  2. set nocompatible
  3. syntax on
  4. set ruler
  5. set number
  6. set hls                 " Highlight search results
  7. set showmatch   " Show matching () {} []
  8. set wildmode=list:longest,full  " Use tab-completition
  9. set mouse=a                     " Always use the mouse
  10.  
  11. " Set the working directory to the directory of the current file.
  12. autocmd BufEnter * lcd %:p:h
  13.  
  14. " Allow movement to another buffer without saving the current one
  15. set hidden
  16.  
  17. " *********** Text formatting *************
  18. set nowrap
  19. set beautify
  20. set shiftwidth=3
  21. set tabstop=3
  22.  
  23. filetype on
  24. filetype plugin indent on
  25.  
  26. " *********** Search &amp; replace *************
  27. set ignorecase  " case insensitive
  28. set smartcase   " case insensitive only if there is no uppercase
  29. set incsearch   " incremental seach
  30. set gdefault    " default to /g on replace
  31.  
  32. " Load matchit (% to bounce from do to end, etc.)
  33. runtime! macros/matchit.vim
  34.  
  35. augroup myfiletypes
  36.         " Clear old autocmds in group
  37.         autocmd!
  38.         " autoindent with two spaces, always expand tabs
  39.         autocmd FileType ruby,eruby,yaml set ai sw=2 sts=2 et
  40. augroup END
  41.  
  42. " display the current mode and partially-typed commands in the status line:
  43. set showmode
  44. set showcmd
  45.  
  46. set autoindent
  47. set smartindent
  48. " Show an error window (if there are errors)
  49. cwindow
  50.  
  51. " *********** Mappings *************
  52. " Ctrl-t: Write tabnew (wait for filename and )
  53. map  :tabnew
  54. " Alt-R: Exec current file as script
  55. map  :!.%
  56. " Ctrl-Alt-R
  57. map  :tabnew:make
  58. " Spellcheck
  59. map  :!ispell -x %:e!
  60. " Comment a line
  61. map  0i//
  62. map  0xxx
  63.  
  64. " Build for a LaTeX file (assumes correct path and makefile)
  65. autocmd filetype tex map  :w:make
  66.  
  67. " Automatic closing brackets
  68. inoremap do{ do{}while();O
  69. inoremap do{ do{}while();O
  70. inoremap { {}O
  71. <a href="http://nicolasb.com.ar/archivos/2009/05/.vimrc">Link to my .vimrc file</a>

apt-get install new computer IV: round up

author Posted by: nico on date Jun 9th, 2009 | filed Filed under: Linux

Quick post this time – just a roundup of the “apt-get install new computer” series. This is a one liner I use in any new install I’m planning to work with, hope it’s useful for you too.

sudo apt-get install lyx mozilla-thunderbird tilda mmv unclutter gnome-do moc ffmpeg shntool cuetools flac wavpack vlc deluge bittornado-gui build-essential gcc g++ valgrind latex-beamer ssh sshfs openssh-server vim vim-gtk sun-java5-bin sun-java5-jdk sun-java5-jre sun-java6-jdk antiword ifstat php5 php5-mysql php5-pgsql php5-cli php5-gd php5-curl ruby1.9 irb1.9 rails rake valgrind install

New package: antiword – read office documents on console

Editors Learning Curves

author Posted by: nico on date Jun 7th, 2009 | filed Filed under: Vim

emacs_learning_curves

Vim Tip: Know your blocks!

author Posted by: nico on date Jun 5th, 2009 | filed Filed under: Vim, Vim Tips
vim_editor Vim is the best editor for programmers and as such it has some neat “programmer commands”, which make editing source code a lot easier. Take for example a block with code, or a function definition: how many times did you have to copy the code between parenthesis from one place to the other?
  1. int foo(int bar, int baz)

You could do ‘0f(df)’ to delete “int bar, int baz” but that won’t do if the definition is more complicated than that. ‘dib’ is a better choice to delete the text.

(ACTION)i{b|B} applies ACTION to a block, for example, pressing diB in

  1. void foo() _ {
  2.         /* Lots of source code */
  3. }

(with the cursor placed at _) will delete lots of source code.

Testing & mocking: C++

author Posted by: nico on date Jun 2nd, 2009 | filed Filed under: C++, My Articles, Programming

Check the previous post about this presentation.

Where I work we have been working a lot with unit testing and continuous integration. This is a presentation I worked with, about unit testing and mocking tools in C++ (only in spanish, sorry).

Link to the article

Article created with LaTeX