Copy full path of file to clipboard on the command line

I’m working with files almost exclusively in the terminal either directly in the shell or in Midnight Commander. This is the most effective way for me, however, sometimes it would be very convenient to use Drag and Drop, e.g. when uploading files using a form or attaching files to e-mail.

I could use the file selection dialog of the application in question but that is tedious and requires the mouse. To remedy this, I use this little shell script:

#!/bin/bash
readlink -f "$1" | xclip -i

I have it in my path as clippath. What it does is it resolves the filename passed to it to an absolute path and adds it to the clipboard, ready to be pasted into a file selection dialog.

Now suppose I have created a PDF document paper.pdf in my home folder and I want to attach it to an email. In a shell:

(~) > clippath paper.pdf                                                                                                            

The clipboard now contains /home/kba49/paper.pdf. I write my email, add an attachment and just paste (C-v) the path into the file name field, press enter and am done.

Tagged with: , , , , , , ,
Posted in Shell

Chromium rendering only after every second key

If anyone runs into the issue that navigating pages with the keyboard, using PageUp/PageDown and arrow keys only seems to work on every second key press, then try disable the ‘Accelerated overflow scroll’ setting or enabling the ‘Smooth scroll’ setting in chrome://flags.

Posted in Uncategorized

Latex Folding and Syntax Highlighting in Vim

The syntax plugin for TeX/LaTeX that comes bundled with vim is pretty good, not only does it highlight keywords, markup, environments but allows folding of text using part/chapter/section/subsection/subsubsection/ and so on. This is a tremendous help for navigating documents.

Enabling LaTeX folding

To enable it, put

let g:tex_fold_enabled=1

in $HOME/.vim/ftplugin/tex.vim and

% vim: fdm=syntax

to the end of your LaTeX source file (or set it from the command line or add it to your .vimrc)

Vim LaTeX folding is wrong / Vim Latex Syntax Highlighting is wrong

The folding and syntax highlighting reacts badly if you have unmatched parentheses/braces/brackets in the text. If the folding works up to a certain point and then slaps everything together into one big fold or if the section markup is highlighted like a Statement instead of like a texSection — the root of the problem is probably an unclosed parenthesis.

