Pages

26 November, 2014

Switchable inline comments for LaTeX/LyX document.

For communication with my co-authors, I sometimes use inline comments, i.e., additional highlighted paragraphs withing the text of my PDF documents; exported from LyX/LaTeX. I know, I could also use PDF comments, but I like the inline style better. Here is how it looks like:


To create these comments, I use a redefinition of LyX's greyedout notes, turning them into an \fcolorbox (see code below). For exporting a printable/camera-ready PDF, I need to turn of the comments.  It took me some time to figure out how to tell LaTeX to completely ignore the comment's body text. I use the environ package for that. Here is the complete code (LaTeX preamble):

\usepackage{verbatim}
\usepackage{environ}
\usepackage{color}

% remove old lyxgreyedout notes
\let\lyxgreyedout\relax
\let\endlyxgreyedout\relax

% redefine lyxgreyedout notes
\NewEnviron{lyxgreyedout}{%
  \noindent %
  \fcolorbox{yellow}{yellow}{
    \begin{minipage}[t]{0.95\columnwidth}%
    \textcolor{blue}{\footnotesize{\BODY}}
  \end{minipage}
}}%

% remove notes for printing: rename the above env and the next env
\NewEnviron{lyxgreyedout2}{%
  %this will ignore all the body content in my greyedouts
  %\BODY
}
And here is the rest of my LaTeX preamble; just for reference:
% I sometimes need a little more space
\newcommand{\vs}{ \textbf{\vspace{2pt}}}

