Pages

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

Links

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 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)
%\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}

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

\begin{textblock}{2}(0,0)
\begin{minipage}[t]{1\paperwidth}%
\begin{shaded}%
\begin{center}
\textbf{\textcolor{blue}{Preprint version for self-archiving.}}\\
The final publication is available at [Name of Publisher] via
\textbf{\href{http://dx.doi.org}{http://dx.doi.org/[DOI Number]}.} 
\end{center}
\end{shaded}%
\end{minipage}
\end{textblock}

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!)

 
 

05 August, 2015

Listing code in LaTeX/LyX

In the past I used external tools to provide listings for my papers. However, with 90% of my listings being SQL today, I am regularly editing and tweaking my listings for readability, which is easier when having them directly inside my LyX document. I had the fear that this would impair code highlighting. It doesn't, since the default listings package provides a ton of options [1].

Current working mode and options

  1. Use default listings package
  2. Want floated listings (in LyX)? -> (Right-Click >Settings > Placement > Float [x])
  3. Float needs caption (in LyX)? -> (Menu > Insert > Caption)
  4. Want to add/change colors? -> use colors + listing options
    \definecolor{byzantium}{rgb}{0.44, 0.16, 0.39}
    commentstyle={\color{byzantium}\textit}
  5. Want more colors? -> go to http://latexcolor.com/
  6. Want to add keywords? -> use listing options 
    language=SQL
    morekeywords={WITH} 
  7. Want to emphasize words? -> use listing options
    emph={Q,Q_c,Q_r,Q_b,Q_d,Q_}
    emphstyle={\color{blue}\textbf}
LyX provides the (Document > Settings > LaTeX preamble) to add colors.
LyX also to define default listing properties in (Document  > Settings > Listings).

Here are my current defaults.
basewidth={0.5em}
basicstyle={\ttfamily\small}
breaklines=true
columns=flexible
commentstyle={\color{byzantium}\textit}
emph={Q,Q_c,Q_r,Q_b,Q_d,Q_}
emphstyle={\color{blue}\textbf}
keepspaces=true
keywordstyle={\color{darkmidnightblue}}
language=SQL
morekeywords={WITH}
tabsize=4

Here is some example output.


Links


[1] Carsten Heinz, Brooks Moses, Jobst Ho mann. The Listings Package.
      http://mirror.unl.edu/ctan/macros/latex/contrib/listings/listings.pdf

24 July, 2015

Programming exercise: find palindromic numbers!

Here is the task:
"A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. Find the largest palindrome made from the product of two 3-digit numbers." (originally posted by Joseph Farah)
Here is my quick solution. I know that the palindrome test may be improved, e.g., by excluding some of the numbers based on the arithmetic properties.
#!/usr/bin/env coffee
{floor} = Math
{now}   = Date

print   = console.log.bind console, "palindromes:"
assert  = (expr,msg) -> throw new Error "AssertionError: #{msg}" unless expr
bench   = (name,fn) -> t = now(); r = fn(); print "#{name} took #{now() - t}ms"; r

isPalindrome = (n) ->
  str  = "#{n}";        len  = str.length
  mid  = floor len / 2; last = len - 1
  for i in [0..mid]
    if str[i] != str[last - i] then return false
  return true

findPalindromes = (n=999) ->
  list = []
  for x in [0..n]
    for y in [x..n]
      list.push {x,y,palindrome: p} if isPalindrome p = x*y
  list

byPalindrome = (a,b) -> a.palindrome - b.palindrome

testSuite1 = do ->
  f1 = (n) -> assert     isPalindrome(n), "'#{n}' must be a palindrome!"
  f2 = (n) -> assert not isPalindrome(n), "'#{n}' must not be a palindrome!"

  [9009, 919, 1, 11, 123321, "abba", "aba", NaN, "" ].forEach f1
  [991,9919,10,"01","abc",null,-1,undefined].forEach f2

main = (n) ->
  list = bench "findPalindromes(#{n})", -> findPalindromes n
  largest = list.sort(byPalindrome)[list.length - 1]
  print "found #{list.length} palindromes:", {last5: list[-5..], largest}

module.exports = {isPalindrome,findPalindromes,byPalindrom}

if process.mainModule == module then main 1 * process.argv[2]


Example output on my 2.5Ghz Macbook:
$ ./palindrom.coffee 999
palindromes: findPalindromes(999) took 52ms
palindromes: found 3539 palindromes: { last5:
   [ { x: 894, y: 957, palindrome: 855558 },
     { x: 924, y: 932, palindrome: 861168 },
     { x: 916, y: 968, palindrome: 886688 },
     { x: 924, y: 962, palindrome: 888888 },
     { x: 913, y: 993, palindrome: 906609 } ],
  largest: { x: 913, y: 993, palindrome: 906609 } }

$ ./palindrom.coffee 9999
palindromes: findPalindromes(9999) took 6893ms
palindromes: found 36433 palindromes: { last5:
   [ { x: 9631, y: 9999, palindrome: 96300369 },
     { x: 9721, y: 9999, palindrome: 97200279 },
     { x: 9811, y: 9999, palindrome: 98100189 },
     { x: 9867, y: 9967, palindrome: 98344389 },
     { x: 9901, y: 9999, palindrome: 99000099 } ],
  largest: { x: 9901, y: 9999, palindrome: 99000099 } }


Update: I just needed to take a break from writing my PhD thesis and optimized the search for the largest palindrome. Here is an improved version of the above script.

findPalindromes = (n=999,pruneSmallProducts=false) ->
  list = []
  pmax = x:0, y:0, palindrome:0
  for x in [n..0]
    break if x * n < pmax.palindrome and pruneSmallProducts
    for y in [n..x]
      p = x * y
      break if p < pmax.palindrome and pruneSmallProducts
      if isPalindrome p
        list.push o = {x,y,palindrome:p}
        pmax = o if o.palindrome > pmax.palindrome
  list

#...

main = (n) ->
  list = bench "findPalindromes(#{n})", -> findPalindromes n,true
  largest = list.sort(byPalindrom)[list.length - 1]
  print "found #{list.length} palindromes:", {last5: list[-5..], largest}

The speed up is significant.
$ ./palindrom.coffee 999
palindroms: findPalindromes(999) took 1ms
palindroms: found 2 palindromes: { last5:
   [ { x: 924, y: 962, palindrome: 888888 },
     { x: 913, y: 993, palindrome: 906609 } ],
  largest: { x: 913, y: 993, palindrome: 906609 } }
$ ./palindrom.coffee 9999
palindroms: findPalindromes(9999) took 1ms
palindroms: found 1 palindromes: { last5: [ ... ],
  largest: { x: 9901, y: 9999, palindrome: 99000099 } }
$ ./palindrom.coffee 99999
palindroms: findPalindromes(99999) took 19ms
palindroms: found 1 palindromes: { last5: [ ... ],
  largest: { x: 99681, y: 99979, palindrome: 9966006699 } }
$ ./palindrom.coffee 999999
palindroms: findPalindromes(999999) took 129ms
palindroms: found 1 palindromes: { last5: [ ... ],
  largest: { x: 999001, y: 999999, palindrome: 999000000999 } }
$ ./palindrom.coffee 9999999
palindroms: findPalindromes(9999999) took 1402ms
palindroms: found 1 palindromes: { last5: [ ... ],
  largest: { x: 9997647, y: 9998017, palindrome: 99956644665999 } }

How fast does your browser render line charts?

Here is quick demo that tries to draw hundreds to millions of lines using your browsers drawing APIs of the HTML canvas. (Click on the "Result" of tab of the JSFiddle to show the app)

For instance, you can try to set the number of lines to 6 Million, for which I get the following results on my Macbook.

Firefox 39 Chrome 44
= 817 ms
= 3047 ms
= 5484 ms
= 55383 ms  
= 1490 ms
= 3066 ms
= 4116 ms
= 13789 ms  

You may need to increase tmax to 60k or more milliseconds on slower machines or browsers. Otherwise the processing will stop after  tmax ms

Feel free to post your results in the comments. Note that this demo is copy my former jsPerf test. However, since jsPerf is down due to spam activities, I moved it over to JSFiddle for everyone to experiment with it.

Cheers, Juve