donderdag 21 oktober 2010

LaTeX Tables

updated September 2013

I am not a big believer of LaTeX, but I do use it. One reason to dislike LaTeX is the way you need to make tables. It is very easy to mess up and very hard to debug.

From your stats package to LaTeX

My workflow is the following: make every table with just data in Excel, then convert using excel2latex and paste it in your .tex file. If you happen to have crazy formulas in your table, do the same but use codes in your excel table which you then replace by the formulas in LaTeX.

Do not, as a rule, use tabout-like output that Stata delivers. I prefer a little adjustment of Excel matrix output, which is good nowadays, over the burden to look into the LaTeX puzzle. Face it: when we use tables, it's generally for several models or with a combination of different analyses. So for me -tabout- is worthless.

Adjustments to LaTeX tables

The standard LaTeX-layout, which is good enough, has very large margins. That's nice, but it limits your tables. To cope with that, I've read about two solutions:
  • The tabularx package
  • Put the table inside a minipage and scale it to fit
We're left with just a few more issues: 
  • Landscape pages (fear, anger, hate!)
  • Wrapping lines
  • Wide tables (through -tabularx-)
As for landscapes, I have no clue for the moment. You may want to check here. And pdflscape may be it.
Wrapping lines I've done. It's cumbersome. Basically, you will want to limit the size of a column. You do that through specifying p{3 cm} in your {l l l c r r r c} series of column specifications, where each of l, r, c refers to a column that is left aligned, right aligned or centered. p{} replaces such a specification, so you lose your control over alignment! To solve this issue, you need yet another package: arrays. Then, and I'm not joking, your wrapped left aligned column should be specified as:

>{\raggedright\arraybackslash}p{width}

It is really that stupid. Never saw a > in LaTeX syntax before? Neither did I. As always, there will be some logic behind it, for which a Ph.D. level IQ will suffice, but even if it is understandable, we don't want to waste our time figuring out. 

Links

If you don't want to google, hit some old bookmarks (2010):

woensdag 20 oktober 2010

Word of LaTeX?

Dingen die goed werken, interesseren mij, en men zegt dat LaTeX goed werkt. Effectief, de output ziet er behoorlijk uit. Saai, maar consistent. Die twee dingen gaan samen en zijn voor bepaalde opdrachten gewenst.

Maar wat er bij mij niet ingaat is hoe je een tekst kunt schrijven in LaTeX. De markup code stuurt je in de war en tijdens het typen is de bladspiegel niet om aan te zien. Hou er rekening mee dat veel, zo niet de meeste, teksten vooral gelezen worden vóór ze afgedrukt of gefinaliseerd worden. Dat heet dan een werkdocument.

Eén optie is te starten in Word, en de finale versie in LaTeX te maken indien nodig. In veel gevallen zal dat niet kunnen, omdat er bijvoorbeeld een template opgelegd wordt door een consortium of een opdrachtgever.
  • Type de tekst in Word, tenzij er wiskundige afleidingen in voorkomen, dan ga je meteen aan de slag in LaTeX.
  • Exporteer het bestand (.doc) naar LaTeX (.tex) met Word-to-LaTeX
  • Maak de tabellen altijd in Excel
  • Converteer de tabel naar LaTeX met Excel2latex
  • Voeg de tabellen in en check de cross-references
  • Kuis de opmaak
    • \title{titel hier} in de heading
    • \data{datum hier} in de heading
    • \maketitle als titel
    • \section{} en \subsection{} als titels van de paragrafen
    • \usepackage{verbatim} in de heading en \begin{comment} \end{comment} om tijdelijk syntax weg te laten (vb. uit Word overgenomen marges)
Voordeel: je ziet meteen een behoorlijke tekst en moet alleen kleine wijzigingen doorvoeren in de .tex-file.
Nadeel: met het gratis programma worden formules overgenomen als afbeeldingen. Je kan ze dus niet bewerken. Er zijn enkele betalende alternatieven, zoals GrindEQ, die dit wel kunnen. Ze doen het echter niet noodzakelijk beter voor andere omzettingen.

De tweede optie is meteen een LaTeX document maken.

  • Werken met twee schermen is een must.
  • Voor documenten met veel verwijzingen, grafieken en formules is dit een must.
  • Grafieken kan je in één map plaatsen als pdf's, aangeduid via graphicspath. De kwaliteit van vectorafbeeldingen is niet te evenaren met .jpg/.bmp/.png of zelfs .tiff. Word kan overweg met .emf en .wmf, maar microsoft ontmoedigt deze formaten zelf in de recentere windows versies. Bovendien blijft consistent schalen een probleem in MS Office en is de controle over de bladspiegel onmogelijk. LaTeX daarentegen heeft eigen algoritmes om figuren een plaats te geven, die je desnoods kan overrulen.
  • Je kan de tex-file altijd downgraden naar een ander soort tekstbestand. Er is een optie om te exporten naar html en naar rdf, maar ik heb die nog niet aan de praat gekregen.
  • Het grootste probleem zijn de vreemde tekens, waar LaTeX niet mee overweg kan: een ö wordt in LaTeX \"{o}. Voor ç, û, etc. gelden gelijkaardige problemen. LaTeX verstaat deze karakters echt wél mits het oproepen van inputenc: \usepackage[utf8]{inputenc}. Dat kon gebruiksvriendelijker, natuurlijk.
  • Ik heb geen idee of de bibliografie dan ineens mee geëxporteerd wordt. Laten we het hopen.

