## 04 December, 2015

### Useful command to help tuning your WiFi antenna

WiFi throughput depends on the placement of your router and connected WiFi adapters, i.e., the position of their antennas.

I just tuned my WiFi, by testing various placements and observing the detailed signal quality in real time using the following bash command,

while sleep 0.5; do clear; iwconfig wlan1 | grep -iE "rate|quality"; done

which will continuously output the data rate and signal quality of your WiFi adapter wlan1. Note that, depending on your setup, your device name may be different, e.g., wlan0, wlan2, etc.

## 19 October, 2015

### Enable sectioned bibliography in LaTeX/LyX under Linux

Today I switched my dissertation workplace from my corporate MacBook to my Ubuntu Linux PC at home. Nearly everything worked fine, since I already carefully defined all figures and child documents to use relative paths.

However, I got one error that puzzled me:
LaTeX Error: File bibtopic.sty' not found
Obviously some LaTeX package was missing, which did not happen before under Linux. Now what to do -- in absence of a LaTeX package manager on Linux?

So I did a search for "bibtex":
$aptitude search bibtex p bibtex2html - filters BibTeX files and translates p bibtexconv - BibTeX Converter p bibtexconv:i386 - BibTeX Converter p jbibtex-base - make a bibliography for ASCII p(La) p kbibtex - BibTeX editor for KDE p kbibtex:i386 - BibTeX editor for KDE p libtext-bibtex-perl - Perl extension to read and parse Bi p libtext-bibtex-perl:i386 - Perl extension to read and parse Bi p nbibtex - Powerful, flexible replacement for p nbibtex:i386 - Powerful, flexible replacement for p nbibtex-doc - Documentation of source code for nb p python-bibtex - Python interfaces to BibTeX and the p python-bibtex:i386 - Python interfaces to BibTeX and the v python2.7-bibtex - v python2.7-bibtex:i386 - p texlive-bibtex-extra - TeX Live: BibTeX additional styles  OK, "texlive-bibtex-extra", "additional styles". This was what I was missing and installing this package fixed the problem. $ sudo aptitude install texlive-bibtex-extra 
Done!

## 22 September, 2015

### LaTeX \sloppy and \fussy line breaking

In my thesis, I use words like "visualization-related" a lot. Such words should not be further hyphenated, since it may look awkward.

Example: manual hyphenation

Words  break awkwardly

like visualization-rel-
ated or like visualiza-
tion-related.

The hyphenation for line breaking will interfere with the initial hyphenation and impair readability.

In LaTeX, the default line breaking mode is \fussy. This mode tries to present the words on each line very condensed, not allowing for the space between two words becoming too large. However, this causes problems with hyphenated words that should not be hyphenated any further. If the entire word would be moved to the next line, then the inter-word space on the current line would suddenly be too large. LaTeX then decides not to hyphenate AND not to break, but instead let the word flow over.

Example: default \fussy mode

All words break normally but
may overflow like visualization-
related or visualization-related.

The overflow can be removed by setting \sloppy mode instead of \fuzzy mode in your preabmle or locally using {\sloppy ... }. This forces overflowing words to move to the next line, but may lead to large inter-word spaces on the current line.

Example: alternative \sloppy mode

All  words  break  normally
and  without  overflow like
visualization-related,  but
also   like   visualization-
related.   But   inter-word
space can be very large.

### Getting to best of both worlds

Lately, I am writing my documents as follows:
1. Start writing your document in \sloppy mode.
2. Extend, rewrite, review, revise the document until it is nearly ready for publication/submission.
3. Switch to \fuzzy mode and fix any problems manually.
Manual fixing will be mostly done by (1) rewriting a few sentences, or by (2) telling LaTeX exactly where to break.

For Option 1, just add a few words, such as a "the" or rephrase some words from short nouns to using a phrase with an "ing"-form. Exchanging verbs also helps.

Example: rephrasing to push over hyphenated words (before and after)

All words break normally but
may overflow like visualization-
related or visualization-related.

All words break normally but
also  suffer  from  overflow

like visualization-related or
visualization-related.

The problem is that the overflow may be pushed down, i.e., other words following long hyphenated words may not be allowed to wrap over,  due to the prioritization of inter-word spaces. In this case, LaTeX can be told where to break and thus occasionally violate the inter-word spacing rule.

Therefore, you need Option 2, the \linebreak{} command to manually wrap over while leaving the previous line justified; however awkward it may look thereafter. In LyX this special line break can be inserted via Insert > Formatting > Justified Line Break and depending on your OS it should have a hotkey you should remember.

Example: additional line breaks (before and after)

All words break normally but
also  suffer  from  overflow

like visualization-related or
visualization-related.

All words break normally but
also  suffer  from  overflow

like   visualization-related \linebreak{}
or visualization-related.

