awk length of each line sorted

This is just an awk one-liner for helping me find long lines, usually in latex documents, that makes merging different versions of my paper easier. It just identifies the long lines and you can then easily break them into smaller ones. No more 3000 character lines.

awk '{print length($0), ++nn}' file.txt | sort -n

LaTeX: continuous footnote numbers and footnote to endnote conversion

Continuous footnote numbering

When writing long documents in LaTeX, like books sometimes you want footnotes to run continuously through the document instead of restarting the count every chapter. This can be accomplished using the chngcntr package like this:

% In the preamble
\usepackage{chngcntr}
\counterwithout{footnote}{chapter}

Converting footnotes to Endnotes

Another thing that you usually see in books is that the footnotes don’t appear at the bottom of the page, but instead appear in the end of the book. The easy way to convert footnotes to endnotes in latex is by using the endnotes package like this:

% In the preamble
\usepackage{endnotes}
\let\footnote=\endnote
 
% In the document where you want the notes to be printed
\newpage
\theendnotes

Latex: When Algorithms and Hyperref hate each other

When using algorithms in Latex and trying to use hyperref to produce automatic links in the references that one uses in LaTeX documents one usually finds out that although the references are printed correctly, the links for algorithms don’t work (usually pointing to the first page in the document). If you investigate the messages of the output you usually find:

pdfTeX warning (dest): name{algorithm.1} has been referenced
but does not exist, replaced by a fixed one

Well, the problem is that for some reason hyperref doesn’t work correctly with the algorithm and float packages. The trick to solve this is to push the use of hyperref package down the most in the preamble (without breaking anything) and then put the float package before hyperref and algorithm package after hyperref like in the example below:

...
\usepackage{float} % Before hyperref
\usepackage{hyperref} 
\usepackage{algorithm} % After hyperref
\begin{document}
...

This seems to solve the problem, and there are other situations where one might want to be careful with the order we load packages.

Does this solve the problem for you?

Latex Tip: back references in bibliography

Latex

When writing long texts, articles or you know… thesis, in latex I find very useful to have automatic links between references and the entries that show up in the bibliography. That is easily accomplished by using the hyperref package in the preamble of the latex document by including the package hyperref

\usepackage{hyperref}

Now, this is cool, but sometimes I’m seeing a reference on the bibliography and I’d just like to know where it was used in the text so I could check what I wrote about it quickly. But this normally involves a search box and it is a pain. It would be easier if you just included backlinks at the end of each reference with the pages where that reference was used.

The hyperref package allows that by setting the option pagebackref=true on the package options. Now you just have to use

\usepackage[pagebackref=true]{hyperref}

and it will give you those nice links at the end of each reference, back to the pages where you first inserted them.

If only bibliographic styles for major publications would be like that! The solution is to remove the option after writing, but even so it is a nice productivity feature to have while writing.