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-

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

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

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.
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.

1. Installation

Simply download and setup Skim and LyX, following their instructions.

2. Setup PDFSync Support

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

LyX -> Prefs -> Output 
    PDF command: /Applications/ $$n $$o $$t 

LyX -> Prefs -> File Handling -> File Formats -> Format: [PDF (pdflatex)]
    Viewer: [Custom] [open -a $$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:
LyX SyncTeX help:

24 August, 2015

LaTeX/LyX positioning foating 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)

% import textpos in LaTeX preamble

% set default positioning parameters
\textblockorigin{0mm}{0mm} % start content at the top-left corner

\definecolor{shadecolor}{rgb}{1, 0.80078125, 0}

\textbf{\textcolor{blue}{Preprint version for self-archiving.}}\\
The final publication is available at [Name of Publisher] via
\textbf{\href{}{[DOI Number]}.} 

The output looks as follows.

15 August, 2015

Fun with functions on WolframAlpha

Trying to plot some functions on WolframAlpha I stumbled upon this one.

 f(x,y) = (x2 + y2) * sin( 1 / (x2 + y2) ) 

It creates some nice apparently not-fully symmetric contour plot, such as this one [1]:

Here are two different views [2,3] on the function:

Seeing such images, always inspires me to start my own algorithmic fine arts projects.

Image Sources

[1] WolframAlpha plot of f(x,y) with -0.01 < x,y < 0.01
[2] WolframAlpha plot of f(x,y) with -1 < x,y < 1
[3] WolframAlpha plot of f(x,y) with -0.5 < x,y < 0.5

PS: I will let you know, when I found the time for such procrastination.

09 August, 2015

VLDB Journal paper on visualization-driven data aggregation

Dear readers,
I like to inform you that the main paper about my research of the past 2-3 years has been published [1] in the The VLDB Journal. It is based on my award-winning paper about the M4 aggregation [2] for line charts. It generalizes and extends the M4 approach to the most common chart types, such as bar charts, scatter plots, space-filling visualizations, and also describes how to conduct visualization-driven data aggregation in chart matrices.

For more details, I suggest to have a look at the papers [1, 2].

[1VDDA: automatic visualization-driven data aggregation in relational databases
U Jugel, Z Jerzak, G Hackenbroich, V Markl
The VLDB Journal
2014, DOI 10.1007/s00778-015-0396-z

[2M4: A Visualization-Oriented Time Series Data Aggregation
U Jugel, Z Jerzak, G Hackenbroich, V Markl
Proceedings of the VLDB Endowment 7 (10), 797 - 808, 2014, (best paper award!)