The broken line may suffer from larger inter-word space. You just have to find a nice compromise here. In texts with more words per line than the shown examples, additional white-space is less notable and the fixes should be easier, i.e., the overflow will not be pushed down to following words.

There is also an Option 3: Instead of manually fixing, you can wrap a paragraph with {\sloppy ... } to temporarily allow large inter-word spaces. However, I like Options 1 and 2 better.

## 05 September, 2015

### How to fix a broken Logitech mouse that is clicking multiple times on single click

My Logitech was sending false mouse up and down events to my MacBook. I first though it was a software problem or that the mouse, which I bought as used hardware on Ebay, has some broken electronic component. Other users had similar problems. However, here is how I fixed it.

## 02 September, 2015

### Copy & paste tabular data to tables in LyX

As it can be cumbersome to manually transfer data from an external source to a table in LyX, here is trick to speed up the process.

Let's assume the data is stored comma-separated in a text file with the following content.
1920,1080,48,24,40,45,1920,1080,0%
1920,1080,46,23,41,46,1886,1058,3.8%
1920,1080,45,23,42,46,1890,1058,3.6%
1920,1080,44,22,43,49,1892,1078,1.6%
1920,1080,43,22,44,49,1892,1078,1.6%
1920,1080,42,21,45,51,1890,1071,2.4%
1920,1080,41,21,46,51,1886,1071,2.6%
1920,1080,40,20,48,54,1920,1080,0.0%

Then copy&pasting (CMD+SHIFT+V or CTRL+SHIFT+V) this text into a table in LyX will only fill the first table column. However, if the data were TAB-separated as follows,
1920 1080 48 24 40 45 1920 1080 0%
1920 1080 46 23 41 46 1886 1058 3.8%
1920 1080 45 23 42 46 1890 1058 3.6%
1920 1080 44 22 43 49 1892 1078 1.6%
1920 1080 43 22 44 49 1892 1078 1.6%
1920 1080 42 21 45 51 1890 1071 2.4%
1920 1080 41 21 46 51 1886 1071 2.6%
1920 1080 40 20 48 54 1920 1080 0.0%

then LyX will nicely fill your table. This should also work for data that is copy pasted from spreadsheet applications.

If your spreadsheet does not copy&paste using TAB-separated data in the clipboard, then you can use some Vim magic. Paste the, e.g., space-separated, data into Vim and replace spaces with tabs, i.e., type :%s# #\t#gc (ENTER).

Note: Don't forget to use format-preserving paste (CMD+SHIFT+V or CTRL+SHIFT+V) instead of the normal paste in LyX (CMD+V or CTRL+V)

PS: I know that LyX also offers to import external files, but I often like to have all my text editable inside the document, e.g., to add colors, change font sizes, add footnotes, or use Math enviroments in the data.

## 27 August, 2015

### Using Skim as preview tool with LyX/LaTeX

OS X's Preview app does not support reloading of updated PDFs and has no PDFSync support.
Here is quick guide to set up Skim, which is a better app for this purpose.

#### 2. Setup PDFSync Support

Skim -> Prefs -> Sync
[x] Check for file changes
Preset: [Lyx]

LyX -> Prefs -> Output
PDF command: /Applications/Skim.app/Contents/SharedSupport/displayline $$n$$o $$t LyX -> Prefs -> File Handling -> File Formats -> Format: [PDF (pdflatex)] Viewer: [Custom] [open -a Skim.app$$i] (click Apply)

Repeat previous step for PDF (LuaTeX) and PDF (XeTeX)

#### 3. Improve Output

The text in Skim can be blurry on some systems OS X versions. You can try messing around with the font smoothing to fix that.

defaults write -app Skim AppleFontSmoothing -integer 1

worked well for me.

Skim hidden preferences: http://sourceforge.net/p/skim-app/wiki/Hidden_Preferences/#system-overrides
LyX SyncTeX help: http://wiki.lyx.org/LyX/SyncTeX

## 24 August, 2015

### LaTeX/LyX positioning floating text on top of a page

To publish preprint versions of papers, you often need to add a remark on top of the first page. If you do not want to mess around with the final PDF, there is are several ways to add floating text, with absolute positioning.

Here is my current solution.

% optional box and link packages (LyX adds them automatically)
%\usepackage{framed}
%\usepackage{color}
%\usepackage{hyperref}

% import textpos in LaTeX preamble
\usepackage[absolute]{textpos}

% set default positioning parameters
\setlength{\TPHorizModule}{10mm}
\setlength{\TPVertModule}{\TPHorizModule}
\textblockorigin{0mm}{0mm} % start content at the top-left corner
\setlength{\parindent}{0pt}

\begin{textblock}{2}(0,0)
\begin{minipage}[t]{1\paperwidth}%
`