Posts for 2009 May

Quote of the day

Post by Nico Brailovsky @ 2009-05-30 | Permalink | Leave a comment

If you can't see any error messages it must be because you didn't start it. Or it has already core-dumped.


LaTeX basics

Post by Nico Brailovsky @ 2009-05-28 | Permalink | Leave a comment

LaTeX basics

Remember last post? I mentioned it's possible to create several type of documents. Even if the structure will, most likely, be different for different applications, there's a common ground which can be used for most LaTeX documents. I'd go as far as saying ALL of them, but in LaTeX it's possible to override everything and anything. Any reasonable package won't do it, so let's see some LaTeX basics you can use for any project.

LaTeX documents

The first thing to understand about LaTeX, it's not WYSIWYG. If you use a plain text editor you won't see any kind of format at all (LyX provides some sort of preview though). This confuses some people who, used to Word-like applications, tend to think in the structure and desing before the contents; LaTeX is different in the way to structure documents, a way which is called What You See Is What You Mean, WYSIWYM, for short.

What does being WYSIWYM means? You just think about the content and structure and it gets formatted for you. Instead of saying you want "Centered, Arial 12px orange font with pink background" just say "this is a title". The format will be there, but not attached to the content - it'll be in a "stylesheet", the document's class (*). Of course, these styles can be changed too.

WYSIWYM has a downside too: you'll have to "compile" the mark-up text into a pdf (or any other format) using pdflatex, for example. It may be a shock to some but it's not difficult, just write "pdf2latex file.tex" and let it work its magic. You can use the makefile I'm attaching to this post too, if you feel comfortable with makefiles (The makefile has a few cool tricks you can use too. I'll explain all of it in another entry).

Seeing some examples

In GNU/Linux you can find lots of examples and templates in /usr/share/doc/texlive-doc/latex/ (no idea where may they be in Windows). Writing this article I found out lots of templates I didn't know about so go and take a look. Go on, I'll wait here. Done? Ok, let's move on.

Preamble

In LaTeX there's a basic structure every document follows:

% Preamble
begin{document}
end{document}

What comes before the begin'ning is the preamble. There you can tell LaTeX: * Which packages are you going to use - there are lots of packages, some examples include source code highlighting, including images, absolute positioning of figures and much more. Include them with the usepackage command

This post is getting a little bit too large so I'll leave some basic commands for the next one; you should be able to start writing some basic documents anyway.

(*) Yeah, something like content and style separation but only a couple of decades before it was "invented" for the WWW.


Vim Tip: Partial Search & Replace

Post by Nico Brailovsky @ 2009-05-26 | Permalink | Leave a comment

So, you have a paragraph, or any kind of text, and need to replace a substring without altering other paragraphs. You could write :set number and then :A,Bs/what to search/what to replace/g, being A and B the start and end of the paragraph, or you could just use visual mode.

Enter line selection mode (Shift + V) and then select a block of text. Without moving the cursor any further type :s/SEARCH/REPLACE and the search string in the selected block will be replaced without altering any other part of the document.


self.uptime = 725328000

Post by Nico Brailovsky @ 2009-05-23 | Permalink | Leave a comment

| Today it's been 725328000 seconds of uptime since I was promoted from Release Candidate to V1.0. Still waiting for security updates though. | |


Vim: Success

Post by Nico Brailovsky @ 2009-05-22 | Permalink | Leave a comment

The other day I convinced someone Vim is THE true editor.

Success Disclaimer: I love that image and would have found other excuse to use it


A case for LaTeX

Post by Nico Brailovsky @ 2009-05-21 | Permalink | Leave a comment