Links

dinsdag 19 oktober 2010

Kaartjes maken in Stata

Er bestaat speciale software voor het maken van landkaarten met statistische informatie. Als ik die zou ontwikkelen, zou ik die InfoMaps dopen, dus waarschijnlijk heet het programma zo (edit: het programma heet MapInfo). Maar voor de arme assistent die het met zijn Stataatje moet doen, is er een oplossing:

spmap

Wat je in elk geval nodig hebt zijn Shapefiles. Die kun je dan omzetten naar punten op een assenstelsel, die de grenzen van de landen weergeven. En goede files vind je hier:

donderdag 14 oktober 2010

Reference managers

This post has been updated 9 November 2013: added JabRef

Routine work should be automatized. I remember writing my master thesis using a not so legal copy of Endnot X, which had a terrible memory leak. As a result, I had to restart my computer every hour - which took about 10 minutes! I didn't smoke cigarettes, so what a waste of time... However, the best part of my thesis was probably the bibliography.

Today we get all the fun for free. You may get rid of your boxes of EndNote and Reference Manager. They're too expensive and little innovative. There are two fresh, hip reference managers that rule the scientific world nowadays: Zotero and Mendeley. There is an additional and traditional tool I use with them when doing LaTeX-work: JabRef. I discuss pro's and cons, so you should understand why I choose for Zotero. Both are excellent research tools, but the functionality sticks to managing references. There may be broader tools to manage all of your research, such as One Note or Citavi. I don't know these programs and I am not a big believer.

Zotero

This program meets your needs. It integrates seamlessly with Word 2007 and syncs its catalogue (the references) with your free account at the Zotero server. Data can be synced with the Zotero server or your WebDAV server of choice. I use 4shared.com.

The good

  • Elegantly exports to many formats, including the files in a nice way. As a consequence, you can always return on your steps and use your old reference manager.
  • Neat integration in all major webbrowsers
  • BibTeX can be synced using the AutoZotBib plugin and the Spartan or the RobinTan translator.
  • It is open source

The bad

  • Each file has its folder and folders have nonsensical names, ruling out the use of Explorer
  • Interface is old fashioned, ineffective
  • Automatic indexing is lagging pdf import and unintuitive to turn of
  • Doesn't sync with Mendeley: you should work via RIS files that include the file path.

Mendeley

A proprietary copy of Zotero, that should sync with it, as well as with a BibTex-file, zo it could act as a bridge between those programs. The file manager is neat, quick and accurate. I regret Zotero doesn't sync back, so I could do part of the job in Mendeley. Mendely offers 1000 MB free cloud storage, which is nice. Prices go up after that, but for lightweight users, it may be a good deal.