Search for all opening parens /( and make sure they are closed.

In my case, the problem was a sad smilie face I had in a comment. :-( But I fixed it by adding a happy smilie :-) Oh, if only there were more things in life that could be fixed by adding a happy smilie!

Formatting gets really slow

Unfortunately, when the file is rather large, enabling syntax-based folding makes formatting paragraphs (e.g. gqap) really slow. I haven’t found a solution for this yet, my workaround is to temporarily set foldmethod=marker and set it back to set foldmethod=syntax when I’m not writing text.

Tagged with: , , , ,
Posted in LaTeX, Vim

BSD Games: go-fish

Sometimes back I wrote about the backgammon terminal game that comes with the bsd-games package found in many Linux distros (and *BSDs of course). Another little game I really like is the text-interface card game version of Go Fish.

It is kind of a two-player solitaire game: You try to get all four colors of a certain rank of card by asking the other player (the not-that-smart computer AI) whether it has any cards of that rank and if it does it must hand them over to you. If it doesn’t you can draw a card from the stack (standard 52 card deck) and it’s the computer’s turn.

Not that deep strategically but a nice five-minute-diversion nonetheless and actually a game you can play with kids because the rules are so simple.

Below is a transcript to show you how it looks like.

Would you like instructions (y or n)? n
I get to start.
I ask you for: 2.
You have 1 2.
I get another guess!
I ask you for: 6.
You have 1 6.
I get another guess!
I ask you for: 7.
You say "GO FISH!"

Your hand is: A 4 9 9 K
You ask me for: a
I say "GO FISH!"
You drew 10.
I ask you for: 8.
You say "GO FISH!"

Your hand is: A 4 9 9 10 K
You ask me for: 10
I have 1 10.
You get another guess!

Your hand is: A 4 9 9 10 10 K
You ask me for: 4
I say "GO FISH!"
You drew Q.
I ask you for: 9.
You have 2 9's.
I get another guess!
I ask you for: J.
You say "GO FISH!"

Your hand is: A 4 10 10 Q K
You ask me for: q
I say "GO FISH!"
You drew 9.
I ask you for: 2.
You say "GO FISH!"

Your hand is: A 4 9 10 10 Q K
You ask me for: 9
I have 3 9's.
You made a book of 9's!
You get another guess!

Your hand is: A 4 10 10 Q K + Book of 9
You ask me for: k
I say "GO FISH!"
You drew Q.
I ask you for: 5.
You say "GO FISH!"
I drew 2 and made a book of 2's!

Your hand is: A 4 10 10 Q Q K + Book of 9
You ask me for: q
I say "GO FISH!"
You drew K.
I ask you for: 6.
You say "GO FISH!"

Your hand is: A 4 10 10 Q Q K K + Book of 9
You ask me for: k
I say "GO FISH!"
You drew Q.
I ask you for: 7.
You say "GO FISH!"

Your hand is: A 4 10 10 Q Q Q K K + Book of 9
You ask me for: 4
I have 2 4's.
You get another guess!

Your hand is: A 4 4 4 10 10 Q Q Q K K + Book of 9
You ask me for: a
I say "GO FISH!"
You drew J.
I ask you for: 8.
You say "GO FISH!"

Your hand is: A 4 4 4 10 10 J Q Q Q K K + Book of 9
You ask me for: j
I have 2 J's.
You get another guess!

Your hand is: A 4 4 4 10 10 J J J Q Q Q K K + Book of 9
You ask me for: 10
I say "GO FISH!"
You drew J and made a book of J's!
I ask you for: 5.
You say "GO FISH!"

Your hand is: A 4 4 4 10 10 Q Q Q K K + Books of 9 J
You ask me for: k
I say "GO FISH!"
You drew 5.
I ask you for: 6.
You say "GO FISH!"

Your hand is: A 4 4 4 5 10 10 Q Q Q K K + Books of 9 J
You ask me for: 5
I have 3 5's.
You made a book of 5's!
You get another guess!

Your hand is: A 4 4 4 10 10 Q Q Q K K + Books of 5 9 J
You ask me for: a
I say "GO FISH!"
You drew 4 and made a book of 4's!
I ask you for: 7.
You say "GO FISH!"

Your hand is: A 10 10 Q Q Q K K + Books of 4 5 9 J
You ask me for: q
I say "GO FISH!"
You drew A.
I ask you for: 8.
You say "GO FISH!"

Your hand is: A A 10 10 Q Q Q K K + Books of 4 5 9 J
You ask me for: a
I have 1 A.
You get another guess!

Your hand is: A A A 10 10 Q Q Q K K + Books of 4 5 9 J
You ask me for: 10
I say "GO FISH!"
You drew K.
I ask you for: 6.
You say "GO FISH!"

Your hand is: A A A 10 10 Q Q Q K K K + Books of 4 5 9 J
You ask me for: k
I say "GO FISH!"
You drew 7.
I ask you for: 7.
You have 1 7.
I get another guess!
I ask you for: 8.
You say "GO FISH!"
I drew the guess!
I get to ask again!
I ask you for: A.
You have 3 A's.
I made a book of A's!
I get another guess!
I ask you for: 6.
You say "GO FISH!"

Your hand is: 10 10 Q Q Q K K K + Books of 4 5 9 J
You ask me for: q 
I say "GO FISH!"
You drew 6.
I ask you for: 7.
You say "GO FISH!"

Your hand is: 6 10 10 Q Q Q K K K + Books of 4 5 9 J
You ask me for: 6
I have 3 6's.
You made a book of 6's!
You get another guess!

Your hand is: 10 10 Q Q Q K K K + Books of 4 5 6 9 J
You ask me for: 10
I say "GO FISH!"
You drew 3.
I ask you for: 8.
You say "GO FISH!"

Your hand is: 3 10 10 Q Q Q K K K + Books of 4 5 6 9 J
You ask me for: 3
I have 3 3's.
You made a book of 3's!
You get another guess!

Your hand is: 10 10 Q Q Q K K K + Books of 3 4 5 6 9 J
You ask me for: k
I say "GO FISH!"
You drew 7.
I ask you for: 7.
You have 1 7.
I made a book of 7's!
I get another guess!
I ask you for: 8.
You say "GO FISH!"

Your hand is: 10 10 Q Q Q K K K + Books of 3 4 5 6 9 J
You ask me for: 10
I say "GO FISH!"
You drew K and made a book of K's!
I ask you for: Q.
You have 3 Q's.
I made a book of Q's!
I get another guess!
I ask you for: 8.
You say "GO FISH!"
I drew 8 and made a book of 8's!
I don't have any more cards!
My books: A 2 7 8 Q
Your books: 3 4 5 6 9 J K

I have 5, you have 7.

You win!!!
Tagged with: , ,
Posted in Linux, Linux Game

Illegal parameter number in definition of Hy@tempa

You used a # in a \url{} without escaping it. Escape it by prepending the # with a backslash, like so: \#.

If you have

\url{http://example.com/#fragment}

change it to

\url{http://example.com/\#fragment}

Carl Turner did a blog post on this error back in 2010.

Tagged with:
Posted in LaTeX, LaTeX Error

WARNING: location-reference “{}{i}” did match multiple location-classes! (taking first one)

This is the first post of a supposed number of posts on LaTeX error message. With a sufficiently large document there are a lot of Warnings and errors to deal with so I thought it might be useful to explain what they mean and — if I can — offer advice how to fix them.

This is caused by the the *.gls intermediary file of the glossaries package when rebuilding the index using xindy.

Seems harmless.

Tagged with: , , , ,
Posted in LaTeX, LaTeX Error

Rebuild PDF from VUE diagrams without GUI using latexmk

In a previous post I shared a way to export VUE diagrams to PDF in bulk on the command-line. In this post I’ll share a way to automate this even further by delegating the dynamic recreation of PDF files to LaTeX-Mk (latexmk), an excellent make-like build tool for generating documents from arbitrarily complex LaTeX projects.

latexmk can be extended using Perl in a file called latexmkrc in the project’s base directory (or one of the locations mentioned in the latexmk man page). This is accomplished by adding a custom file dependency that states that for every “*.vue* file that is newer than the corresponding “*.pdf” file (or for which noch corresponding “*.pdf” file exists) the PDF should be re-created.

Here is the code to put into latexmkrc:

add_cus_dep( 'vue', 'pdf', 0, 'makevue' );
sub makevue {
    system( "timeout 20 java -cp \$(locate VUE.jar|head -1) edu.tufts.vue.component.Export \"$_[0].vue\" \"$_[0].pdf\" pdf" );
    system( "pdfcrop \"$_[0].pdf\" \"$_[0].pdf\"" );
}

Because the edu.tufts.vue.component.Export seems to hang indefinitely for large diagrams, the process is killed after 20 seconds if it hasn’t finished before by the highly recommended timeout tool. The call to pdfcrop removes all surrounding whitespace around the actual diagram which makes the PDF files easier to include and position in LaTeX.

Now, whenever I have changed a diagram, I just have to save it and rebuild the LaTeX document, e.g. to a PDF:

$ latexmk -pdf thesis.tex

This should produce output similar to the following (for an updated VUE map diagrams/myDiagram.vue):

Latexmk: This is Latexmk, John Collins, 11 Nov. 2012, version: 4.35.
**** Report bugs etc to John Collins . ****
Latexmk: applying rule 'cusdep vue pdf diagrams/myDiagram'...
Rule 'cusdep vue pdf diagrams/myDiagram': File changes, etc:
   Changed files, or newly in use since previous run(s):
      'diagrams/myDiagram.vue'
------------
Run number 1 of rule 'cusdep vue pdf diagrams/myDiagram'
------------
For rule 'cusdep vue pdf diagrams/myDiagram', running '&do_cusdep( makevue )' ...
VUE 2013-04-04 14:59:37,106  INFO [main] Mapping: Loading mapping descriptors from jar:file:/usr/share/java/vue/VUE.jar!/tufts/vue/resources/lw_mapping_1_1.xml
VUE 2013-04-04 14:59:37,107  INFO [main] ActionUtil: unmarshalling: file:/tmp/testproj/diagrams/myDiagram.vue; charset=UTF-8
VUE 2013-04-04 14:59:37,823  INFO [main] ActionUtil: unmarshalled: LWMap[v5 myDiagram.vue n=97]
VUE 2013-04-04 14:59:38,517  INFO [main] Images: created thread pool: tufts.vue.Images$PriorityThreadPool@1a46725d[Running, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0]; maxSize=3
PDFCROP 1.38, 2012/11/02 - Copyright (c) 2002-2012 by Heiko Oberdiek.
==> 1 page written on `diagrams/myDiagram.pdf'.
Latexmk: applying rule 'pdflatex'...
Rule 'pdflatex': File changes, etc:
   Changed files, or newly in use since previous run(s):
      'diagrams/myDiagram.pdf'

Yay, another optimization as the result of procrastination!

Tagged with: , , , , ,
Posted in LaTeX
Follow

Get every new post delivered to your Inbox.