% small fancy links; clickable but still readable (without the http protocol string)
\newcommand{\lnk}[1]{{\small{(\href{http://#1}{#1})}}}

% setting pretolerance to 4500 will remove most overflowing lines, esp.
% for two-column documents. In the final version of a paper, I lower this setting
% and handtune the overflows using hyphenation hints
\pretolerance = 4500

% more penalties for misplaced paragraphs,
% (usually not required for academic paper templates)
%\clubpenalty = 10000
%\widowpenalty = 10000
%\displaywidowpenalty = 10000
Ciao,
Juve

25 November, 2014

Linux at home + Mac at work = Goodbye Windows!


At home I had the luxury, freedom, and fun to use a Desktop Linux for nearly 10 years now. And I am quite happy with my fast and responsive Ubuntu/Gnome Desktop since 2006. When I started my professional career in 2008, I was shocked and sad to see only Windows machines; even on most servers! I think that server-side Windows was really popular at that time in Germany, even though the rest of the world was already moving forward to more OSS and to using Linux servers.

Today, over 6 years later, the situation in my company and in Germany has improved. Thanks to acquisitions, the Linux and Mac crowd was growing inside my company and also the religious devotion to Windows (in Germany) has changed. At my company, there is now a significant and growing number of Mac users and Linux servers are everywhere! Many people are remotely developing on Linux Desktops now, even if they still use a Windows machine as access point.

I am really happy to have Unix-like operating systems on all my devices now. No more fighting with missing features and cross platform software that behaves awkwardly under Windows. No more Cygwin, crappy XServer substitutes, or having to use MSBuild instead of make.

One of the most annoying things in Windows are regular freezes that are often impossible to explain. I had this 1-2 times a week and even more as the device/OS grew older. In most cases I just had to wait 2-10 minutes until the OS was responsive again. Sometimes, I had to hard reset my machine. Let's see if my new Macbook is better in this regard. I never had such issues with my Linux Desktops, or at least there was a way to kill the culprit, find an explanation, and eventually setup a mitigation to the problem. For Windows (and Mac) it is usually much harder or impossible to solve such problems.

I am a first time Mac user now and will probably run into several issues. Stay tuned for regular reports on my progress.

Ciao,
Juve

Update: My new Macbook also froze or had to be restarted a few times in the past month. Mainly caused by issues when logging into the corporate network, but also by software running wild. Regarding stability, I have to say that my new Mac is only slightly better than the a fresh Windows machine. Next time, I will try get a real Linux machine!

05 November, 2014

Cleaning up SVG `transform="translate(dx,dy)"` in Inkscape

I use SVGs in Inkscape and some JavaScript magic to create all my slides for talks and presentations and show them using Firefox or Chrome. Therefore, in Inkscape I draw rectangles on a separate layer to mark the view of each slides. All content goes to the second layer. My JavaScript -- actually it is some awesome CoffeeScript -- then uses the transform attribute to control the current view and the flow of the slides. However, sometimes Inkscape already sets an transform on some of the rectangles, e.g., when copying slides from previous presentations. These transforms interfere with my script.

Here is the trick how to remove them:
  1. Group the rectangles (Ctrl+G).
  2. Ungroup the group (Ctrl+Shift+G).
Inkscape will then recompute the x and y attributes, incorporating the translate(dx,dy) defined in the transform attribute. Afterwards, the transform will then be removed.

PS: If I find the time to cleanup my presentation script, I will open-source it on Github.

23 September, 2014

Modern indentation for old LaTeX document classes

In my last papers I always manually removed the indentation of the first paragraph of each section. This indentation style is considered more modern and more aesthetic, compared to just indenting every paragraph independently of its placement in the document.

Many LaTeX book/article/conference templates, esp. those from the last century ;-), still use old-school indentation. And since I am finally starting to put my PhD thesis work into a real thesis document I was looking for a way to automate the cumbersome manual work I had done previously.

Here is my current solution (based on this TeX answer):

\usepackage{etoolbox}
\makeatletter
\patchcmd{\@startsection}
  {\@afterindenttrue}
  {\@afterindentfalse}
  {}{}
\patchcmd{\chapter}
  {\@afterindenttrue}
  {\@afterindentfalse}
  {}{}
\makeatother

This work nicely for the AMS book template. If you use LyX, as I do, then just add this to your LaTeX preamble in the document settings.


17 September, 2014

Pushing uncompressed and gzip-compressed files into awk

I was just wondering how to best handle compressed and uncompressed files together in my CSV-processing bash/awk scripts. Here is a very simple solution:

#!/usr/bin/env bash

file=my-data.csv.gz

kat(){
  case $file in
    *.gz) gzip -dc $file;;
    *)    cat      $file;;
  esac
}


kat $file | awk '{/* do something */}'

I would say this is really lean code. Even if bash has its restrictions and I despised it in the past, I
have come to love it over the past years.
 
PS: I know there are more sophisticated tools, such as `file` and `zcat`. However, they are not available in the default GitBash on Windows, which I am still using at work for many tasks.


12 February, 2014

Using Gimp Images (xcf files) directly inside LyX

Long ago, I was tired manually converting images to PDF, for papers etc. And I have been using SVGs directly inside LyX, which works quite nice. For my current work I also need some pixel images and composed them in Gimp. Gimp puts out XCF images that contain all layer information, etc.

Unfortunately, LyX (2.0.7) cannot fully handles these images out of the box. The preview is fine, but when generating PDFs LyX/LaTeX fails. To fix this you need to do add following settings in LyX:

1. Preferences -> File Handling -> File Formats -> [New] ->
Format: XCF
Short Name: Gimp Image
Extension: xcf

2. Preferences-> Converters:
From: XCF, To: PNG
Converter: convert -layers merge $$i $$o

This will flatten the file, so make sure your current layer arrangement, etc. looks like your desired final out put. Note that there is  no need for an additional XCF to PDF setting, since the internal PNG to PDF converters will be for that.

Cheers,
Juve


23 October, 2013

Adding JSON quotes with Vim

I just had some bad JSON and quickly replaced the bad text with good text using my magic Vim editor:

The bad code looked like:
{
    prop: "value"
}

But JSON requires:
{
    "prop": "value"
}

Here is the command I used in Vim:

%s#\([^"\t ][a-zA-Z0-9_-]*\):\([\t ]\+\)#"\1":\2#gc

Ciao,
Juve