The good

  • It syncs with Zotero. However, for large sqlite.data files, this becomes cumbersome and slow, as the syncing is continuous.
  • It natively syncs with a BibTex file, which is very good
  • The interface is nice and let's you read pdfs in the left pane, while having the reference column to the left.
  • You can always revert your decision, via RIS files as said before
  • Search results go quite deep into the references and are neatly shown

    The bad

    • The browser integration is limited to a bookmarklet. This means you have to press and see whether you can import straight from the browser. If you do, you only download to your Mendeley account. Importing to your desktop program is a second step. I understand the cloud approach, but soon you'll leave free territory (considering a HD as free storage).
    • A deal breaker: there is no way to sort search results! What if you want a chronological overview by author? What if you want to see what journals were published in? These are common desires!
    • The thing with syncing large libraries.
    • It's proprietary and they've slowed down on updates.

    JabRef

    JabRef is a totally different breed from the first two. It is to Mendeley/Zotero what TexMaker is to Word. You basically get a list with references, screen wide, optionally linked to fixed folder paths.

    The good

    • It's blazing fast to open and quick to search through.
    • Your database is a text-file, there is nothing to slow it down.
    • It's a bibtex file, which all software can read and what you need in LaTex.
    • Put it on Dropbox, google Drive, and the like, and you are always in sync.
    • You choose an appropriate bibtex key you will remember.

    The bad

    • It doesn't auto-catalog, manage, or rename pdf files.
    • If you use several bibtex files, it is not obvious to move references from one to the other, except by export/import.
    • It doesn't auto-create the bibtex keys.
    • It doesn't ocr for references.

    Workflow

    I use Zotero and JabRef. Zotero manages my literature in the same way iTunes manages my music collection. It is useful though, to make/export a small bibtex file when you finished a paper. It's faster and it secures your references. Also, sometimes Zotero skrews up the references (say, names with multiple uppercase characters), and you can solve this in JabRef.

    A few ways to make the most use of Zotero:
    • Make a dump folder for new documents. I do this by quarter.
    • Use three kinds of tags:
      • Some generic terms: TO DO, CLASSIC, STARS
      • The paper's keywords or theme
      • Some nickname, or the project or institue the paper comes from
    • Use the notes, but do not overinvest in this, because it is too software specific and you'll lose notes and folders one day for sure. I generally give up why I downloaded a paper or who sent it to me.
    • Do not catalog other things than literature. It could replace explorer, but you'll waste your time.
    • Make a folder for each project, with two subfolders: a) literature, and b) references. In references, you keep what you reference to in the paper. 
    • If you write several papers, make several references folders.
    • Export the references folders to bibtex for survival. Polish with JabRef, and edit the bibtex files when you later pick up the work on the paper. By then, your library will have changed and will mess up your paper.
    • Example of the latter: Zotero auto-assigns bibtex keys, say AuthorYearA/B/C. If more articles are imported, those will change and you'll be miserable.
    Some non-workflow related hints:
    • Use a cheap WebDAV server to sync. It works well, won't mess up your database like dropbox would.
    • Go through the pain of setting up Firefox if you're on mac.
    • Solve the Bibtex export problems.
    • Spent your free time tidying up your database. It's your comparative advantage.

    Online sources

    JobAt Loonwijzer

    http://content.jobat.be/nl/loonwijzer-starterslonen/

    Deze keer niet op basis van een enquête, maar via experts. Een leuke tool, wetenschappelijke waarde is wellicht eerder beperkt.

    woensdag 13 oktober 2010

    LaTeX

    Update 20-06-2013

    Probleem

    Na heel wat uren turen onder de Office-motorkap blijven veel problemen onopgelost. Vooral Word werkt soms tegen:
    • Nummering van hoofdstukken en secties
    • Insluiten van vectorafbeeldingen
    • Dimensies van tabellen
    • Cross references naar tabellen en grafieken
    • Inhoudstabellen
    • Paginanummering, first pages en secties
    • Paginadimensies, illustraties
    • Compatibiliteit illustraties in Excel, Powerpoint en Word
    • ...
    Met andere woorden, het is een boeltje. Ondertussen hoor je dat er een markuptaal bestaat die al die zaken onder controle houdt, LaTeX. Ik experimenteer daar ondertussen al even mee.

    Het systeem

    Zoals veel dingen uit de alternatieve wereld van computernerds zijn de interfaces van de programma's onoverzichtelijk en is de installatie al meteen problematisch. In essentie heb je twee programma's nodig.

    Eén: een 'parser', een programma dat de code omzet in - laten we zeggen - een pdf'je. Dat kan MikTeX zijn of TexLive. Het komt allemaal op hetzelfde neer. Je moet wel de toepassing tex.exe weten te localiseren (onder Windows). Ik heb TexLive geïnstalleerd om alternatief te doen.

    Twee: een frontend of editor. Dat kan bij wijze van spreken kladblok zijn, maar het is interessanter om een programma te gebruiken waar bijvoorbeeld knoppen met shortcuts voor bepaalde commando's reeds in aanwezig zijn en waar je met een muisklik het document kunt naar de parser sturen. Ik gebruik hiervoor TexMaker. Meer populair is TexnicCenter, en voor sommige mensen de tussenslag LyX, die reeds een indruk geeft van je output. Ter vergelijking: in Word zie je quasi exact de uiteindelijke output.

    Mijn ervaring:
    • LyX: nutteloos, je kan de LaTeX code niet wijzigen (!)
    • TechnicCenter: oeverloos, er komt geen einde aan de foutmeldingen, zelfs voor een goede file
    • TexMaker: heel erg goed, overschrijft je pdf's en je opent ze met de interne viewer in no time
    Je kan ook alles online laten geschieden. Een briljant idee, maar het werkt nog niet zo goed. Zie:

    Voordelen

    • Het ziet er goed uit - je hebt standaard een heel wetenschappelijke stijl, en met XeTeX wordt het zelfs artistiek.
    • Systematiek is heilzaam.

    Nadelen

    Eerste grote nadeel: samenwerken. Iets als track changes bestaat wel, maar ik durf mij er eerlijk gezegd niet aan wagen, laat staan om iemand anders te dwingen LaTeX te begrijpen.

    Tweede nadeel: cite while you write blijft een beetje klungelig, want je moet in de .bibtex-file keys bepalen voor de referenties. Vanuit Zotero wordt dit automatisch gedaan, maar afhankelijk van de gebruikte plugin krijg je andere keys. Die zijn te manipuleren in JabRef, maar dit kan in feite enkel op het laatste moment wanneer je een definitieve, en paper specifieke referentielijst hebt, zoniet wordt je werk toch telkens overschreven.

    Derde gigantische nadeel: tabellen. Probeer in HTML een tabel te maken: dat gaat niet. In LaTeX is het net zo. Je doet er dan ook best aan om te werken via Excel en een plug-in. Dat voorspelt wel problemen, uiteraard. Enkele links:
    Voor het gebruik van booktabs moet je in de 'preamble' of 'head' de volgende lijn toevoegen:

    \usepackage{booktabs}

    Vierde nadeel: als er een fout in de code zit, krijg je geen output. Begin dan maar te debuggen.

    Nog kritiek:
    Links