So, after struggling with you word processor to get an acceptable format you decide to hunt the repos (you're using Linux, right?) for a better alternative. We already know why would you choose LyX but why would you choose LaTeX?

Let's begin by listing some of its advantages

It has some downsides too

Who should use LaTeX?

As previously stated, programmers will be more comfortable around plain LaTeX but that's not the only pre requisite - you should be somewhat familiar with the console in Linux (no idea about LaTeX on Windows) and have some patience to read a couple of manuals. Once you have mastered the basics it's much easier, so don't get discouraged.

If you feel you don't fit the profile perhaps LyX is a better alternative than plain LaTeX; it's very easy to use and quite user friendly. It won't be that great for presentations and other, more "advanced", documents though.

What kind of work can you do with LaTeX?

That's an easy one, check My Articles section for some examples. You can create any kind of document but it's better suited for those in which you care most about the content and don't want to get bogged down with pesky design details.

Editors

Last (for this entry) but not least, what editor can you use to create LaTeX documents? Well, LaTeX is basically plain text so any editor will do. There are some LaTeX-specific editors, I like ViM myself. There'll be a complete post dedicated to LaTeX + Vim, coming soon.

This article will be the first in a series of LaTeX survival guide so stay tuned.


apt-get install new computer III

Post by Nico Brailovsky @ 2009-05-19 | Permalink | Leave a comment

Check the other two parts of this series:

I recently updated to Ubuntu 9.04 and had to reinstall my work computer. Since the stuff I use for work (mostly c++ programming) was left out in the previous two posts I'll post it here:

sudo apt-get install g++ gdb build-essential g++-4.2 omniorb4 omniidl4-python omniidl4 libxerces-c2-dev
sudo apt-get install vim gvim vim-common vim-doc vim-full vim-gnome vim-gtk
sudo apt-get install ddd devhelp doxygen doxygen-gui exuberant-ctags ctags  subversion
sudo apt-get install ifstat
sudo apt-get install antiword

Done, a couple of apt-get's and you are ready to build your c++ projects! (Ok, actually only the first one is needed, the others are nice-to-have programs).


Everything is a file A.K.A. Battery state on Linux

Post by Nico Brailovsky @ 2009-05-14 | Permalink | Leave a comment

I present to you the latest release from Wheel Reinventions Inc. - Already Invented dept. - a script to check the remaining battery time from Linux console.

|


echo -n "Hours remaining: "
&& echo "$(cat /proc/acpi/battery/BAT0/state
      | grep 'remaining capacity'
      | awk '{print $3}') /
   $(cat /proc/acpi/battery/BAT0/state
      | grep 'present rate'
      | awk '{print $3}')"
   | bc -l

Yes, I was bored, so? I'm planning to release a new bogosort implementation after this one, what do you think?

Jokes aside, this nifty script shows how flexible can be the model "everything is a file" which Unix-y systems implement. With a couple of pipes (and an almost magical incantation for those uninitiated in the console cult) you can do lots of stuff with very little work

This concept could be associated with the way polymorfism works in a programming language, but that's an entry for another day.


In reply to this post, Nicolás Brailovsky » Blog Archive » DIY gnome applets commented @ 2011-09-29T09:13:55.000+02:00:

[...] widgets. Need to check your laptop’s battery? No need to search for a widget anymore, just cat /proc/acpi/battery/BAT0/state. Need to check the weather? Just wget your favorite forecast page and parse it with grep, sed an [...]

Original published here.


LaTeX!

Post by Nico Brailovsky @ 2009-05-12 | Permalink | Leave a comment

Some time ago I wrote a review about LyX for DPOTD (recommended link) and now I think it's time for an update: what can you do when LyX is not enough?

I'll quote myself; the original article ends (almost) like this:

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.

After having prepared several presentations with LyX (even my CV!) I'd like to write some more on this last part. Even if I thought that my original comment was mistaken I write once again the same: when you have to create a presentation LyX is not the tool for the job, LaTeX is.

As I explained in that article, LyX is a front-end for LaTeX but at the same time it's only a small part of LaTeX. Doing several presentations in LyX (using Beamer, a package I'll talk about in another post) I noticed that most of my documents where "ERT", evil red text, which is nothing else than plain TeX code: that means, each time more, I was using LaTeX functionality not available from LyX. This is the reason I've decided to write a how-to LaTeX, a small survival guide for those want to start using with the tips and tricks I've learned in this time.

The target for these posts series will be, mainly, programmers or other advanced users, without fear of working a little bit in the console, markup languages and maybe a makefile.

Soon the first part :)


Vim Tip: Visual Mode

Post by Nico Brailovsky @ 2009-05-07 | Permalink | Leave a comment

There's normal mode, command mode and a third, less known to the beginners, visual mode. What's this mode about?

Using Vim on visual mode can make some rather complex tasks and regex operations go away with a couple of keystrokes and it's as easy as selecting the text you want with the cursor.

Move your cursor over the first part of the text you're trying to select and press Ctrl + V to set Vim to visual mode, then move the cursor to the last part of the text you're trying to select (it works in blocks, not character by character nor line by line... try it, it's easier than it may seem).

What can you do after selecting text this way? Pretty much anything else you'd do with normal text, like cut (x) and paste (p). This is specially useful when working with formatted text (i.e. programming).

Visual mode can also work with lines (use Shift + V instead. Notice the uppercase V) and with other modes; check the manual for more information.


Fixing keyboard problems in Ubuntu J.J.

Post by Nico Brailovsky @ 2009-05-05 | Permalink | Leave a comment

I recently metioned in my Ubuntu J.J. review I was experiencing some issues with the keyboard in Opera. Well, the solution is simple, though not easy to find: the culprit was a missing language pack.

While installing the OS I didn't have Internet connection (the Squid server died and left me with no repos to work with after installing) so it didn't download some required language files, thus screwing up non Gnome programs (Opera, in my case).

To fix this problem go to System > Administration > Language Support (1) and a notification should pop up if there are packages missing; install them and then uncheck "Use Input Method Engine ..." (2), then restart the session.

Everything should work fine now (áéíóú :)).

(1) Sistema > Administración > Soporte de Idiomas (2) Usar motores de método de entrada (IME) para ...

| |